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 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, a pointer to the next node and a pointer to the previous node
  3. CTwo copies of the data and one pointer
  4. DData and a pointer to the next node only
2.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 path that visits every vertex
  4. DA vertex with no edges
3.Easy

What is the root of a tree?

  1. AThe top node with no parent
  2. BAny node in the middle
  3. CThe node with the largest value
  4. DA node with no children
4.Medium

In a hash table using open addressing, what is the maximum possible load factor?

  1. A0.5
  2. B1
  3. CThere is no maximum
  4. D2
5.Medium

A hash table of size 7 uses h(k) = k mod 7 and linear probing. After inserting 10, where is 17 stored?

  1. AIndex 0
  2. BIndex 6
  3. CIndex 4
  4. DIndex 3
6.Medium

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

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

In Kruskal's minimum spanning tree algorithm, what is the union-find structure used for?

  1. AChecking whether an edge's two endpoints are already connected
  2. BChoosing the starting vertex
  3. CSorting the edges by weight
  4. DStoring each vertex's current distance from the source during the search
8.Hard

A dynamic array doubles when full. Why do many implementations shrink it only when it is one quarter full, not half full?

  1. ABecause halving at one half would lose elements
  2. BBecause the memory allocator can only release memory in quarters of a block
  3. CTo keep the array sorted
  4. DTo avoid repeated resizing when pushes and pops alternate near the boundary

Answer key

  1. 1. B · Data, a pointer to the next node and a pointer to the previous node
  2. 2. A · A path that starts and ends at the same vertex
  3. 3. A · The top node with no parent
  4. 4. B · 1
  5. 5. C · Index 4
  6. 6. B · A stack
  7. 7. A · Checking whether an edge's two endpoints are already connected
  8. 8. D · To avoid repeated resizing when pushes and pops alternate near the boundary

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