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 a graph, what is a cycle?

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

What does each node in a doubly linked list contain?

  1. AData and two pointers, one to the next node and one to the node after that
  2. BData and a pointer to the next node only
  3. CData, a pointer to the next node and a pointer to the previous node
  4. DTwo copies of the data and one pointer
3.Easy

What is a directed graph?

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

Which data structure is used to check whether the brackets in "{[()]}" are balanced?

  1. AA stack
  2. BA binary search tree
  3. CA queue
  4. DA hash table
5.Medium

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

  1. AA larger table is allocated and every key is inserted again
  2. BThe oldest keys are deleted to make room
  3. CThe existing keys are sorted in place
  4. DOnly the colliding keys are moved to a new overflow list at the end of the table
6.Medium

Which collision resolution method stores colliding keys in a list at the same bucket?

  1. ASeparate chaining
  2. BQuadratic probing
  3. CLinear probing
  4. DDouble hashing
7.Hard

Which property keeps every B-tree perfectly balanced?

  1. AEach node stores one key
  2. BAll leaves are at the same depth
  3. CThe keys are stored only in the root
  4. DEvery node has exactly two children
8.Hard

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

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

Answer key

  1. 1. A · A path that starts and ends at the same vertex
  2. 2. C · Data, a pointer to the next node and a pointer to the previous node
  3. 3. C · A graph whose edges have a direction from one vertex to another
  4. 4. A · A stack
  5. 5. A · A larger table is allocated and every key is inserted again
  6. 6. A · Separate chaining
  7. 7. B · All leaves are at the same depth
  8. 8. C · O(n) time and O(1) extra space

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