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 does a map (dictionary) store?

  1. APairs of equal keys
  2. BKey-value pairs with unique keys
  3. COnly values in insertion order
  4. DValues sorted by size
2.Easy

In an undirected graph, what is the degree of a vertex?

  1. AThe number of edges connected to it
  2. BIts position in the adjacency list
  3. CThe length of the longest path from it
  4. DThe number of vertices in the graph
3.Easy

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

  1. ALeft subtree, then node, then right subtree
  2. BLevel by level from the top
  3. CNode, then left subtree, then right subtree
  4. DLeft subtree, then right subtree, then node
4.Medium

How many nodes does a perfect binary tree of height h have, with height counted in edges?

  1. Ah2
  2. B2h + 1
  3. C2h
  4. D2h+1 − 1
5.Medium

An in-order traversal of a binary search tree visits the keys in:

  1. AAscending sorted order
  2. BInsertion order
  3. CDescending order always
  4. DLevel order
6.Medium

How do you find the minimum key in a binary search tree?

  1. AFollow left children from the root until there is no left child
  2. BVisit every leaf and compare them
  3. CFollow right children from the root until there is no right child
  4. DLook at the root only
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

What are the time and extra space costs of reversing a singly linked list in place?

  1. AO(n log n) time and O(1) extra space
  2. BO(1) time and O(1) extra space
  3. CO(n) time and O(1) extra space
  4. DO(n) time and O(n) extra space

Answer key

  1. 1. B · Key-value pairs with unique keys
  2. 2. A · The number of edges connected to it
  3. 3. C · Node, then left subtree, then right subtree
  4. 4. D · 2h+1 − 1
  5. 5. A · Ascending sorted order
  6. 6. A · Follow left children from the root until there is no left child
  7. 7. D · Emptying the slot could break the probe sequence for other keys
  8. 8. C · O(n) time and O(1) extra space

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