Introduction to Java Programming, Seventh Edition, Y. Daniel Liang

Chapter 25 Trees, Iterators, Heaps, and Priority Queues


Section 25.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 an inner class inside BinaryTree.
B. Node is defined as a static inner class inside BinaryTree because it does not reference any instance data fields in BinaryTree.
C. Node has a property named left that links to the left subtree and a property named right that links to the right subtree and a property named right
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

Section 25.5 Heaps
7  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.

8  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

9  To add a new node, you need to start a process by first placing it as _______ and move it up to maintain 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 25.6 Priority Queues
10  Which data structure is appropriate to store patients in an emergency room?

A. Stack
B. Queue
C. Priority Queue
D. Linked List

11  Which data structure is appropriate to store customers in a clinic for taking flu shots?

A. Stack
B. Queue
C. Priority Queue
D. Array List
E. Linked List

12  Suppose the rule of the party is that the participants who arrive later will leave earlier. Which data structure is appropriate to store the participants?
A. Stack
B. Queue
C. Array List
D. Linked List