613 views

Uploaded by Raffi Sk

17

- Data Structure Simple
- opr000I6
- 48702225-DS-BOOK
- Data Structures and Other Objects Using C++, Third Edition, by Michael Main and Walter Savitch
- 48702225-DS-BOOK
- DS CS qb
- Sample Data Structures Questions
- Trees1x1
- List
- 5. Binary Tree Traversal
- Data Structures and Other Objects Using C++, Third Edition, by Michael Main and Walter Savitch
- binTrees1
- CSCE 3110 Data Structures & Algorithm Analysis: Binary Trees
- Data Structures Using C++
- Sample Data Structures Questions - Chapter 2
- GeeksforGeeks placement questions
- Binary Tree Overview
- 9. Binary Trees and Binary Search Trees
- Make Money Fast! - Department of Computer Science-copypasteads.com
- epi-toc-1.4.3

You are on page 1of 9

Data Structures and Other Objects Using C++ by Michael Main and Walter Savitch Second Edition ISBN 0-201-70297-5, Softcover, 816 pages, 2000

The Purpose of These Questions These are typical exam questions from Chapter 10 of the textbook. These exact questions might not be on your exam, but if you research and find the right answers to these questions, that should be good preparation for a real exam. (It's also possible that some of this material was not covered in your class.) At the moment there are 20 short answer questions and 20 multiple choice questions in this file. Short Answers Section 10.1 Introduction to Trees Short Answers 1. Here is a small binary tree:

2. 3. 4. 5. 6. 7. 8. / / \ 1 3 2 14 \ 11 / \ 10 30 / / 7 40

Circle all the leaves. Put a square box around the root. Draw a star around each ancestor of the node that contains 10. Put a big X through every descendant of the node the contains 10. Short Answers Section 10.2 Tree Representations 9. Draw a full binary tree with at least 6 nodes. 10. Draw a complete binary tree with exactly six nodes. Put a different value in each node. Then draw an array with six components and show where each of the six

node values would be placed in the array (using the usual array representation of a complete binary tree). 11. Write the private member variables for a new node definition that could be used for a node in a tree where: (1) Each node contains int data, (2) Each node has up Short Answers Section 10.3 A Toolkit for Binary Tree Nodes to four children, and (3) Each node also has a pointer to its parent. Store the pointers to the children in an array of four pointers. 12. Draw a binary taxonomy tree that can be used for these four animals: Rabbit, Horse, Whale, Snake. 13. Using the binary_tree_node from page 465, write a function to meet the following specification. Check as much of the precondition as possible. No recursion is needed.

14. template <class Item> 15. void subswap(binary_tree_node<Item>* root_ptr) 16. // Precondition: root_ptr is the root pointer of a non-empty binary tree. 17. // Postcondition: The original left subtree has been moved and is now the right 18. // subtree, and the original right subtree is now the left subtree. 19. // Example original tree: Example new tree: 20. // 1 1 21. // / \ / \ 22. // 2 3 3 2 23. // / \ / \ 24. // 4 5 4 5

25. template <class Item> Using the binary_tree_node from page 465, write a recursive function to meet the following specification. Check as much of the precondition as possible.

26. template <class Item> 27. void flip(binary_tree_node<Item>* root_ptr) 28. // Precondition: root_ptr is the root pointer of a non-empty binary tree. 29. // Postcondition: The tree is now the mirror image of its original value. 30. // Example original tree: Example new tree: 31. // 1 1 32. // / \ / \

33. // 34. // 35. // 2 / \ 4 5 3 3 5 2 / \ 4

/ / \ 1 3 2

14

11 / \ 10 30 / / 7 40

Write the order of the nodes visited in: A. An in-order traversal: B. A pre-order traversal: C. A post-order traversal: 44. Using the binary_tree_node from page 465, Write a recursive function to meet the following specification. You do not need to check the precondition.

45. 46. 47. 48. template <class Item> void increase(binary_tree_node<Item>* root_ptr) // Precondition: root_ptr is the root pointer of a binary tree. // Postcondition: Every node of the tree has had its data increased by one.

49. Using the binary_tree_node from page 465, write a recursive function to meet the following specification. You do not need to check the precondition.

50. 51. 52. 53. template <class Item> size_t many_nodes(binary_tree_node<Item>* root_ptr) // Precondition: root_ptr is the root pointer of a binary tree. // Postcondition: The return value is the number of nodes in the tree. 54. // NOTES: The empty tree has 0 nodes, and a tree with just a root has 55. // 1 node.

56. Using the binary_tree_node from page 465, write a recursive function to meet the following specification. You do not need to check the precondition.

57. 58. 59. 60. template <class Item> int tree_depth(binary_tree_node<Item>* root_ptr) // Precondition: root_ptr is the root pointer of a binary tree. // Postcondition: The return value is the depth of the binary tree. 61. // NOTES: The empty tree has a depth of -1 and a tree with just a root 62. // has a depth of 0.

63. Using the binary_tree_node from page 465, write a function to meet the following specification. You do not need to check the precondition.

64. template <class Item> 65. size_t count42(binary_tree_node<Item>* root_ptr) 66. // Precondition: root_ptr is the root pointer of a binary tree (but 67. // NOT NECESSARILY a search tree). 68. // Postcondition: The return value indicates how many times 42 appears 69. // in the tree. NOTE: If the tree is empty, the function returns zero.

70. Using the binary_tree_node from page 465, write a function to meet the following specification. You do not need to check the precondition.

71. template <class Item> 72. bool has_42(binary_tree_node<Item>* root_ptr) 73. // Precondition: root_ptr is the root pointer of a binary tree (but 74. // NOT NECESSARILY a search tree). 75. // Postcondition: The return value indicates whether 42 appears somewhere 76. // in the tree. NOTE: If the tree is empty, the function returns false.

77. Using the binary_tree_node from page 465, write a function to meet the following specification. You do not need to check the precondition.

78. template <class Item> 79. bool all_42(binary_tree_node<Item>* root_ptr) 80. // Precondition: root_ptr is the root pointer of a binary tree (but 81. // NOT NECESSARILY a search tree). 82. // Postcondition: The return value is true if every node in the tree 83. // contains 42. NOTE: If the tree is empty, the function returns true.

84. Using the binary_tree_node from page 465, write a recursive function to meet the following specification. You do not need to check the precondition.

85. 86. 87. 88. template <class Item> int sum_all(binary_tree_node<Item>* root_ptr) // Precondition: root_ptr is the root pointer of a binary tree. // Postcondition: The return value is the sum of all the data in all the nodes.

89. // NOTES: The return value for the empty tree is zero.

90. Suppose that we want to create a binary search tree where each node contains information of some data type called Item (which has a default constructor and a correct value semantics). What additional factor is required for the Item data type? 91. Suppose that a binary search tree contains the number 42 at a node with two children. Write two or three clear sentences to describe the process required to delete the 42 from the tree. 92. Using the binary_tree_node from page 465, write a function to meet the following specification. You do not need to check the precondition. Make the function as efficient as possible (do not visit nodes unnecessarily):

93. template <class Item> 94. size_t count42(binary_tree_node<Item>* root_ptr) 95. // Precondition: root_ptr is the root pointer of a binary SEARCH tree. 96. // Postcondition: The return value indicates how many times 42 appears 97. // in the tree.

98. Using the binary_tree_node from page 465, write a function to meet the following specification. You do not need to check the precondition. Make the function as efficient as possible (do not visit nodes unnecessarily):

99. template <class Item> 100. int max(binary_tree_node<Item>* root_ptr) 101. // Precondition: root_ptr is the root pointer of a nonempty binary SEARCH 102. // tree. 103. // Postcondition: The return value is the largest value in the tree.

104. Using the binary_tree_node from page 465, write a function to meet the following specification. You do not need to check the precondition.

105. template <class Item> 106. void insert_one_42(binary_tree_node<Item>*& root_ptr) 107. // Precondition: root_ptr is the root pointer of a binary SEARCH tree.

14 2 / / \ 1 3 11 / \ 10 30 / / 7 40 \

108. // Postcondition: One copy of the number 42 has been added to the binary 109. // search tree.

Multiple Choice 1. There is a tree in the box at the top of this section. How many leaves does it have? o A. 2 o B. 4 o C. 6 o D. 8 o E. 9 2. There is a tree in the box at the top of this section. How many of the nodes have at least one sibling? o A. 5 o B. 6 o C. 7 o D. 8 o E. 9 3. There is a tree in the box at the top of this section. What is the value stored in the parent node of the node containing 30?

A. 10 B. 11 C. 14 D. 40 E. None of the above 4. There is a tree in the box at the top of this section. How many descendants does the root have? o A. 0 o B. 2 o C. 4 o D. 8 5. There is a tree in the box at the top of this section. What is the depth of the tree? o A. 2 o B. 3 o C. 4 o D. 8 o E. 9 6. There is a tree in the box at the top of this section. How many children does the root have? o A. 2 o B. 4 o C. 6 o D. 8 o E. 9 7. Consider the binary tree in the box at the top of this section. Which statement is correct? o A. The tree is neither complete nor full. o B. The tree is complete but not full. o C. The tree is full but not complete. o D. The tree is both full and complete. 8. What is the minimum number of nodes in a full binary tree with depth 3? o A. 3 o B. 4 o C. 8 o D. 11 o E. 15 9. What is the minimum number of nodes in a complete binary tree with depth 3? o A. 3 o B. 4 o C. 8 o D. 11 o E. 15 10. Select the one true statement. o A. Every binary tree is either complete or full. o B. Every complete binary tree is also a full binary tree.

o o o o o

C. Every full binary tree is also a complete binary tree. D. No binary tree is both complete and full. 11. Suppose T is a binary tree with 14 nodes. What is the minimum possible depth of T? o A. 0 o B. 3 o C. 4 o D. 5 12. Select the one FALSE statement about binary trees: o A. Every binary tree has at least one node. o B. Every non-empty tree has exactly one root node.

o o

Multiple Choice Section 10.2 Tree Representations C. Every node has at most two children. D. Every non-root node has exactly one parent. 13. Consider the binary_tree_node from page 465. Which expression indicates that t represents an empty tree? o A. (t == NULL) o B. (t->data( ) == 0) o C. (t->data( ) == NULL) o D. ((t->left( ) == NULL) && (t->right( ) == NULL)) 14. Consider the node of a complete binary tree whose value is stored in data[i] for an array implementation. If this node has a right child, where will the right child's value be stored? o A. data[i+1] o B. data[i+2]

o o

Multiple Choice Section 10.3 A Toolkit for Binary Tree Nodes C. data[2*i + 1] D. data[2*i + 2] 15. How many recursive calls usually occur in the implementation of the tree_clear function for a binary tree? o A. 0 o B. 1 o C. 2 16. Suppose that a binary taxonomy tree includes 8 animals. What is the minimum number of NONLEAF nodes in the tree? o A. 1 o B. 3

o o

14 2 / / \ 1 3 11 / \ 10 30 / / 7 40 \

o o o

C. 5 D. 7 E. 8

17. There is a tree in the box at the top of this section. What is the order of nodes visited using a pre-order traversal? o A. 1 2 3 7 10 11 14 30 40 o B. 1 2 3 14 7 10 11 40 30 o C. 1 3 2 7 10 40 30 11 14 o D. 14 2 1 3 11 10 7 30 40 18. There is a tree in the box at the top of this section. What is the order of nodes visited using an in-order traversal? o A. 1 2 3 7 10 11 14 30 40 o B. 1 2 3 14 7 10 11 40 30 o C. 1 3 2 7 10 40 30 11 14 o D. 14 2 1 3 11 10 7 30 40 19. There is a tree in the box at the top of this section. What is the order of nodes visited using a post-order traversal? o A. 1 2 3 7 10 11 14 30 40 o B. 1 2 3 14 7 10 11 40 30 Multiple Choice Section 10.5 Binary Search Trees C. 1 3 2 7 10 40 30 11 14 D. 14 2 1 3 11 10 7 30 40 20. Consider this binary search tree:

o o 21. 22. 23. 24. 25. 26. 27. / / \ 1 4 / 5 2 14 \ 16

Suppose we remove the root, replacing it with something from the left subtree. What will be the new root?

o o o o o

A. 1 B. 2 C. 4 D. 5 E. 16

Michael Main (main@colorado.edu) and Walter Savitch (wsavitch@ucsd.edu) Thank you for visiting http://www.cs.colorado.edu/~main/questions/chap10q.html Copyright 2000 Addison-Wesley Computer and Engineering Publishing Group

- Data Structure SimpleUploaded byTripti Mishra
- opr000I6Uploaded byPrabhu
- 48702225-DS-BOOKUploaded bySeema Kashyap
- Data Structures and Other Objects Using C++, Third Edition, by Michael Main and Walter SavitchUploaded byMd Rubaiyat Bhuiyan
- 48702225-DS-BOOKUploaded byPrateek Sharma
- DS CS qbUploaded byAbubaker Siddique
- Sample Data Structures QuestionsUploaded byrethic
- Trees1x1Uploaded byshwetashetty1990
- ListUploaded byRaffi Sk
- 5. Binary Tree TraversalUploaded bySenthil Pi
- Data Structures and Other Objects Using C++, Third Edition, by Michael Main and Walter SavitchUploaded byMd Rubaiyat Bhuiyan
- binTrees1Uploaded bykarthikc_625
- CSCE 3110 Data Structures & Algorithm Analysis: Binary TreesUploaded bycount3r5tr1ke
- Data Structures Using C++Uploaded byInsane Clown Prince
- Sample Data Structures Questions - Chapter 2Uploaded bykarthik
- GeeksforGeeks placement questionsUploaded byRadhika Parik
- Binary Tree OverviewUploaded bykusum
- 9. Binary Trees and Binary Search TreesUploaded byYogesh Yadav
- Make Money Fast! - Department of Computer Science-copypasteads.comUploaded byMike
- epi-toc-1.4.3Uploaded bySandeep Kaushik
- Assignment 8Uploaded bySonu Parmani
- TreesUploaded byRoshani Shetty
- 27287326-Algorithms-and-Data-StructuresUploaded bykvvbgayathri
- report101.pptxUploaded bysayonaitobes
- Data Structure Lec22 HandoutUploaded byJʋŋaiɗ Aĸɓar
- Notes 13Uploaded bysavio77
- Recorrido del árbolUploaded byMarco Caceres
- ch9.3.pptUploaded byVenkatanagasudheer Thummapudi
- Data Structure %26 LeftOversUploaded bykingonline
- Data Structure MCQsUploaded byShuseel Baral

- DM7474.pdfUploaded byRaffi Sk
- (www.entrance-exam.net)-25 August 2007 sriindu collge.pdfUploaded byRaffi Sk
- TermsUploaded byRaffi Sk
- VLSI LAB DOCUMENTUploaded byRaffi Sk
- lab1Uploaded byRaffi Sk
- lab1Uploaded byRaffi Sk
- (www.entrance-exam.net)-Wipro_sample_paper_2.pdfUploaded byRaffi Sk
- wipro3Uploaded byakmalrahman
- Compile Test CodesUploaded byRaffi Sk
- VgaUploaded byfenutfenut
- 10.1.1.86Uploaded byMahendra Reddy
- Chp8Uploaded bykr_ravi
- New Text DocumentsssUploaded byRaffi Sk
- 2 Design Specification for 4 Bit ProcessorUploaded byRaffi Sk
- (Www.entrance Exam.net) Electronics Based CompaniesUploaded byPrativendra Patel
- 4bit processor.txtUploaded byRaffi Sk
- adc0808Uploaded byAmine Ichigo
- Chapter6 DataflowUploaded byRaffi Sk
- OopUploaded byRaffi Sk
- Chapter 4Uploaded byRaffi Sk
- Synonyms & AntonymsUploaded byMohan
- Tcs Talent Test 015Uploaded byRaffi Sk
- A Greedy Algorithm for Wire Length OptimizationUploaded byRaffi Sk
- 265lab06F2012answers_2Uploaded byRaffi Sk
- 04041915Uploaded byRaffi Sk
- Cadence5_www.engineering108.com.docUploaded byRaffi Sk
- Assignment6 Solution 3rd EditionUploaded byRaffi Sk
- 06242064Uploaded byRaffi Sk
- 2 Design Specification for 4 Bit ProcessorUploaded byRaffi Sk
- New Text Document (3)Uploaded byRaffi Sk

- Imp_Robert Shepherd_Faculty Profile - School of Mechanical & Aerospace Engineering - Cornell EngineeringUploaded bySkmack
- Cep Exam Study PlanUploaded byI Kailash Rao
- Easy Set-up Guide for the 550 Reg MattingUploaded bygenid.ss
- manual+de+serviço+motog+2+XT1063-XT1064-XT1068-XT1069+Uploaded byToni Alvaro Soares
- https://www.scribd.com/book/334349612/Jeet-AapkiUploaded byBhupendra
- Biology Related General Knowledge Questions and Answers - Page 2Uploaded byRajeev Kumar
- 3d Map Generator-terrain Short-InstructionsUploaded byAhmed Bikarnaf
- Calcs HETPUploaded byChemEngGirl89
- Load AnalysisUploaded byIrfanButt
- phy-pdf-1Uploaded byab
- Appendix a for Malab Assignment 4Uploaded bySadia Murshad
- ES Development Tools1Uploaded bylavanyakodidasu
- Power Structure ManualUploaded byTitus Muntean
- 7 Split Cls AdcUploaded byKarthik Koneru
- author jim grayUploaded byapi-233448344
- 2013 4M3 Liquid Liquid ExtractionUploaded byAndré Mendes Piol
- AGACAD_Building BIM Together_broshure 2015Uploaded bymymikeymikes
- c Asm ExampleUploaded byvasudevan
- lesson plan - debate - displacementUploaded byapi-335568174
- Review on Different Trends in FSWUploaded byKaushik Sengupta
- LimitsUploaded byAbderrahman El Oufir
- Thermal-Radiation-System-Manual-TD-8553-1(1).pdfUploaded byDaniel Parra
- visionplus-testing-services_csUploaded byVinod Makani
- lis6511 draft 2Uploaded byapi-386365051
- Cost Effective and Efficient Industrial Tank Cleaning ProcessUploaded byesatjournals
- N-40-01Uploaded byمنير أحمد
- Modelling and Simulation of Three Level VSI-Neutral Point Balancing -Fed AC Drive using Intelligence TechniquesUploaded byAnonymous 7VPPkWS8O
- (de Gruyer Studies in Mathematical Physics) Anna G. Chunovkina, Leonid a. Mironovsky, Valery a. Slaev-Metrology and Theory of Measurement-De Gruyter (2013)Uploaded byGovinda Prasad Dhungana
- Practicum SyllabusUploaded byMelissa M. Merritt
- MANUAL International.pdfUploaded byTallerGarza