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 a directed graph?

  1. AA graph whose edges have a direction from one vertex to another
  2. BA graph that has no cycles
  3. CA graph in which every pair of distinct vertices is joined by an edge
  4. DA graph whose edges all have weights
2.Easy

In a graph, what is a cycle?

  1. AA vertex with no edges
  2. BA path that starts and ends at the same vertex
  3. CAn edge with a weight of zero
  4. DA path that visits every vertex
3.Easy

What is the load factor of a hash table?

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

A node in a binary search tree has a right subtree. Where is its in-order successor?

  1. AIts parent, always
  2. BThe rightmost node of its left subtree
  3. CThe leftmost node of its right subtree
  4. DIts right child, always
5.Medium

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

  1. AAscending sorted order
  2. BLevel order
  3. CInsertion order
  4. DDescending order always
6.Medium

You have a reference to a node in the middle of a list. In which list can you remove it in O(1)?

  1. AA sorted array
  2. BA singly linked list
  3. CA doubly linked list
  4. DA dynamic array
7.Hard

What is the running time of breadth-first search on a graph with V vertices stored as an adjacency matrix?

  1. AO(V²)
  2. BO(E log V)
  3. CO(V + E)
  4. DO(V)
8.Hard

Inserting a key into an AVL tree makes a node's left subtree too tall, and the new key went into the left subtree of its left child (left-left case). Which fix is applied?

  1. AA left rotation at the child, then a right rotation at the node
  2. BA single right rotation at the unbalanced node
  3. CRecolouring the node and its child
  4. DA single left rotation at the unbalanced node

Answer key

  1. 1. A · A graph whose edges have a direction from one vertex to another
  2. 2. B · A path that starts and ends at the same vertex
  3. 3. D · The number of stored elements divided by the number of buckets
  4. 4. C · The leftmost node of its right subtree
  5. 5. A · Ascending sorted order
  6. 6. C · A doubly linked list
  7. 7. A · O(V²)
  8. 8. B · A single right rotation at the unbalanced node

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