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

How many edges does a tree with n nodes have?

  1. An + 1
  2. B2n
  3. Cn
  4. Dn − 1
2.Easy

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

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

In a hash table, what is a collision?

  1. AA key cannot be hashed at all
  2. BTwo equal keys are stored twice
  3. CThe table runs out of memory
  4. DTwo different keys map to the same index
4.Medium

Why is traversing an array often much faster in practice than traversing a linked list of the same length?

  1. AArrays use fewer instructions to compare values
  2. BArray traversal is O(1) in total, while linked list traversal is O(n)
  3. CArray elements are contiguous, so they make good use of the CPU cache
  4. DLinked lists always store elements on disk
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. A2i and 2i + 1
  2. Bi + 1 and i + 2
  3. Ci/2 and i/2 + 1
  4. D2i + 1 and 2i + 2
6.Medium

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

  1. AA hash table only
  2. BA stack
  3. CA queue
  4. DA heap
7.Hard

Which pair of traversals always determines a unique binary tree with distinct keys?

  1. APreorder alone
  2. BLevel-order alone
  3. CPreorder and inorder
  4. DPreorder and postorder
8.Hard

A Bloom filter can answer "is this element in the set?" with:

  1. APossible false positives but no false negatives
  2. BExact answers always
  3. CAnswers only for numbers
  4. DPossible false negatives but no false positives

Answer key

  1. 1. D · n − 1
  2. 2. C · At the root
  3. 3. D · Two different keys map to the same index
  4. 4. C · Array elements are contiguous, so they make good use of the CPU cache
  5. 5. D · 2i + 1 and 2i + 2
  6. 6. B · A stack
  7. 7. C · Preorder and inorder
  8. 8. A · Possible false positives but no false negatives

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