Deck 17: Tree Structures
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/102
Play
Full screen (f)
Deck 17: Tree Structures
1
Consider the following tree diagram:
Which of the following statements is NOT correct?
A.Nodes H, M, and X form a subtree
B.Nodes D and K form a subtree
C.Nodes R and N form a subtree
D.Nodes L and T form a subtree

A.Nodes H, M, and X form a subtree
B.Nodes D and K form a subtree
C.Nodes R and N form a subtree
D.Nodes L and T form a subtree
Nodes R and N form a subtree
2
Which of the following statements about trees is NOT correct?
A.The height of a tree is based on the longest path from the root to a leaf.
B.Many tree properties are computed with recursive methods.
C.A simple implementation of a Tree class uses an instance variable for the root node and a nested Node class, which stores the node's data and its children.
D.A subtree rooted at node n is the tree formed by taking n as the root node and including all of its ancestors.
A.The height of a tree is based on the longest path from the root to a leaf.
B.Many tree properties are computed with recursive methods.
C.A simple implementation of a Tree class uses an instance variable for the root node and a nested Node class, which stores the node's data and its children.
D.A subtree rooted at node n is the tree formed by taking n as the root node and including all of its ancestors.
A subtree rooted at node n is the tree formed by taking n as the root node and including all of its ancestors.
3
Consider the following tree diagram:
Which of the following statements is NOT correct?
A.H is a descendant of M
B.N is a descendant of C
C.L is a descendant of C
D.N is a descendant of R

A.H is a descendant of M
B.N is a descendant of C
C.L is a descendant of C
D.N is a descendant of R
H is a descendant of M
4
Consider the following tree diagram:
Which of the following nodes are leaf nodes?
A)C
B)B
C)B and H
D)H

A)C
B)B
C)B and H
D)H
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
5
Consider the following tree diagram:
Which of the following is a path in the tree?
A.R, H, X
B.K, D, P
C.C, R, N, X
D.T, L, P, C

A.R, H, X
B.K, D, P
C.C, R, N, X
D.T, L, P, C
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
6
Consider the following tree diagram:
Which of the following is NOT a path starting with the node P in the tree?
A.P, L, T
B.P, K, D
C.P
D.P, B

A.P, L, T
B.P, K, D
C.P
D.P, B
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
7
Given the Node class (partially shown below), select a statement to complete the recursive method descendants, which is designed to return the number of descendants of a node.
A.num = num + child.descendants();
B.num = num + child.descendants() + 1;
C.num = child.descendants();
D.num = num + child.children.size();

A.num = num + child.descendants();
B.num = num + child.descendants() + 1;
C.num = child.descendants();
D.num = num + child.children.size();
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
8
Given the Node class (partially shown below), select an expression to complete the isLeaf method, which is designed to return true if the node is a leaf, false otherwise.
A.children.size() == 0
B.children.get(0) == null
C.data == null
D.root == null

A.children.size() == 0
B.children.get(0) == null
C.data == null
D.root == null
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
9
Consider the following tree diagram:
Which of the following nodes are siblings?
A.H and M
B.D and B
C.D and U
D.L and T

A.H and M
B.D and B
C.D and U
D.L and T
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
10
Consider the following tree diagram:
Which of the following nodes are interior nodes?
A.C, N, and P
B.B
C.C and P
D.N

A.C, N, and P
B.B
C.C and P
D.N
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
11
Consider the following tree diagram:
Which of the following nodes are child nodes?
A.C
B.C and P
C.C and X
D.P and X

A.C
B.C and P
C.C and X
D.P and X
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
12
Consider the following tree diagram:
What is the height of the subtree with root R?
A.3
B.2
C.4
D.6

A.3
B.2
C.4
D.6
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
13
Consider the following tree diagram:
What is the height of this tree?
A.7
B.3
C.6
D.4

A.7
B.3
C.6
D.4
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
14
Consider the following tree diagram:
Which of the following nodes are root nodes?
A)R
B)P
C)C
D)R and P

