Introduction to C++ Programming, Y. Daniel Liang

Chapter 17 Trees, Heaps, and Priority Queues


Section 17.2 Binary Trees
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

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.

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

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

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

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

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.

8  If you insert 4, 5, 1, 2, 9, 3 into a binary search tree in this order, what the printout of the inorder traversal?

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

Section 17.3 Heaps
9  Which of the following statements are true?

A. A heap is a complete binary tree.
B. Each node is greater than or equal to any of its children.
C. A binary tree is complete if every level of the tree is full except that the last level may not be full and all the leaves on the last level are placed left-most.
D. A heap is a full binary tree.

10  To remove the root, you need to start a process by first placing _______ to the place of the root and move it down to maintain the heap property.

A. one of the root's children
B. the larger child of the root
C. the smaller child of the root
D. the last node in the heap

11  To add a new node in the heap, you need to start a process by first placing it as _______ and move it up to main the heap property.

A. the new root
B. the last node in the heap
C. the left child of the root
D. the right child of the root

Section 17.4 Priority Queues
12  Which data structure is appropriate to store patients in an emergency room?
A. Stack
B. Queue
C. Priority Queue
D. Linked List