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

Which data structure is used to perform a level-order traversal of a tree?

  1. AHash table
  2. BQueue
  3. CPriority queue
  4. DStack
2.Easy

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

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

In an adjacency list representation of a graph, what is stored for each vertex?

  1. AA row of V Boolean values
  2. BThe total number of edges in the graph
  3. CThe shortest path to every other vertex
  4. DA list of its neighbouring vertices
4.Medium

Why can a binary heap be stored in an array without any pointers?

  1. AAll keys in a heap are equal
  2. BArrays automatically keep the keys in sorted order, so no pointers are needed
  3. CIt is a complete binary tree, so positions follow simple index formulas
  4. DHeaps never contain more than 100 elements
5.Medium

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

  1. AA stack
  2. BA queue
  3. CA hash table only
  4. DA heap
6.Medium

In a binary heap stored in an array starting at index 0, where is the parent of the node at index i?

  1. AAt index ⌊(i − 1) / 2⌋
  2. BAt index i − 1
  3. CAt index 2i + 1
  4. DAt index ⌊i / 2⌋ + 1
7.Hard

Why might a server choose its hash function at random from a universal family?

  1. ATo guarantee that no two keys can ever collide, whatever keys an attacker sends
  2. BTo make it very unlikely that an attacker can pick many keys that all collide
  3. CTo make the hash table sorted
  4. DTo remove the need to resize the table
8.Hard

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

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

Answer key

  1. 1. B · Queue
  2. 2. D · Null (no node)
  3. 3. D · A list of its neighbouring vertices
  4. 4. C · It is a complete binary tree, so positions follow simple index formulas
  5. 5. A · A stack
  6. 6. A · At index ⌊(i − 1) / 2⌋
  7. 7. B · To make it very unlikely that an attacker can pick many keys that all collide
  8. 8. A · Preorder and inorder

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