A)R
B)P
C)C
D)R and P
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
15
Consider the following tree diagram:
What is the size of the subtree with root R?
A.2
B.4
C.3
D.6

A.2
B.4
C.3
D.6
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
16
Consider the following tree diagram:
Which of the following statements is NOT correct?
A.C is an ancestor of N
B.R is an ancestor of N
C.D is an ancestor of P
D.H is an ancestor of M

A.C is an ancestor of N
B.R is an ancestor of N
C.D is an ancestor of P
D.H is an ancestor of M
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
17
Consider the following tree diagram:
What is the height of this tree?
A.5
B.7
C.3
D.4

A.5
B.7
C.3
D.4
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
18
Consider the following tree diagram:
What is the size of this tree?
A.5
B.6
C.4
D.13

A.5
B.6
C.4
D.13
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
19
Consider the following tree diagram:
Which of the following nodes are parent nodes?
A.R
B.N
C.M
D.B

A.R
B.N
C.M
D.B
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
20
Which of the following statements about trees is NOT correct?
A.The root of the tree does not have a parent.
B.A tree is composed of nodes.
C.A node can have multiple parents.
D.A node can have multiple child nodes.
A.The root of the tree does not have a parent.
B.A tree is composed of nodes.
C.A node can have multiple parents.
D.A node can have multiple child nodes.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
21
Which of the following statements about balanced trees is NOT correct?
A.For a given height, a balanced tree can hold more nodes than an unbalanced tree.
B.In a balanced binary tree, each subtree has approximately the same number of nodes.
C.In a balanced tree, all paths from the root to the leaves have approximately the same length.
D.The efficiency of algorithms for balanced trees is better expressed using the size of the tree than the height of the tree.
A.For a given height, a balanced tree can hold more nodes than an unbalanced tree.
B.In a balanced binary tree, each subtree has approximately the same number of nodes.
C.In a balanced tree, all paths from the root to the leaves have approximately the same length.
D.The efficiency of algorithms for balanced trees is better expressed using the size of the tree than the height of the tree.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
22
Which of the following is NOT an example of a binary tree?
A.A decision tree where each interior node contains a question and the two subtrees correspond to a yes or no answer.
B.An expression tree that shows the order of evaluation in an arithmetic expression.
C.The family tree of a person, which includes all descendants of a person.
D.A Huffman tree where the left and right turns on the paths to the leaves describe binary encodings.
A.A decision tree where each interior node contains a question and the two subtrees correspond to a yes or no answer.
B.An expression tree that shows the order of evaluation in an arithmetic expression.
C.The family tree of a person, which includes all descendants of a person.
D.A Huffman tree where the left and right turns on the paths to the leaves describe binary encodings.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
23
Consider a balanced binary tree with 520 nodes.The average length of all paths from the root to the leaves is approximately ____.
A.10
B.12
C.9
D.13
A.10
B.12
C.9
D.13
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
24
You are using a tree to show the evaluation order of arithmetic expressions.Which of the following statements is NOT correct?
A.Every level of the tree must contain an operator.
B.Leaves contain numbers.
C.The root contains an operator.
D.Interior nodes contain operators.
A.Every level of the tree must contain an operator.
B.Leaves contain numbers.
C.The root contains an operator.
D.Interior nodes contain operators.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
25
Consider the following tree diagram:
Which arithmetic expression is represented by this tree?
A.(2 + 3) + (5 * 4) * 6 * (- 1)
B.[(2 + 3) + (5 * 4)] * (6 - 1)
C.2 + 3 + 5 * 4 - 6 - 1
D.(2 + 3) * (5 * 4) * (6 - 1)
![Consider the following tree diagram: Which arithmetic expression is represented by this tree? A.(2 + 3) + (5 * 4) * 6 * (- 1) B.[(2 + 3) + (5 * 4)] * (6 - 1) C.2 + 3 + 5 * 4 - 6 - 1 D.(2 + 3) * (5 * 4) * (6 - 1)](https://d2lvgg3v3hfg70.cloudfront.net/TB7392/11eb9782_fe11_bcba_b9fe_db3dccdb2a52_TB7392_00.jpg)
A.(2 + 3) + (5 * 4) * 6 * (- 1)
B.[(2 + 3) + (5 * 4)] * (6 - 1)
C.2 + 3 + 5 * 4 - 6 - 1
D.(2 + 3) * (5 * 4) * (6 - 1)
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
26
A balanced binary tree with 260 nodes has a height of approximately ____.
A.13
B.8
C.12
D.10
A.13
B.8
C.12
D.10
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
27
The height h of a completely filled binary tree with n nodes is ____.
A.h= log2(n + 1)
B.h = log2(n) + 1
C.h = log2(n) - 1
D.h = log2(n - 1)
A.h= log2(n + 1)
B.h = log2(n) + 1
C.h = log2(n) - 1
D.h = log2(n - 1)
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
28
The height of a tree can be obtained by recursively computing the heights of its subtrees, while keeping track of the height of the deepest subtree.Given the Node class (partially shown below), select an expression to complete the recursive method height, which is designed to return the height of the tree rooted at a node.
A.maxChildHeight + 1
B.maxChildHeight + 2
C.maxChildHeight
D.maxChildHeight + height()

A.maxChildHeight + 1
B.maxChildHeight + 2
C.maxChildHeight
D.maxChildHeight + height()
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
29
Consider the following tree diagrams:
Which of these trees is considered to be unbalanced?
A.II only
B.III only
C.II and III only
D.I only

A.II only
B.III only
C.II and III only
D.I only
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
30
Which of the following statements about binary trees is correct?
A.Each node in a binary tree has at most two child nodes.
B.If divided down the middle from top to bottom, a binary tree must be symmetrical.
C.Each node in a binary tree has at least two child nodes.
D.The number of child nodes for each node in a binary tree is any power of two.
A.Each node in a binary tree has at most two child nodes.
B.If divided down the middle from top to bottom, a binary tree must be symmetrical.
C.Each node in a binary tree has at least two child nodes.
D.The number of child nodes for each node in a binary tree is any power of two.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
31
Consider the following tree diagrams:
Which tree represents the arithmetic expression (2 + 5) * 4?
A.Both I and II
B.I only
C.Neither I nor II
D.II only

A.Both I and II
B.I only
C.Neither I nor II
D.II only
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
32
A binary tree of height h can have up to ____ nodes.
A.2h + 1
B.2h + 1
C.2h - 1
D.2h- 1
A.2h + 1
B.2h + 1
C.2h - 1
D.2h- 1
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
33
Consider the following tree diagrams:
Which tree represents the arithmetic expression 2 + 5 * 4?
A.Neither I nor II
B.Both I and II
C.II only
D.I only

A.Neither I nor II
B.Both I and II
C.II only
D.I only
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
34
Consider the following tree diagrams:
Which of the above are binary trees?
A.Neither I nor II
B.II only
C.I only
D.Both I and II

A.Neither I nor II
B.II only
C.I only
D.Both I and II
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
35
Consider the following tree diagrams:
Which tree represents the arithmetic expression 2 * 5 + 4?
A.I only
B.Both I and II
C.Neither I nor II
D.II only

A.I only
B.Both I and II
C.Neither I nor II
D.II only
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
36
Consider the following Huffman encoding tree:
The letter H will be encoded as ____.
A.010
B.001
C.011
D.000

A.010
B.001
C.011
D.000
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
37
Consider the following tree diagram:
Which arithmetic expression is represented by this tree?
A.2 * 3 + 5 + 4 * 6 - 1
B.2 * (3 + 5 + 4) * (6 - 1)
C.[(2 * 3) + 5 + 4] * (6 - 1)
D.2 * 3 + 5 + 4 - 6 - 1
![Consider the following tree diagram: Which arithmetic expression is represented by this tree? A.2 * 3 + 5 + 4 * 6 - 1 B.2 * (3 + 5 + 4) * (6 - 1) C.[(2 * 3) + 5 + 4] * (6 - 1) D.2 * 3 + 5 + 4 - 6 - 1](https://d2lvgg3v3hfg70.cloudfront.net/TB7392/11eb9782_fe11_95a9_b9fe_9b63ba935a02_TB7392_00.jpg)
A.2 * 3 + 5 + 4 * 6 - 1
B.2 * (3 + 5 + 4) * (6 - 1)
C.[(2 * 3) + 5 + 4] * (6 - 1)
D.2 * 3 + 5 + 4 - 6 - 1
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
38
Consider the following Huffman encoding tree:
The letter K will be encoded as ____.
A.10
B.001
C.010
D.100

A.10
B.001
C.010
D.100
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
39
Consider the following tree diagrams:
Which of these trees is considered to be balanced?
A.II and III only
B.I only
C.I and II only
D.I and III only

A.II and III only
B.I only
C.I and II only
D.I and III only
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
40
A completely filled binary tree with a height of 3 has ____ nodes.
A.12
B.6
C.7
D.8
A.12
B.6
C.7
D.8
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
41
Consider the following binary search tree diagram:
Consider the following pseudocode for the removal of a node n in a binary search tree:
if n has no children then
remove the node n
if n has only one child then
replace the node n with its child
if n has two children then
replace the node n with the smallest node of its right subtree
If node D is to be removed, which action should be taken?
A.Swap the values in C and D so that C has A as its left child, then remove the new D node.
B.Modify K to point to A as its left child, and modify A to point to F as its right child.
C.Modify K to make its left child null.
D.Modify K to point to F as its left child and modify F to point to A as its left child.

if n has no children then
remove the node n
if n has only one child then
replace the node n with its child
if n has two children then
replace the node n with the smallest node of its right subtree
If node D is to be removed, which action should be taken?
A.Swap the values in C and D so that C has A as its left child, then remove the new D node.
B.Modify K to point to A as its left child, and modify A to point to F as its right child.
C.Modify K to make its left child null.
D.Modify K to point to F as its left child and modify F to point to A as its left child.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
42
Which of the following statements about a binary search tree is correct?
A.You can specify an insert position for inserting a node in the tree.
B.Locating an element in a balanced binary search tree takes O(n) time.
C.The speed of inserting or removing a node is dependent on the shape of the tree.
D.Adding elements that are already sorted will result in a balanced binary search tree.
A.You can specify an insert position for inserting a node in the tree.
B.Locating an element in a balanced binary search tree takes O(n) time.
C.The speed of inserting or removing a node is dependent on the shape of the tree.
D.Adding elements that are already sorted will result in a balanced binary search tree.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
43
If the child references of a binary tree node are both null, the node is ____.
A.a parent node
B.a leaf node
C.an interior node
D.a root node
A.a parent node
B.a leaf node
C.an interior node
D.a root node
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
44
Consider the following binary search tree diagram:
Consider the following addNode method for inserting a newNode into a binary search tree:
public void addNode(Node newNode)
{
int comp = newnode.data.compareTo(data);
if (comp < 0)
{
if (left == null) {left = newNode;}
else { left.addNode(newNode); }
}
else
{
if (right == null) {right = newNode;}
else { right.addNode(newNode); }
}
}
Which of the following trees represents the correct result after inserting element B, calling addNode on the root of the tree?
A.III
B.IV
C.II
D.I

public void addNode(Node newNode)
{
int comp = newnode.data.compareTo(data);
if (comp < 0)
{
if (left == null) {left = newNode;}
else { left.addNode(newNode); }
}
else
{
if (right == null) {right = newNode;}
else { right.addNode(newNode); }
}
}
Which of the following trees represents the correct result after inserting element B, calling addNode on the root of the tree?

A.III
B.IV
C.II
D.I
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
45
Consider the following addNode method for inserting a newNode into a binary search tree:
Which of the following sequences of insertions will result in a balanced tree? In each sequence, the first node inserted becomes the root of the tree on which the addNode method is called for the subsequent insertions.
I 12, 7, 25, 6, 9, 13, 44
II 12, 7, 25, 44, 13, 6, 9
III 12, 25, 44, 13, 6, 9, 7
A.I and II only
B.I only
C.II only
D.I and III only

I 12, 7, 25, 6, 9, 13, 44
II 12, 7, 25, 44, 13, 6, 9
III 12, 25, 44, 13, 6, 9, 7
A.I and II only
B.I only
C.II only
D.I and III only
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
46
In a binary search tree, where the root node data value = 45, what do we know about the data values of all the descendants in the left subtree of the root?
A.all will be < 45
B.some values will be < 45, but there may be a few values > 45
C.approximately half the values are < 45, the other half are > 45
D.the root's left child value < 45, but the right child of the root's left child value is > 45
A.all will be < 45
B.some values will be < 45, but there may be a few values > 45
C.approximately half the values are < 45, the other half are > 45
D.the root's left child value < 45, but the right child of the root's left child value is > 45
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
47
Consider the following binary search tree diagram:
Consider the following pseudocode for the removal of a node n in a binary search tree:
if n has no children then
remove the node n
if n has only one child then
replace the node n with its child
if n has two children then
replace the node n with the smallest node of its right subtree
If node Y is to be removed, which action should be taken?
A.Modify V's right reference to point to X.
B.Modify V to have a null right pointer.
C.Modify V's left reference to point to X.
D.Swap the values in V and X, and modify X's right reference to point to V.

if n has no children then
remove the node n
if n has only one child then
replace the node n with its child
if n has two children then
replace the node n with the smallest node of its right subtree
If node Y is to be removed, which action should be taken?
A.Modify V's right reference to point to X.
B.Modify V to have a null right pointer.
C.Modify V's left reference to point to X.
D.Swap the values in V and X, and modify X's right reference to point to V.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
48
Consider the following binary search tree diagram:
Consider the following pseudocode for the removal of a node n in a binary search tree:
if n has no children then
remove the node n
if n has only one child then
replace the node n with its child
if n has two children then
replace the node n with the smallest node of its right subtree
If node J is to be removed, to which node will H point to instead of J?
A.X
B.N
C.M
D.L

if n has no children then
remove the node n
if n has only one child then
replace the node n with its child
if n has two children then
replace the node n with the smallest node of its right subtree
If node J is to be removed, to which node will H point to instead of J?
A.X
B.N
C.M
D.L
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
49
Consider the following binary search tree diagram:
Consider the following addNode method for inserting a newNode into a binary search tree:
public void addNode(Node newNode)
{
int comp = newnode.data.compareTo(data);
if (comp < 0)
{
if (left == null) {left = newNode;}
else { left.addNode(newNode); }
}
else
{
if (right == null) {right = newNode;}
else { right.addNode(newNode); }
}
}
Which nodes will be visited in order to insert the letter B into this tree, calling addNode on the root of the tree?
A.H, D, and A
B.H and D only
C.H only
D.H, D, and F

public void addNode(Node newNode)
{
int comp = newnode.data.compareTo(data);
if (comp < 0)
{
if (left == null) {left = newNode;}
else { left.addNode(newNode); }
}
else
{
if (right == null) {right = newNode;}
else { right.addNode(newNode); }
}
}
Which nodes will be visited in order to insert the letter B into this tree, calling addNode on the root of the tree?
A.H, D, and A
B.H and D only
C.H only
D.H, D, and F
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
50
In a binary search tree, where the root node data value = 45, what do we know about the values of all the descendants in the right subtree of the root?
A.some values will be > 45, but there may be a few values < 45
B.all will be > 45
C.the root's right child value > 45, but the left child of the root's right child key is < 45
D.approximately half the values are < 45, the other half are > 45
A.some values will be > 45, but there may be a few values < 45
B.all will be > 45
C.the root's right child value > 45, but the left child of the root's right child key is < 45
D.approximately half the values are < 45, the other half are > 45
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
51
A completely filled binary tree with a height of 4 has ____ nodes.
A.16
B.12
C.8
D.15
A.16
B.12
C.8
D.15
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
52
Consider the following tree diagrams:
Which of the above are binary search trees?
A.Neither I nor II
B.I only
C.II only
D.Both I and II

A.Neither I nor II
B.I only
C.II only
D.Both I and II
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
53
If both of the child references of a binary tree node are non-null, it follows that the node must be ____.
A.a child node
B.the root node
C.a leaf node
D.an interior node
A.a child node
B.the root node
C.a leaf node
D.an interior node
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
54
Consider the following binary search tree diagram:
Consider the following addNode method for inserting a newNode into a binary search tree:
public void addNode(Node newNode)
{
int comp = newnode.data.compareTo(data);
if (comp < 0)
{
if (left == null) {left = newNode;}
else { left.addNode(newNode); }
}
else
{
if (right == null) {right = newNode;}
else { right.addNode(newNode); }
}
}
Which nodes will be visited in order to insert the letter E into this tree, calling addNode on the root of the tree?
A.H only
B.H and D only
C.H, D, and A
D.H, D, and F

public void addNode(Node newNode)
{
int comp = newnode.data.compareTo(data);
if (comp < 0)
{
if (left == null) {left = newNode;}
else { left.addNode(newNode); }
}
else
{
if (right == null) {right = newNode;}
else { right.addNode(newNode); }
}
}
Which nodes will be visited in order to insert the letter E into this tree, calling addNode on the root of the tree?
A.H only
B.H and D only
C.H, D, and A
D.H, D, and F
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
55
Consider the following tree diagrams:
Which are binary search trees?
A.Neither I nor II
B.I only
C.Both I and II
D.II only

A.Neither I nor II
B.I only
C.Both I and II
D.II only
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
56
Given the BinaryTree class (partially shown below), select an expression to complete the static recursive helper method rightMostValue, which is designed to return the data value in the rightmost node of the tree rooted at node n.
A.rightMostValue(n.left)
B.rightMostValue(root.right)
C.rightMostValue(n)
D.rightMostValue(n.right)

A.rightMostValue(n.left)
B.rightMostValue(root.right)
C.rightMostValue(n)
D.rightMostValue(n.right)
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
57
Consider the following binary search tree diagram:
Consider the following addNode method for inserting a newNode into a binary search tree:
public void addNode(Node newNode)
{
int comp = newnode.data.compareTo(data);
if (comp < 0)
{
if (left == null) {left = newNode;}
else { left.addNode(newNode); }
}
else
{
if (right == null) {right = newNode;}
else { right.addNode(newNode); }
}
}
Which of the following trees represents the correct result after inserting element T, calling addNode on the root of the tree?
A.II
B.I
C.IV
D.III

public void addNode(Node newNode)
{
int comp = newnode.data.compareTo(data);
if (comp < 0)
{
if (left == null) {left = newNode;}
else { left.addNode(newNode); }
}
else
{
if (right == null) {right = newNode;}
else { right.addNode(newNode); }
}
}
Which of the following trees represents the correct result after inserting element T, calling addNode on the root of the tree?

A.II
B.I
C.IV
D.III
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
58
Locating an element in a balanced binary search tree takes ____ time.
A.O(1)
B.O(log(n))
C.O(n2)
D.O(n)
A.O(1)
B.O(log(n))
C.O(n2)
D.O(n)
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
59
Adding an element to a balanced binary search tree takes ____ time.
A.O(log (n))
B.O(1)
C.O(n2)
D.O(n)
A.O(log (n))
B.O(1)
C.O(n2)
D.O(n)
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
60
Given the BinaryTree class (partially shown below), select an expression to complete the static recursive helper method countLeaves, which returns the number of leaf nodes in the binary tree rooted at node n.
A.n.right == null
B.n.left == null || n.right == null
C.n.left == null
D.n.left == null && n.right == null

A.n.right == null
B.n.left == null || n.right == null
C.n.left == null
D.n.left == null && n.right == null
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
61
Consider the following binary search tree:
Which of the following sequences correctly represents an inorder traversal of this tree?
A.A, C, H, G, E, N, P, M, J
B.J, E, M, C, G, P, A, H, N
C.A, C, E, G, H, J, M, N, P
D.J, E, C, A, G, H, M, P, N

A.A, C, H, G, E, N, P, M, J
B.J, E, M, C, G, P, A, H, N
C.A, C, E, G, H, J, M, N, P
D.J, E, C, A, G, H, M, P, N
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
62
What are the
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
63
If the postorder traversal of an expression tree is 8, 2, +, 5, /, what is the preorder traversal?
A./, +, 2, 8, 5
B.8, +, 2, /, 5
C./, +, 8, 2, 5
D.+, /, 8, 2, 5
A./, +, 2, 8, 5
B.8, +, 2, /, 5
C./, +, 8, 2, 5
D.+, /, 8, 2, 5
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
64
You wish to traverse a binary search tree in sorted order.Arrange the following actions in the correct order to accomplish this.
I Print the right subtree recursively
II Print the root
III Print the left subtree recursively
A.I, II, III
B.II, III, I
C.III, I, II
D.III, II, I
I Print the right subtree recursively
II Print the root
III Print the left subtree recursively
A.I, II, III
B.II, III, I
C.III, I, II
D.III, II, I
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
65
Locating an element in an unbalanced binary search tree takes ____ time.
A.O(n)
B.O(n2)
C.O(1)
D.O(log (n))
A.O(n)
B.O(n2)
C.O(1)
D.O(log (n))
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
66
Removing an element from an unbalanced binary search tree takes ____ time.
A.O(log (n))
B.O(n)
C.O(1)
D.O(n2)
A.O(log (n))
B.O(n)
C.O(1)
D.O(n2)
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
67
Which of the following statements about the three tree traversal schemes studied is correct?
A.Preorder traversal is used for evaluating arithmetic expression trees on a stack-based calculator.
B.Postorder traversal is used for evaluating arithmetic expression trees on a stack-based calculator.
C.Preorder traversal is used for removing file directories by removing subdirectories first.
D.Postorder traversal is used for copying file directories.
A.Preorder traversal is used for evaluating arithmetic expression trees on a stack-based calculator.
B.Postorder traversal is used for evaluating arithmetic expression trees on a stack-based calculator.
C.Preorder traversal is used for removing file directories by removing subdirectories first.
D.Postorder traversal is used for copying file directories.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
68
Consider the following binary search tree:
Which of the following sequences correctly represents a postorder traversal of this tree?
A.J, E, C, A, G, H, M, P, N
B.J, E, M, C, G, P, A, H, N
C.A, C, E, G, H, J, M, N, P
D.A, C, H, G, E, N, P, M, J

A.J, E, C, A, G, H, M, P, N
B.J, E, M, C, G, P, A, H, N
C.A, C, E, G, H, J, M, N, P
D.A, C, H, G, E, N, P, M, J
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
69
Which of the following statements about the three tree traversal schemes studied is correct?
A.Inorder traversal is used for copying file directories.
B.Postorder traversal is used for copying file directories.
C.Postorder traversal is used for removing file directories by removing subdirectories first.
D.Inorder traversal is used for evaluating arithmetic expression trees on a stack-based calculator.
A.Inorder traversal is used for copying file directories.
B.Postorder traversal is used for copying file directories.
C.Postorder traversal is used for removing file directories by removing subdirectories first.
D.Inorder traversal is used for evaluating arithmetic expression trees on a stack-based calculator.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
70
Given the BinarySearchTree and Node classes (partially shown below), select an expression to complete the recursive method smallest in the Node class.The method returns the smallest data value in the binary search tree rooted at a node.
A.right.smallest()
B.left.smallest()
C.Math.min(left.smallest(), right.smallest())
D.data.smallest()

A.right.smallest()
B.left.smallest()
C.Math.min(left.smallest(), right.smallest())
D.data.smallest()
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
71
You wish to traverse a binary search tree using preorder traversal.Arrange the following actions in the correct order to accomplish this.
I Print the right subtree recursively
II Print the root
III Print the left subtree recursively
A.II, III, I
B.II, I, III
C.I, II, III
D.III, I, II
I Print the right subtree recursively
II Print the root
III Print the left subtree recursively
A.II, III, I
B.II, I, III
C.I, II, III
D.III, I, II
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
72
Consider the following binary search tree:
Which of the following sequences correctly represents a preorder traversal of this tree?
A.J, E, M, C, G, P, A, H, N
B.J, E, C, A, G, H, M, P, N
C.A, C, H, G, E, N, P, M, J
D.A, C, E, G, H, J, M, N, P

A.J, E, M, C, G, P, A, H, N
B.J, E, C, A, G, H, M, P, N
C.A, C, H, G, E, N, P, M, J
D.A, C, E, G, H, J, M, N, P
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
73
Adding an element to an unbalanced binary search tree takes ____ time.
A.O(n)
B.O(1)
C.O(log (n))
D.O(n2)
A.O(n)
B.O(1)
C.O(log (n))
D.O(n2)
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
74
You wish to traverse a binary search tree using postorder traversal.Arrange the following actions in the correct order to accomplish this.
I Print the right subtree recursively
II Print the root
III Print the left subtree recursively
A.III, II, I
B.I, III, II
C.III, I, II
D.I, II, III
I Print the right subtree recursively
II Print the root
III Print the left subtree recursively
A.III, II, I
B.I, III, II
C.III, I, II
D.I, II, III
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
75
Which of the following statements about breadth-first and depth-first traversal is NOT correct?
A.Depth-first search goes deeply into the tree and then backtracks when it reaches the leaves.
B.Breadth-first and depth-first search only work on a binary tree.
C.Breadth-first search first visits all nodes on the same level before visiting the children.
D.Depth-first search uses a stack to track the nodes that it visits.
A.Depth-first search goes deeply into the tree and then backtracks when it reaches the leaves.
B.Breadth-first and depth-first search only work on a binary tree.
C.Breadth-first search first visits all nodes on the same level before visiting the children.
D.Depth-first search uses a stack to track the nodes that it visits.
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
76
Assuming that the variable t is instantiated to an empty BinarySearchTree, select a statement to complete the following code segment, so that the resulting binary search tree has a height of 4.
A.t.add("your");
B.t.add("the");
C.t.add("his");
D.t.add("my");

A.t.add("your");
B.t.add("the");
C.t.add("his");
D.t.add("my");
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
77
Removing an element from a balanced binary search tree takes ____ time.
A.O(1)
B.O(log (n))
C.O(n2)
D.O(n)
A.O(1)
B.O(log (n))
C.O(n2)
D.O(n)
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
78
Given the Visitor interface discussed in section 17.4 (shown below), select a statement to complete the class CodeFinder.The class is to be used when traversing a binary tree while displaying every data value that contains the code "007".
A.data.toString().indexOf("007") > 0
B.data.equals("007")
C.data.toString().indexOf("007") >= 0
D.data.contains("007")

A.data.toString().indexOf("007") > 0
B.data.equals("007")
C.data.toString().indexOf("007") >= 0
D.data.contains("007")
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
79
If the postorder traversal of an expression tree is 8, 2, +, 5, /, what is the numeric result of that Reverse Polish Notation expression?
A.8
B.2
C.7
D.15
A.8
B.2
C.7
D.15
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck
80
If the postorder traversal of an expression tree is, 8, 2, +, 5, /, what is the result of an inorder traversal?
A.+, /, 8, 2, 5
B.8, +, 2, /, 5
C./, +, 2, 8, 5
D./, +, 8, 2, 5
A.+, /, 8, 2, 5
B.8, +, 2, /, 5
C./, +, 2, 8, 5
D./, +, 8, 2, 5
Unlock Deck
Unlock for access to all 102 flashcards in this deck.
Unlock Deck
k this deck