Introduction to Programming with C++, Third Edition, Y. Daniel Liang

This quiz is for students to practice. A large number of additional quiz is available for instructors using Quiz Generator from the Instructor's Resource Website. Videos for Java, Python, and C++ can be found at https://yongdanielliang.github.io/revelvideos.html.

Many questions in this edition have been updated in the new edition. Please check with the publisher on the newest edition.

Chapter 21 Trees, Heaps, and Priority Queues


Section 21.2 Binary Trees
21.1  A __________ (with no duplicate elements) has the property that for every node in the tree the value of any node in its left subtree is less than the value of the node and the value of any node in its right subtree is greater than the value of the node.
A. binary tree
B. binary search tree
C. list
D. linked list

21.2  In the implementation of BinaryTree, which of the following are true?
A. Node is defined as a class inside BinaryTree.
B. Node is defined as a class inside BinaryTree because it is only used inside the BinaryTree class.
C. Node has a property named left that links to the left subtree and a property named right that links to the right subtree.
D. BinaryTree contains a property named root. If tree is empty, root is null.

21.3  The ________ is to visit the left subtree of the current node first, then the current node itself, and finally the right subtree of the current node.
A. inorder traversal
B. preorder traversal
C. postorder traversal
D. breadth-first traversal

21.4  The _________ is to visit the left subtree of the current node first, then the right subtree of the current node, and finally the current node itself.
A. inorder traversal
B. preorder traversal
C. postorder traversal
D. breadth-first traversal

21.5  The _________ is to visit the current node first, then the left subtree of the current node, and finally the right subtree of the current node.
A. inorder traversal
B. preorder traversal
C. postorder traversal
D. breadth-first traversal

21.6  The _________ is to visit the nodes level by level. First visit the root, then all children of the root from left to right, then grandchildren of the root from left to right, and so on.
A. inorder traversal
B. preorder traversal
C. postorder traversal
D. breadth-first traversal

21.7  If a set of the same elements is inserted into a binary tree in two different orders, which of the following statements are true?
A. The two corresponding binary trees look the same.
B. The inorder traversal generate the same sequence of nodes.
C. The preorder traversal generate the same sequence of nodes.
D. The postorder traversal generate the same sequence of nodes.

21.8  If you insert 4, 5, 1, 2, 9, 3 into a binary search tree in this order, what the inorder traversal of this tree?
A. 4, 5, 1, 2, 9, 3
B. 3, 9, 2, 1, 5, 4
C. 1, 2, 3, 4, 5, 9
D. 2, 5, 1, 4, 9, 3