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
A graph consists of:
ARows and columns
BVertices (nodes) connected by edges
COnly a root and leaves
DKeys and hashes only
2.Easy
In which order does a postorder traversal of a binary tree visit nodes?
ARight subtree, then node, then left subtree
BNode, then left subtree, then right subtree
CLeft subtree, then node, then right subtree
DLeft subtree, then right subtree, then node
3.Easy
What is the name of the stack operation that adds an element to the top?
APush
BEnqueue
CPop
DPeek
4.Medium
In a circular queue stored in an array of capacity n, how is the next position after index i computed?
Ai + 1
B2i + 1
C(i − 1) mod n
D(i + 1) mod n
5.Medium
What balance condition does an AVL tree maintain at every node?
AEvery node is coloured red or black
BThe heights of the left and right subtrees differ by at most 1
CAll leaves are at exactly the same depth
DBoth subtrees of every node contain exactly the same number of nodes
6.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 preorder traversal?
A1 2 3 4 5
B1 2 4 5 3
C4 2 5 1 3
D4 5 2 3 1
7.Hard
An AVL node is unbalanced because its left child's right subtree became too tall (left-right case). Which fix is applied?
AA single right rotation at the node
BA right rotation at the left child, then a left rotation at the node
CA single left rotation at the node
DA left rotation at the left child, then a right rotation at the node
8.Hard
What does a splay tree do after each access?
ARebuilds the whole tree in balanced form
BRecolours the nodes on the search path
CMoves the accessed node to a leaf
DRotates the accessed node up to the root
Answer key
1. B · Vertices (nodes) connected by edges
2. D · Left subtree, then right subtree, then node
3. A · Push
4. D · (i + 1) mod n
5. B · The heights of the left and right subtrees differ by at most 1
6. B · 1 2 4 5 3
7. D · A left rotation at the left child, then a right rotation at the node
8. D · Rotates the accessed node up to the root
Full step-by-step solutions: practise this topic on examproblems.com.