For teachers: free to print, copy and use in class. Every new worksheet has new values and its own answer key. A link to ExamProblems on your course page is appreciated.
Name: ____________________ Date: ____________
1.Easy
Which operation is slow in an array but fast at the head of a linked list?
AAccessing the 5th element
BReading the last element by index
CFinding the length of a fixed array
DInserting at the beginning
2.Easy
A graph consists of:
AOnly a root and leaves
BRows and columns
CKeys and hashes only
DVertices (nodes) connected by edges
3.Easy
What is the root of a tree?
AThe node with the largest value
BThe top node with no parent
CA node with no children
DAny node in the middle
4.Medium
A binary tree has root 1 with left child 2 and right child 3; node 2 has children 4 (left) and 5 (right). What is the postorder traversal?
A4 5 2 3 1
B5 4 3 2 1
C1 2 4 5 3
D4 2 5 1 3
5.Medium
A hash table of size 7 uses h(k) = k mod 7 and linear probing. After inserting 10, where is 17 stored?
AIndex 0
BIndex 3
CIndex 4
DIndex 6
6.Medium
How does extract-min work in a binary min-heap?
ARemove the last element of the array
BMove the last element to the root and sift it down
CSearch all leaves for the new minimum
DRemove the root and shift all elements one place left
7.Hard
What does a splay tree do after each access?
ARecolours the nodes on the search path
BRotates the accessed node up to the root
CMoves the accessed node to a leaf
DRebuilds the whole tree in balanced form
8.Hard
You must keep the k smallest values from a stream of n numbers using O(k) memory. Which approach works in O(n log k) time?
AA sorted array of all n values
BA FIFO queue of the last k values
CA min-heap holding all n values, from which the k smallest are popped at the end
DA max-heap of size k, replacing its root when a smaller value arrives
Answer key
1. D · Inserting at the beginning
2. D · Vertices (nodes) connected by edges
3. B · The top node with no parent
4. A · 4 5 2 3 1
5. C · Index 4
6. B · Move the last element to the root and sift it down
7. B · Rotates the accessed node up to the root
8. D · A max-heap of size k, replacing its root when a smaller value arrives
Full step-by-step solutions: practise this topic on examproblems.com.