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 data structure is most suitable for the "undo" feature in a text editor?

  1. AQueue
  2. BGraph
  3. CHash set
  4. DStack
2.Easy

Which data structure is used to perform a level-order traversal of a tree?

  1. AQueue
  2. BStack
  3. CHash table
  4. DPriority queue
3.Easy

Which data structure works on the principle "last in, first out"?

  1. AStack
  2. BLinked list
  3. CQueue
  4. DHash table
4.Medium

A circular buffer (ring buffer) is commonly used to implement:

  1. AA graph traversal
  2. BA fixed-size queue
  3. CA binary search tree
  4. DA hash function
5.Medium

Which abstract data type does Dijkstra's algorithm use to choose the next vertex to process?

  1. AA FIFO queue
  2. BA stack
  3. CA set with no ordering
  4. DA min-priority queue
6.Medium

An adjacency matrix for a graph with V vertices uses how much memory?

  1. AO(V²)
  2. BO(E)
  3. CO(V + E)
  4. DO(log V)
7.Hard

Which property must a red-black tree satisfy?

  1. AEvery red node must have red children, so red nodes always form unbroken chains to the leaves
  2. BEvery node must be red
  3. CEvery path from a node to its descendant leaves has the same number of black nodes
  4. DThe root must be red
8.Hard

In a circular buffer, front == rear can mean either empty or full. What is a common way to tell them apart?

  1. AMake the buffer size a power of two
  2. BKeep a separate element count, or always leave one slot unused
  3. CAlways clear the buffer whenever front equals rear, so the state is empty
  4. DStore the front and rear in the same variable

Answer key

  1. 1. D · Stack
  2. 2. A · Queue
  3. 3. A · Stack
  4. 4. B · A fixed-size queue
  5. 5. D · A min-priority queue
  6. 6. A · O(V²)
  7. 7. C · Every path from a node to its descendant leaves has the same number of black nodes
  8. 8. B · Keep a separate element count, or always leave one slot unused

Full step-by-step solutions: practise this topic on examproblems.com.