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 a map (dictionary) store?

  1. APairs of equal keys
  2. BOnly values in insertion order
  3. CKey-value pairs with unique keys
  4. DValues sorted by size
2.Easy

What does each node in a doubly linked list contain?

  1. ATwo copies of the data and one pointer
  2. BData, a pointer to the next node and a pointer to the previous node
  3. CData and two pointers, one to the next node and one to the node after that
  4. DData and a pointer to the next node only
3.Easy

What is a deque (double-ended queue)?

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

What happens when a hash table rehashes after its load factor exceeds a threshold?

  1. AThe oldest keys are deleted to make room
  2. BThe existing keys are sorted in place
  3. COnly the colliding keys are moved to a new overflow list at the end of the table
  4. DA larger table is allocated and every key is inserted again
5.Medium

How long does a search for a word of length L take in a trie with a fixed alphabet?

  1. AO(L), independent of how many words are stored
  2. BO(n), where n is the number of words
  3. CO(log n), where n is the number of words
  4. DO(L × n)
6.Medium

An in-order traversal of a binary search tree visits the keys in:

  1. AInsertion order
  2. BDescending order always
  3. CLevel order
  4. DAscending sorted order
7.Hard

For each element of an array you want the next greater element to its right, in O(n) total time. Which structure helps?

  1. AA stack that keeps elements waiting for their answer
  2. BA binary search tree rebuilt for each element
  3. CA hash table of all elements
  4. DA queue that holds every pair of elements
8.Hard

How long does it take to search for an arbitrary key in a binary min-heap of n elements?

  1. AO(log n)
  2. BO(1)
  3. CO(log log n)
  4. DO(n)

Answer key

  1. 1. C · Key-value pairs with unique keys
  2. 2. B · Data, a pointer to the next node and a pointer to the previous node
  3. 3. B · A structure that allows insertion and removal at both ends
  4. 4. D · A larger table is allocated and every key is inserted again
  5. 5. A · O(L), independent of how many words are stored
  6. 6. D · Ascending sorted order
  7. 7. A · A stack that keeps elements waiting for their answer
  8. 8. D · O(n)

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