0 Up votes0 Down votes

12 views7 pagesAug 25, 2011

© Attribution Non-Commercial (BY-NC)

DOC, PDF, TXT or read online from Scribd

Attribution Non-Commercial (BY-NC)

12 views

Attribution Non-Commercial (BY-NC)

- Short Questions on DS
- B TREE TUTORIAL PPT
- MCS 021 Data and File Structures
- Dat Structure Homework3
- Thinking in Sets
- chap3alg
- TREE (JAVA)
- BST Deletion
- IJCSE11-03-07-092
- Tree Properties
- Tree
- Java BasicADTs
- Algorithms and Data Structures Exam Practice
- WEB CONTENT ADAPTATION FOR MOBILE DEVICES: A GREEDY APPROACH
- aashish.docx
- 234-Trees.pptx
- ALL_88NV
- User Guide Documentation
- Indexing
- tree_sy

You are on page 1of 7

4 0 3 0 3 2 5 5 3 2 3 0 3 5

4 0 5 5 5 0

(A)

(B)

a. Answer these questions: What is its height? Is it a full binary tree? Is it a complete binary tree? Is it a binary search tree? b. If visiting a node displays the integer value stored, show the inorder, preorder and postorder traversal of each tree 2. Show the tree that would be built by the following input string, then create this tree using Create method 30 15 4 null null 20 18 null 19 null null null 35 32 null null 38 null

null 3. Show the BSTree that would be formed by adding following values to the tree: a. happy, depressed, manic, sad, ecstatic b. 45, 30, 15, 50, 60, 20, 25, 90 4. For each tree shown below, show or explain the effect of removing the nodes 15, 30 from the tree

4 8 2 8 1 5 1 1 2 1 7 2 3 2 6 3 0 3 7 4 2 4 9 5 1 5 2 6 0 6 3 7 0 5 5 7 1 8 3 9 0

5. Build a class for Binary Search Tree of objects having parameter type a. Implement a recursive and non-recursive method that adds a value to the BSTree, and returns true if the add is sucessful, otherwise returns false b. Implement a recursive and non-recursive method that searches a BSTree looking for the node having specified value and returns a reference variable to that node if found, otherwise returns null c. Implement a method to remove a specified value from the BSTree, and return the removed value if the remove is sucessful, otherwise return null d. Implement recursive and non-recursive methods to perform an inorder, preorder and postorder traversal of a BSTree and display the nodes value e. Implement a method that returns the number of nodes in the BST f. Implement a method that returns the number of nodes having odd value in the BST g. Implement a method that returns the average of nodes having even value in the BST h. Implement a method that returns the height of the BST i. Implement a method that returns the depth or level of the node having specified value j. Implement a method that returns the number of leaf nodes in the BST k. Implement a method that returns the number of nodes at the first level in the BST

Implement a method that returns the number of nodes at the second level in the Implement a method that returns the number of nodes at specified level in the Implement a method that returns the number of internal nodes in the BST Write a recursive and non-recursive method to check if the tree is binary search Recursive: left subtree: BST and right subtree: BST and max(datas of left childs) < root.data < min(datas of right childs) Non-Recursive: inorder traversal, if node datas are increasing: BST Implement a method that returns the height of the node having specified value Implement a method that displays the values of nodes at specified level in the

p. q. BST 6. Build a class for Balanced Search Tree of objects having parameter type a. Implement a method that adds a value to the Tree, and returns true if the add is sucessful, otherwise returns false b. Write a method to check if the tree is balanced binary tree 7. For BSTree shown below:

root

3 8 3 1

a.

Draw the BSTree that would be built by adding following values to the tree: 32, 69, 18, 11, 28, 70, 23, 9, 37, 47 b. 45, 30, 15, 50, 60, 20, 25, 90

c. Show the inorder, preorder and postorder traversal for displaying the nodes value in the tree after adding above values 8. Create following tree using Create method 8

T

1 1 1 1 2 1 0 3 0

