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

A hash table stores data as:

  1. AA tree with ordered keys
  2. BKey–value pairs located by a hash function
  3. CA sorted list only
  4. DA fixed-length string
2.Easy

What is the root of a tree?

  1. AThe top node with no parent
  2. BAny node in the middle
  3. CThe node with the largest value
  4. DA node with no children
3.Easy

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

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

A trie (prefix tree) is especially efficient for:

  1. AStoring matrices
  2. BSorting numbers
  3. CFinding shortest paths
  4. DPrefix searches such as autocomplete
5.Medium

What is the worst-case height of a binary search tree with n nodes if keys are inserted in sorted order?

  1. Alog₂ n
  2. B√n
  3. Cn (it becomes a linked list)
  4. D1
6.Medium

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

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

What guarantee do the red-black tree rules give about the height of a tree with n keys?

  1. AThe height is exactly log2 n
  2. BThe height is at most 2 log2(n + 1)
  3. CThe height is at most log2 n + 1
  4. DThe height is at most n / 2
8.Hard

Under simple uniform hashing, what is the expected time of a search in a hash table with chaining, n keys and m buckets?

  1. AO(m)
  2. BO(1 + α), where α = n / m
  3. CO(n)
  4. DO(log n)

Answer key

  1. 1. B · Key–value pairs located by a hash function
  2. 2. A · The top node with no parent
  3. 3. D · Null (no node)
  4. 4. D · Prefix searches such as autocomplete
  5. 5. C · n (it becomes a linked list)
  6. 6. C · A fixed-size queue
  7. 7. B · The height is at most 2 log2(n + 1)
  8. 8. B · O(1 + α), where α = n / m

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