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

Where is the smallest element of a binary min-heap found?

  1. AAt the root
  2. BIn the leftmost leaf
  3. CIn any leaf, which must be searched
  4. DIn the last array position
2.Easy

What is the load factor of a hash table?

  1. AThe number of stored elements divided by the number of buckets
  2. BThe number of collisions so far
  3. CThe number of buckets divided by the average length of the keys stored
  4. DThe time needed to load the table from disk
3.Easy

In a tree, what are sibling nodes?

  1. ANodes that have no children
  2. BNodes that share the same parent
  3. CNodes at the same depth in different subtrees
  4. DA node and its parent
4.Medium

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

  1. ASeparate chaining
  2. BDouble hashing
  3. CLinear probing
  4. DQuadratic probing
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 worst-case height of a binary search tree with n nodes if keys are inserted in sorted order?

  1. An (it becomes a linked list)
  2. B1
  3. C√n
  4. Dlog₂ n
7.Hard

In a hash table using open addressing, why is deletion often done with a "tombstone" marker?

  1. ADeleted keys must be kept forever for security, so slots can never be reused
  2. BTombstones speed up hashing
  3. CIt makes the table sorted
  4. DEmptying the slot could break the probe sequence for other keys
8.Hard

You must keep the k smallest values from a stream of n numbers using O(k) memory. Which approach works in O(n log k) time?

  1. AA FIFO queue of the last k values
  2. BA sorted array of all n values
  3. CA max-heap of size k, replacing its root when a smaller value arrives
  4. DA min-heap holding all n values, from which the k smallest are popped at the end

Answer key

  1. 1. A · At the root
  2. 2. A · The number of stored elements divided by the number of buckets
  3. 3. B · Nodes that share the same parent
  4. 4. A · Separate chaining
  5. 5. C · 2i + 1 and 2i + 2
  6. 6. A · n (it becomes a linked list)
  7. 7. D · Emptying the slot could break the probe sequence for other keys
  8. 8. C · A max-heap of size k, replacing its root when a smaller value arrives

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