9. Draw process of stack uesed to build binary expression trees for the following infix expressions. Your trees should enforce the Java rules for operator evaluation (higherprecedence operators before lower-precedence operators and left associativity) a. x/y + a b*c b. x*a y/b * (c+d) 10. For expression: (A+B) * (H - (E F ^ D) / C) a. Build expression tree from the above expression b. Build postfix expression from the expression c. Present algorism of evaluating an expression tree d. Draw process of stack used to evaluate the expression

import java.util.*; public class BSTree<E> { private Node<E> root; public static private private private class Node<E> { Node<E>left; Node<E>right; E data;

//Tree includes 1 node having the value d public Node(E d){ left = null; right = null; data = d; } //Tree includes the root node d, //and left subtree l, right subtree r public Node(E d, Node<E>l, Node<E>r) { left = l; right = r; data = d; } } //Initiate tree having root public Node<E> Create(E d){

root = new Node<E>(d); return root; } //Initiate tree having root, and left subtree l, right subtree r public Node<E> Create(E d, Node<E> l, Node<E> r){ root = new Node<E>(d, l, r); return root; } //inorder traversal private void inorderTraversal(Node<E> r) { if (r == null) return; inorderTraversal(r.left); System.out.print(r.data+" "); inorderTraversal(r.right); } public void inorderTraversal(){ inorderTraversal(root); } //inorder traversal return String private String inorderTraversal1(Node<E> r) { if (r == null) return ""; return inorderTraversal1(r.left) + r.data + inorderTraversal1(r.right); } public String innorderTraversal1(){ return inorderTraversal1(root); } //preorder traversal return String private void preorderTraversal1(Node<E> r) { if (r == null) return; System.out.print( r.data+" "); preorderTraversal1(r.left); preorderTraversal1(r.right); } public void prenorderTraversal1(){ preorderTraversal1(root); } //postorder traversal return String private void postorderTraversal1(Node<E> r) { if (r == null) return; postorderTraversal1(r.left); postorderTraversal1(r.right); System.out.print(r.data+" "); } public void postorderTraversal1(){ postorderTraversal1(root); } /********** * This support routine searches a specified subtree looking * for the item specified as the target. * @param r The root of a subtree to be searched

* @param target The target of the search * @return The node having the target value of the search if found, otherwise null */ private Node<E> searchBST(Node<E> r, Comparable<E> target) { if (r == null) return null; int result = target.compareTo(r.data); if (result == 0) return r; if (result < 0) return searchBST(r.left, target); return searchBST(r.right, target); } /********** * This routine searches the BSTree looking for the specified item. * @param target The target of the search * @return The target is returned if found or a null is */ public Node<E> searchBST(E target) { return searchBST((Node<E>)root,(Comparable<E>)target); } private boolean returnValue; // Used to signal if an add was successful /********** * This method is the entry point routines outside of this class use to add * a value to the BST. * @param newValue The target of the search * @return The target is returned if found or a null is */ public boolean add(Comparable<E> newValue) { root = add(root, newValue); return returnValue; } /********** * This is private method is used to add a value to the BST via recursion. * @param newValue The target of the search * @return A reference to the updated subtree after the add */ private Node<E> add(Node<E> r, Comparable<E> newValue) { if (r == null) return new Node(newValue); int compareResult = newValue.compareTo(r.data); if (compareResult == 0) return r; if (compareResult < 0) { r.left = add(r.left, newValue); return r; } r.right = add(r.right, newValue); return r; } public static void main(String[] args){ BSTree<Integer> tree = new BSTree<Integer>(); tree.add(24); tree.add(15); tree.add(30);

} }

tree.add(5); tree.add(7); tree.add(25); tree.add(56); tree.add(17); tree.add(22); tree.add(20); tree.inorderTraversal(); System.out.println(); tree.preorderTraversal1(); System.out.println(); //Creat Binary tree /*BSTree<Integer> tree = new BSTree<Integer>(); tree.Create(7, tree.Create(5, null, tree.Create(9, tree.Create(11), null)), tree.Create(8, tree.Create(6), tree.Create(3, tree.Create(2),tree.Create(4)) ) ); tree.inorderTraversal(); */

