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 works on the principle "first in, first out"?

  1. ABinary tree
  2. BHeap
  3. CQueue
  4. DStack
2.Easy

What does a map (dictionary) store?

  1. AKey-value pairs with unique keys
  2. BValues sorted by size
  3. COnly values in insertion order
  4. DPairs of equal keys
3.Easy

In a singly linked list, what does the next pointer of the last node contain?

  1. ANull (no node)
  2. BThe address of the first node
  3. CThe address of the previous node
  4. DThe number of nodes in the list
4.Medium

Which data structure is used by depth-first search (iterative version)?

  1. AA stack
  2. BA heap
  3. CA queue
  4. DA hash table only
5.Medium

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

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

In a binary heap stored in an array starting at index 0, where is the parent of the node at index i?

  1. AAt index 2i + 1
  2. BAt index i − 1
  3. CAt index ⌊i / 2⌋ + 1
  4. DAt index ⌊(i − 1) / 2⌋
7.Hard

What is the main advantage of a skip list over a sorted linked list?

  1. AExpected O(log n) search by using several levels of forward pointers
  2. BGuaranteed O(1) search because every node stores a pointer to every other node
  3. CIt uses no extra memory
  4. DIt stores keys without order
8.Hard

Which structure lets you compute the maximum of every window of size k in an array in O(n) total?

  1. AA min-heap rebuilt for every window
  2. BA sorted array updated by shifting
  3. CA singly linked list of the window's elements
  4. DA deque holding indices in decreasing order of value

Answer key

  1. 1. C · Queue
  2. 2. A · Key-value pairs with unique keys
  3. 3. A · Null (no node)
  4. 4. A · A stack
  5. 5. C · O(V²)
  6. 6. D · At index ⌊(i − 1) / 2⌋
  7. 7. A · Expected O(log n) search by using several levels of forward pointers
  8. 8. D · A deque holding indices in decreasing order of value

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