C++ Ch 21 All Review and Exercise Questions

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

1. Each node in a binary tree may point to how many other nodes?

1. Two others.

10. A(n) is an entire branch of the tree, from one particular node down.

10. subtree

11. The three common types of traversal with a binary tree are and

11. inorder, preorder, and postorder

12. Write a pseudocode algorithm for inserting a node in a tree.

12. Create a new node. Store a value in the new node. Set the new node's children pointers to a null pointer. If the tree is empty Make root point to the new node. Else Starting at the root node, compare the new node's value with the existing nodes' values. When the new node's value is less than the existing node's value, go the node's left child for the next comparison. Otherwise, go to the right. Repeat this process until a null child pointer is found. That is the insertion point. End If.

13. Write a pseudocode algorithm for the inorder traversal.

13. (Recursive Function) Display In Order(Node Pointer) If Node Pointer is not a null pointer Display In Order (Node Pointer -> Left). Display the node's Value. Display In Order (Node Pointer -> Right). End If End Display In Order

14. Write a pseudocode algorithm for the preorder traversal.

14. (Recursive Function) Display Pre Order(Node Pointer) If Node Pointer is not a null pointer Display the node's Value. Display Pre Order (Node Pointer -> Left). Display Pre Order (Node Pointer -> Right). End If End Display Pre Order

15. Write a pseudocode algorithm for the postorder traversal.

15. (Recursive Function) Display Post Order(Node Pointer) If Node Pointer is not a null pointer Display Post Order (Node Pointer -> Left). Display Post Order (Node Pointer -> Right). Display the node's Value. End If End Display Post Order

16. Write a pseudocode algorithm for searching a tree for a specified value.

16. Node Pointer = Root. While Node Pointer is not a null pointer If Node Pointer -> Value equals the Search Value Return True. // Item found Else If the Search Value is less than Node Pointer -> Value Node Pointer = Node Pointer -> Left. Else Node Pointer = Node Pointer -> Right. End If. End While. Return False. // Item not found

How would the values in the tree you sketched for question 17 be displayed in an inorder transversal?

18. 3 7 9 10 12 14 18 20 22 24 30

How would the values in the tree you sketched for question 17 be displayed in an preorder transversal?

19. 12 7 3 9 10 22 18 14 20 24 30

2. How many predecessors may each node other than the root node have?

2. Only one.

How would the values in the tree you sketched for question 17 be displayed in an postorder transversal?

20. 3 10 9 7 14 20 18 30 24 22 12

True or False: Each node in a binary tree must have at least two children.

21. true

True or False: Values stored in the current node's left subtree are less than the value stored in the current node.

22. false

True or False: When a node is inserted into a tree, it must be inserted as a leaf node.

23. true

True or False: The shape of a binary tree is determined by the order in which values are inserted.

24. true

True or False: In inorder traversal, the node's data is processed first, then the left and right nodes are visited.

25. false

3. What is a leaf node?

3. A node that has no children.

4. What is a subtree?

4. An entire branch of the tree, from one particular node down.

5. What initially determines the shape of a binary tree?

5. The order in which the values are inserted.

6. What are the three methods of traversing a binary tree? What is the difference between these methods?

6. Inorder, preorder, and postorder: Inorder traversal 1. The node's left subtree is traversed. 2. The node's data is processed. 3. The node's right subtree is traversed. Preorder traversal 1. The node's data is processed 2. The node's left subtree is traversed. 3. The node's right subtree is traversed. Postorder traversal 1. The node's left subtree is traversed. 2. The node's right subtree is traversed. 3. The node's data is processed.

7. The first node in a binary tree is called the _

7. root node

8. A binary tree node's left and right pointers point to the node's

8. children

9. A node with no children is called a(n)

9. leaf node


Set pelajaran terkait

Chapter 1: The Political Culture, People, and Economy of Texas

View Set

Abnormal Psychology Chapter 15 Quiz

View Set

Ch 47- Mgmt of Pt with intestinal and rectal disorders, MedSurg Chapter 47: PrepU, Intestinal and Rectal Disorders Prep U, prep chapter 48, LWW - Ch. 47: Mgmt of Patients With Intestinal and Rectal Disorders, Chapter 48 Management of Patients with In…

View Set

Chapter 17. Activity - Based costing and analysis

View Set

Major Nerve Plexuses and Select Nerves

View Set