- Short Questions on DSUploaded byKattupalli Sudhakar
- B TREE TUTORIAL PPTUploaded byharshilsurti
- MCS 021 Data and File StructuresUploaded bySumit Ranjan
- Dat Structure Homework3Uploaded byjitenderthakur490
- Thinking in SetsUploaded bysourcenaturals665
- chap3algUploaded byjose
- TREE (JAVA)Uploaded byakukurt
- BST DeletionUploaded bygurudatt_kulkarni
- IJCSE11-03-07-092Uploaded byd4nief
- Tree PropertiesUploaded byRajendranbehappy
- TreeUploaded byregisanne
- Java BasicADTsUploaded byOla
- Algorithms and Data Structures Exam PracticeUploaded byjosholson6
- WEB CONTENT ADAPTATION FOR MOBILE DEVICES: A GREEDY APPROACHUploaded byInternational Journal of New Computer Architectures and their Applications (IJNCAA)
- aashish.docxUploaded byIppili AaShish
- 234-Trees.pptxUploaded bymln35
- ALL_88NVUploaded byRulas PD
- User Guide DocumentationUploaded byreidstar
- IndexingUploaded bySaraswati Mishra
- tree_syUploaded byRutuja Rajguru
- INFREQUENT WEIGHTED ITEMSET MINING FOR TRANSACTIONAL DATABASES USING FREQUENT PATTERN GROWTHUploaded byIJIERT-International Journal of Innovations in Engineering Research and Technology
- Physical Data OrganizationUploaded byYaronBaba
- ScanUploaded byPrasanth Kumar
- Tree and GraphUploaded bykrayya
- C Programs FinalUploaded bySanJeev Dani PeDrosa
- 0711.3147Uploaded byErickDavidChavarríaMadriz
- mnsc%2E44%2E2%2E262.pdfUploaded byKewal N Mishra
- GATE_QP_CS_2007Uploaded bybasualok@rediffmail.com
- Index RebuildUploaded bypranav_pareek
- xgboost-150831021017-lva1-app6891Uploaded byPushp Toshniwal

- Design Module Users GuideUploaded byGuillermo Ceos
- Test ManagerUploaded byKishan Jasti
- Roger Dannenberg - A Fast Data Structure for Disk-Based Audio EditingUploaded byAlex Di Nunzio
- AVL Tree _ Set 1 (Insertion) - GeeksforGeeksUploaded byamit
- Mercury X-ray SoftwaareUploaded byjiviyana
- aos buddyUploaded bypraveena
- Problem Solving With Prolog - Chapter 3 (John Stobo)Uploaded byJesus Espino Luna
- Wine Case ReportUploaded byNeeladeviN
- Galaxy ManagementUploaded byQBinh Nguyen
- How to check Switch Framework Activation result_v1.pdfUploaded byChong Sa
- Objective Type QuestionsUploaded byRama Kasturi
- A New Encryption Algorithm to Increase Security of Amazigh Text through Tree Traversal TechniqueUploaded byEditor IJRITCC
- Decision Trees for Predictive Modeling (Neville)Uploaded byMohith Reddy
- 02 Problem Solving Search ControlUploaded byShreeji Engg
- User_Manual_drive_studio.pdfUploaded byIñigo
- A Data Structure for Dynamic TreesUploaded bylike2share
- Ext_JS_3.1Uploaded byfvchapa2
- erosUploaded bysanzrohit
- icpc10jak-problemsetUploaded bystreetfi8er1190
- nyc2Uploaded byAkhil Raj
- Models.nsm.Variable Load CreepUploaded byNadhim Khalifa
- Resources 3.8 3.13 Hierarchical PlanningUploaded byAli QasimPouri
- ABAPTips.docxUploaded bysantoshs_41
- rr210301-data-structures-through-cUploaded bySrinivasa Rao G
- Uptu Study Scheme ItUploaded byDivya Arora
- Archi User GuideUploaded byLollu
- OVSFUploaded byShalua Yonah
- On the Principles of Mathematical LinguisticsUploaded bySerge Potemkin
- ASNUploaded byMona Waseem
- [IJCST-V3I4P14]: Deepika Irugu, P. Balaji, P. NirupamaUploaded byEighthSenseGroup

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.