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 in which every pair of distinct vertices is joined by an edge
  3. CA graph whose edges all have weights
  4. DA graph that has no cycles
2.Easy

What is the main difference between a static array and a dynamic array?

  1. AA dynamic array can grow by moving to a larger block of memory
  2. BA static array can only store numbers
  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
3.Easy

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

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

What happens when a hash table rehashes after its load factor exceeds a threshold?

  1. AThe oldest keys are deleted to make room
  2. BA larger table is allocated and every key is inserted again
  3. COnly the colliding keys are moved to a new overflow list at the end of the table
  4. DThe existing keys are sorted in place
5.Medium

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

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

An adjacency matrix for a graph with V vertices uses how much memory?

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

In a circular buffer, front == rear can mean either empty or full. What is a common way to tell them apart?

  1. AStore the front and rear in the same variable
  2. BMake the buffer size a power of two
  3. CKeep a separate element count, or always leave one slot unused
  4. DAlways clear the buffer whenever front equals rear, so the state is empty
8.Hard

Without union by rank or path compression, what is the worst-case cost of a single find in a union-find structure with n elements?

  1. AO(n)
  2. BO(1)
  3. CO(α(n))
  4. DO(log n)

Answer key

  1. 1. A · A graph whose edges have a direction from one vertex to another
  2. 2. A · A dynamic array can grow by moving to a larger block of memory
  3. 3. D · A list of its neighbouring vertices
  4. 4. B · A larger table is allocated and every key is inserted again
  5. 5. A · It is a complete binary tree, so positions follow simple index formulas
  6. 6. B · O(V²)
  7. 7. C · Keep a separate element count, or always leave one slot unused
  8. 8. A · O(n)

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