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
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
- CInserting at the beginning
- DFinding the length of a fixed array
2.Easy
Where is the smallest element of a binary min-heap found?
- AIn the leftmost leaf
- BIn the last array position
- CAt the root
- DIn any leaf, which must be searched
3.Easy
What is the name of the queue operation that removes the element at the front?
- AEnqueue
- BPush
- CDequeue
- DInsert
4.Medium
In a binary min-heap stored in an array (index starting at 0), the children of the node at index i are at:
- A2i + 1 and 2i + 2
- B2i and 2i + 1
- Ci + 1 and i + 2
- Di/2 and i/2 + 1
5.Medium
How does extract-min work in a binary min-heap?
- ASearch all leaves for the new minimum
- BRemove the last element of the array
- CRemove the root and shift all elements one place left
- DMove the last element to the root and sift it down
6.Medium
Why can a binary heap be stored in an array without any pointers?
- AAll keys in a heap are equal
- BArrays automatically keep the keys in sorted order, so no pointers are needed
- CHeaps never contain more than 100 elements
- DIt is a complete binary tree, so positions follow simple index formulas
7.Hard
Which data structure supports an LRU (least recently used) cache with O(1) get and put?
- AA binary search tree only
- BA hash map combined with a doubly linked list
- CA single sorted array
- DA stack only
8.Hard
For each element of an array you want the next greater element to its right, in O(n) total time. Which structure helps?
- AA binary search tree rebuilt for each element
- BA hash table of all elements
- CA queue that holds every pair of elements
- DA stack that keeps elements waiting for their answer