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 is the main difference between a static array and a dynamic array?

  1. AA static array can only store numbers
  2. BA dynamic array can grow by moving to a larger block of memory
  3. CA dynamic array stores its elements in linked nodes so it can grow one at a time
  4. DA static array allows slower index access
2.Easy

The depth of a node in a tree is:

  1. AThe number of nodes in its subtree
  2. BThe number of edges from that node to the deepest leaf
  3. CThe number of children of that node
  4. DThe number of edges from the root to that node
3.Easy

Which data structure is most suitable for the "undo" feature in a text editor?

  1. AQueue
  2. BStack
  3. CGraph
  4. DHash set
4.Medium

A binary tree has root 1 with left child 2 and right child 3; node 2 has children 4 (left) and 5 (right). What is the postorder traversal?

  1. A1 2 4 5 3
  2. B4 5 2 3 1
  3. C5 4 3 2 1
  4. D4 2 5 1 3
5.Medium

The keys 50, 30, 70, 20, 40 are inserted in this order into an empty binary search tree. What is the left child of 30?

  1. A20
  2. B40
  3. C50
  4. D70
6.Medium

A hash table of size 7 uses h(k) = k mod 7 and linear probing. After inserting 10, where is 17 stored?

  1. AIndex 6
  2. BIndex 0
  3. CIndex 4
  4. DIndex 3
7.Hard

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

  1. AExact answers always
  2. BAnswers only for numbers
  3. CPossible false negatives but no false positives
  4. DPossible false positives but no false negatives
8.Hard

An AVL node is unbalanced because its left child's right subtree became too tall (left-right case). Which fix is applied?

  1. AA left rotation at the left child, then a right rotation at the node
  2. BA right rotation at the left child, then a left rotation at the node
  3. CA single right rotation at the node
  4. DA single left rotation at the node

Answer key

  1. 1. B · A dynamic array can grow by moving to a larger block of memory
  2. 2. D · The number of edges from the root to that node
  3. 3. B · Stack
  4. 4. B · 4 5 2 3 1
  5. 5. A · 20
  6. 6. C · Index 4
  7. 7. D · Possible false positives but no false negatives
  8. 8. A · A left rotation at the left child, then a right rotation at the node

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