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

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

  1. AA list of its neighbouring vertices
  2. BA row of V Boolean values
  3. CThe total number of edges in the graph
  4. DThe shortest path to every other vertex
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 stored elements divided by the number of buckets
  3. CThe number of collisions so far
  4. DThe time needed to load the table from disk
4.Medium

In a circular queue stored in an array of capacity n, how is the next position after index i computed?

  1. A2i + 1
  2. B(i − 1) mod n
  3. Ci + 1
  4. D(i + 1) mod n
5.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 dynamic array
  2. BA doubly linked list
  3. CA sorted array
  4. DA singly linked list
6.Medium

AVL trees and red-black trees guarantee:

  1. AThat keys are stored in insertion order
  2. BO(log n) height through rebalancing
  3. CThat no node has two children
  4. DConstant-time search in every case
7.Hard

The keys 5, 3, 8, 1 are inserted in this order into an empty array-based binary min-heap. What is the final array?

  1. A[3, 1, 8, 5]
  2. B[1, 3, 5, 8]
  3. C[1, 5, 8, 3]
  4. D[1, 3, 8, 5]
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(n) extra space
  4. DO(n) time and O(1) extra space

Answer key

  1. 1. A · A list of its neighbouring vertices
  2. 2. B · A path that starts and ends at the same vertex
  3. 3. B · The number of stored elements divided by the number of buckets
  4. 4. D · (i + 1) mod n
  5. 5. B · A doubly linked list
  6. 6. B · O(log n) height through rebalancing
  7. 7. D · [1, 3, 8, 5]
  8. 8. D · O(n) time and O(1) extra space

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