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
What does each node in a doubly linked list contain?
- AData and two pointers, one to the next node and one to the node after that
- BData, a pointer to the next node and a pointer to the previous node
- CData and a pointer to the next node only
- DTwo copies of the data and one pointer
2.Easy
What is the max-heap property?
- AThe keys are sorted from left to right
- BEvery parent's key is greater than or equal to its children's keys
- CEvery left child's key is greater than or equal to its right sibling's key
- DAll leaves contain the maximum key
3.Easy
Which operation is slow in an array but fast at the head of a linked list?
- AAccessing the 5th element
- BFinding the length of a fixed array
- CReading the last element by index
- DInserting at the beginning
4.Medium
Which data structure does a running program use to keep track of active function calls and their local variables?
- AThe heap memory queue
- BA hash table of functions
- CThe call stack
- DA binary search tree of frames
5.Medium
In a circular queue stored in an array of capacity n, how is the next position after index i computed?
- A2i + 1
- Bi + 1
- C(i + 1) mod n
- D(i − 1) mod n
6.Medium
How long does it take to check whether the edge (u, v) exists using an adjacency matrix?
- AO(V)
- BO(E)
- CO(log V)
- DO(1)
7.Hard
Kahn's algorithm for topological sorting repeatedly removes vertices with in-degree 0. Which structure holds those vertices?
- AA stack of all visited edges
- BA queue (or any collection) of vertices whose in-degree is 0
- CA max-heap ordered by out-degree
- DAn adjacency matrix recording which vertices have already been removed
8.Hard
In a circular buffer, front == rear can mean either empty or full. What is a common way to tell them apart?
- AKeep a separate element count, or always leave one slot unused
- BAlways clear the buffer whenever front equals rear, so the state is empty
- CStore the front and rear in the same variable
- DMake the buffer size a power of two