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

In which order does a postorder traversal of a binary tree visit nodes?

  1. ANode, then left subtree, then right subtree
  2. BRight subtree, then node, then left subtree
  3. CLeft subtree, then right subtree, then node
  4. DLeft subtree, then node, then right subtree
2.Easy

Which operation is O(1) for an array but O(n) for a singly linked list?

  1. ARemoving the head element
  2. BAccessing the element at index i
  3. CReading the first element
  4. DInserting at the head
3.Easy

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

  1. APush
  2. BDequeue
  3. CEnqueue
  4. DInsert
4.Medium

An application needs fast lookups and also needs to list keys in sorted order and answer range queries. Which structure fits best?

  1. AA hash table
  2. BA balanced binary search tree
  3. CAn unsorted linked list
  4. DA stack
5.Medium

What is the time complexity of searching for a key in a balanced binary search tree?

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

Which collision resolution method stores colliding keys in a list at the same bucket?

  1. ADouble hashing
  2. BLinear probing
  3. CQuadratic probing
  4. DSeparate chaining
7.Hard

For a hash table to work correctly, which rule must hash and equality follow?

  1. ADifferent keys must have different hash values
  2. BHash values must be prime numbers
  3. CEqual hash values imply equal keys
  4. DEqual keys must have equal hash values
8.Hard

What is the running time of breadth-first search on a graph with V vertices stored as an adjacency matrix?

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

Answer key

  1. 1. C · Left subtree, then right subtree, then node
  2. 2. B · Accessing the element at index i
  3. 3. B · Dequeue
  4. 4. B · A balanced binary search tree
  5. 5. C · O(log n)
  6. 6. D · Separate chaining
  7. 7. D · Equal keys must have equal hash values
  8. 8. C · O(V²)

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