Binary Tree Heap Test
Binary Tree Heap Test
Binary Tree Heap Test
com
A+ Computer Science
Binary Tree and Heap M/C TEST
Directions :: On your answer sheet, mark the letter of the best answer to each question.
1. What is the best case for finding an item in a binary search tree?
a. o(n)
b. o(log2n)
c. o(n*n)
d. o(n/2)
e. o(1)
2. How many children can the root node of binary tree have?
a. 2
b. 3
c. 1
d. 0
e. 4
a. inorder
b. preorder
c. postorder
d. reverse
e. funorder
a. inorder
b. preorder
c. postorder
d. reverse
e. funorder
a. inorder
b. preorder
c. postorder
d. reverse
e. funorder
a. inorder
b. preorder
c. postorder
d. reverse
e. funorder
7. A complete binary tree will
a. 3
b. 5
c. 1
d. 4
e. 2
11. Given a complete tree with 4 levels, how many leaves could this tree have?
I. 2
II. 6
III. 12
a. I only
b. II only
c. III only
d. I and II only
e. I and III only
12. How many nodes would a full tree with 5 levels have?
a. 15
b. 16
c. 32
d. 31
e. 63
13. Which of the following is true for a heap that stores the minimum priority value at the
root?
a. The root will be the item with the lowest value in the tree.
b. The nodes from the root down are in sorted order by level.
c. The root will be the item with the greatest value in the tree.
d. The nodes from the root down are in sorted order by branch.
e. none of these answers are correct.
14. If a complete tree has 3 levels, which of the following are possible node counts for the tree?
a. 9
b. 5
c. 3
d. 2
e. 11
a. 5
b. 6
c. 7
d. 8
e. 9
19. Why do you have to have return tree at the bottom of method fun?
out.println(w.getLeft().getLeft().getValue());
a. 45
b. 200
c. 100
d. 99
e. 13
a. 0
b. the number of nodes in the tree
c. the numeric sum of all nodes
d. the sum of all node values that are leaves
e. the sum of all node values as one big string
22. If you insert the following numbers in the order listed into a binary search tree, which of
the following represents the tree’s in order traversal output?
Items inserted in the following order : 200 150 225 75 210 250
23. If you insert the following numbers in the order listed into a binary search tree, which of
the following represents the tree’s pre order traversal output?
Items inserted in the following order: 200 150 225 75 210 250
24. If you insert the following numbers in the order listed into a binary search tree, which of
the following represents the tree’s post order traversal output?
Items inserted in the following order : 200 150 225 75 210 250
25. If you insert the following numbers in the order listed into a binary search tree, which of
the following represents the tree’s reverse order traversal output?
Items inserted in the following order: 200 150 225 75 210 250
26. Assuming t does not equal null, which of the following blocks of code would fill // blank
1 so that method fun would return the minimum value in the tree?
I.
while(t!=null)
{
t=t.getLeft();
}
return t.getValue();
II.
while(t!=null&&t.getLeft()!=null)
{
t=t.getLeft();
}
return t.getValue();
III.
while(t!=null)
{
t=t.getLeft();
}
return t;
a. I
b. I and II
c. III only
d. II and III
e. II only
27. Assuming t does not equal null, which of the following blocks of code would fill // blank
1 so that method fun would return the maximum value in the tree?
I.
while(t != null)
{
t=t.getRight();
}
return t;
II.
while(t!=null && t.getRight()!=null)
{
t=t.getRight();
}
return t.getValue();
III.
while(t != null)
{
t=t.getLeft();
}
return t.getValue();
a.I
b.I and II
c.II only
d.II and III
e.III only
28. What is wrong with the traversal at right?
29. How many leaves max could a complete tree with 6 nodes have?
a. 3
b. 4
c. 5
d. 6
e. 7
30. Assuming tree does not equal null, which of the following blocks of code would fill
//blank 1 so that method go would return a String containing all nodes in pre order?
I.
if(tree==null)
return "";
return "" + go(tree.getLeft())+ " " +
tree.getValue() + " " + go(tree.getRight());
II.
if(tree==null)
return "";
return "" + go(tree.getLeft()) +
go(tree.getRight())+ tree.getValue() + " ";
III.
if(tree==null)
return "";
return "" + tree.getValue() + " " +
go(tree.getLeft())+ go(tree.getRight());
a. I only
b. I and II only
c. II only
d. II and III only
e. III only
a. All right child nodes have greater values than the parent node
b. All left child nodes have lesser values than the parent node
c. All right child nodes have lesser values than the parent node
d. All left child nodes have greater values than the parent node
e. A&B
32. Which tree traversal algorithim prints all the values of a binary search tree out in
ascending order?
a. Inorder
b. Reverse order
c. Preorder
d. Postorder
e. None
33. Which tree traversal algorithim prints all the values of a binary search tree out in
descending order?
a. Inorder
b. Reverse order
c. Preorder
d. Postorder
e. None
a. Quicksort
b. Treesort
c. Heapsort
d. Mergesort
e. Bubblesort
35. Which of the following are self balancing binary search trees?
a. Trie
b. Red-Black Tree
c. AVL Tree
d. A&B
e. B&C
a. When the nodes are inserted into the tree in such a way that it’s unbalanced
b. When all the nodes are inserted into the tree on one side of the root
c. An operation that swaps the left and right children
d. An operation that changes the tree structure but retains the binary search tree property
e. An operation that removes a tree node and adds a new node
a. ArrayList
b. LinkedList
c. TreeMap
d. TreeSet
e. PriorityQueue
38. What is the run time of inserting into a heap?
a. O(1)
b. O(N)
c. O(N2)
d. O(Log2N)
e. O(N!)
a. O(1)
b. O(N)
c. O(N2)
d. O(Log2N)
e. O(N!)
a. O(1)
b. O(N)
c. O(N2)
d. O(Log2N)
e. O(N * Log2N)