Data structures worksheet with answers
Free printable Data structures worksheet: 8 problems from easy to exam level, with an answer key. Print it or save it as a PDF.
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
In which order does a postorder traversal of a binary tree visit nodes?
- ANode, then left subtree, then right subtree
- BRight subtree, then node, then left subtree
- CLeft subtree, then right subtree, then node
- DLeft subtree, then node, then right subtree
2.Easy
Which operation is O(1) for an array but O(n) for a singly linked list?
- ARemoving the head element
- BAccessing the element at index i
- CReading the first element
- DInserting at the head
3.Easy
What is the name of the queue operation that removes the element at the front?
- APush
- BDequeue
- CEnqueue
- DInsert
4.Medium
An application needs fast lookups and also needs to list keys in sorted order and answer range queries. Which structure fits best?
- AA hash table
- BA balanced binary search tree
- CAn unsorted linked list
- DA stack
5.Medium
What is the time complexity of searching for a key in a balanced binary search tree?
- AO(1)
- BO(n log n)
- CO(log n)
- DO(n)
6.Medium
Which collision resolution method stores colliding keys in a list at the same bucket?
- ADouble hashing
- BLinear probing
- CQuadratic probing
- DSeparate chaining
7.Hard
For a hash table to work correctly, which rule must hash and equality follow?
- ADifferent keys must have different hash values
- BHash values must be prime numbers
- CEqual hash values imply equal keys
- DEqual keys must have equal hash values
8.Hard
What is the running time of breadth-first search on a graph with V vertices stored as an adjacency matrix?
- AO(V + E)
- BO(E log V)
- CO(V²)
- DO(V)