You are on page 1of 4

S17 CS 101 Exam 2 April 12, 2017 Page 1 of 4

This exam is worth 100 points. There are questions totaling 105 points.

____ 1. How many steps does it take to delete an item from a binary search tree (BST)? (When
in doubt, always assume worst-case.)
a) O(1) c) O(n) e) O(n)
b) O(log n) d) O(n log n)
____ 2. How many steps does it take to build a heap using the bottom up method.
____ 3. How many steps does it take to perform an extract-min from a min-ordered heap?
____ 4. How many steps does it take to perform an enqueue operation on a queue
implemented as a linked list?
____ 5. The worst-case to insert an item into a Hash table takes how many steps?
____ 6. The goal of hashing is for inserts to take how many steps on average?
____ 7. Heapsort (using a Heap to sort) n elements takes how many steps?
____ 8. Using an adjacency matrix, how many steps will it take to determine if vertex x is
adjacent to vertex y?
c) O(V+E)
a) O(1)
d) O(V2)
b) O(V)

____ 9. Using an adjacency matrix, how many steps will it take to find all vertices adjacent to
vertex x?
____ 10. How many steps does it take to perform a BFS of a graph?
____ 11. If we have a sparse graph with n vertices and the degree (number of incident edges) of
every node is at most 10, how long will depth first search take?

Suppose we have a min-ordered heap of size 18, stored in an array starting at index 0.
____ 12. At what index is the node that is the parent of the node stored at index 16?
a) 15 c) 7
b) 8 d) 9

____ 13. If we insert a new smallest element, what positions in the array will be modified?
a) 18, 9, 4, 2, 1 c) 19, 9, 4, 1, 0
b) 19, 10, 5, 2, 0 d) 18, 8, 3, 1, 0
____ 14. Suppose that we have a min-ordered heap where the values in the array are
[12,17,14,19,25,72,18,31,47]. Where in the array (at what index) is the value 47 after
an extract-min operation?
a) 7 c) 2 e) 6
b) 1 d) 3
S17 CS 101 Exam 2 April 12, 2017 Page 2 of 4

____ 15. Consider starting from the same starting heap as the question above (before the
extract-min). If we insert the value 13 into the heap, what will its array index be?
a) 1 c) 3 e) 9
b) 2 d) 4

Consider the following BST for questions 17 through 20


15

6 30

2 20 45
9

7 12 21

10 25

____ 16. What nodes would be visited during a search for the value 23?
a) 15,12,20 c) 2,6,15,30,20
b) 15,30,20,21,25 d) 15,6,9,12

____ 17. Where would the value 8 be inserted?


a) Left child of 10 c) Right child of 7
b) Left child of 20 d) Left child of 9

____ 18. Which nodes are candidates to be the root of the tree, if 15 were deleted
a) 12, 20 c) 10, 20
b) 6, 30 d) 10, 25

____ 19. True/false: 2, 7, 10, 12, 9, 6, 25, 21, 10, 45, 30, 15 is the post-order traversal of the
tree.
a) True b) False
S17 CS 101 Exam 2 April 12, 2017 Page 3 of 4

Hashing: For the next 3 questions, suppose that we have inserted values into the hash table
below, with the Xs indicating cells that are occupied.
0 1 2 3 4 5 6 7 8

X X X X

____ 20. Suppose the next value to insert has H(x) = 1 and we are using linear probing. In
what cell will this value be placed?
a) 0 b) 4 c) 6 d) 7 e) 8
____ 21. Suppose the next value to insert has H(x) = 1 and we are using quadratic probing. In
what cell will this value be placed?
a) 0 b) 4 c) 6 d) 7 e) 8
____ 22.
Suppose the next value to insert has H(x) = 5, H2(x)=5 and we are using double
hashing. In what cell will this value be placed?
a) 0 b) 4 c) 6 d) 7 e) 8

____ 23. A good hash function should:


a) Spread the input values over the range c) Spread equal inputs out to avoid
of integer outputs. collisions.
b) Be random.
____ 24. Which operation do hash tables NOT support:
a) Insertion b) Search c) Sorting
____ 25. Which operation do heaps NOT support efficiently:
a) Extract-Min c) Search
b) Insertion d) Sorting

____ 26. Huffman Codes will provide the most benefit when:
a) The characters in the file occur b) There is a skewed distribution of the
uniformly characters

Given the letter frequencies below, construct the Huffman code tree for the message.
A:3 B:4 C:6 D:5 E:20 F:21
____ 27. What is the length of the encoding for the letter A?
a) 1 b) 2 c) 3 d) 4 e) 5
____ 28. What is the length of the encoding for the letter E?
a) 1 b) 2 c) 3 d) 4 e) 5
____ 29. What is the length of the encoding for the letter F?
a) 1 b) 2 c) 3 d) 4 e) 5
S17 CS 101 Exam 2 April 12, 2017 Page 4 of 4

Consider the undirected graph above:


____ 30. If a depth first search is performed starting at vertex 1, which vertex will be the parent
of vertex 7 in the DFS tree?
a) 2 c) 4
b) 3 d) 5

____ 31. A DFS tree of the above graph, starting at vertex 1, can be constructed so that it is a
straight line. In such a tree, which node is the parent of node 5?
a) 2 c) 4
b) 3 d) 6

____ 32. In a breadth first search tree generated from the above graph, starting at vertex 1,
which one of these nodes can NOT be the parent of vertex 5?
a) 2 c) 6
b) 3
____ 33. After an exception is thrown and a catch block executes, execution resumes after the
throw statement.
a) True b) False
____ 34. For a function that may contain a throw, the function's statements must be surrounded
by a try block.
a) True b) False
____ 35. A key advantage of a class template is relieving the programmer from having to write
redundant code that differs only by type.
b) False
a) True

You might also like