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 used to perform a level-order traversal of a tree?

  1. AQueue
  2. BPriority queue
  3. CHash table
  4. DStack
2.Easy

What is a deque (double-ended queue)?

  1. ATwo separate queues sharing one array
  2. BA queue that only allows removal at the back
  3. CA structure that allows insertion and removal at both ends
  4. DA queue sorted by priority
3.Easy

What is the name of the queue operation that removes the element at the front?

  1. ADequeue
  2. BEnqueue
  3. CPush
  4. DInsert
4.Medium

AVL trees and red-black trees guarantee:

  1. AThat keys are stored in insertion order
  2. BO(log n) height through rebalancing
  3. CThat no node has two children
  4. DConstant-time search in every case
5.Medium

In a binary min-heap stored in an array (index starting at 0), the children of the node at index i are at:

  1. Ai/2 and i/2 + 1
  2. Bi + 1 and i + 2
  3. C2i + 1 and 2i + 2
  4. D2i and 2i + 1
6.Medium

What is the value of the postfix expression 3 4 + 2 * ?

  1. A24
  2. B14
  3. C10
  4. D11
7.Hard

Kahn's algorithm for topological sorting repeatedly removes vertices with in-degree 0. Which structure holds those vertices?

  1. AAn adjacency matrix recording which vertices have already been removed
  2. BA max-heap ordered by out-degree
  3. CA queue (or any collection) of vertices whose in-degree is 0
  4. DA stack of all visited edges
8.Hard

Which statement about heapsort is correct?

  1. AIt runs in O(n) time on any input
  2. BIt is stable and needs O(n) extra memory
  3. CIt needs a binary search tree as extra storage, so it uses O(n) extra memory
  4. DIt sorts in place in O(n log n) worst-case time but is not stable

Answer key

  1. 1. A · Queue
  2. 2. C · A structure that allows insertion and removal at both ends
  3. 3. A · Dequeue
  4. 4. B · O(log n) height through rebalancing
  5. 5. C · 2i + 1 and 2i + 2
  6. 6. B · 14
  7. 7. C · A queue (or any collection) of vertices whose in-degree is 0
  8. 8. D · It sorts in place in O(n log n) worst-case time but is not stable

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