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

A hash table stores data as:

  1. AA sorted list only
  2. BKey–value pairs located by a hash function
  3. CA tree with ordered keys
  4. DA fixed-length string
2.Easy

What is the name of the stack operation that adds an element to the top?

  1. APush
  2. BPop
  3. CEnqueue
  4. DPeek
3.Easy

What is the defining feature of a set as an abstract data type?

  1. AIt stores key-value pairs
  2. BIt stores elements in sorted order
  3. CIt stores elements without duplicates
  4. DIt allows access only at one end
4.Medium

A circular buffer (ring buffer) is commonly used to implement:

  1. AA binary search tree
  2. BA hash function
  3. CA graph traversal
  4. DA fixed-size queue
5.Medium

What balance condition does an AVL tree maintain at every node?

  1. ABoth subtrees of every node contain exactly the same number of nodes
  2. BEvery node is coloured red or black
  3. CAll leaves are at exactly the same depth
  4. DThe heights of the left and right subtrees differ by at most 1
6.Medium

What is true of the adjacency matrix of an undirected graph?

  1. AIt is always upper triangular
  2. BIts main diagonal always contains ones
  3. CEach row has exactly one 1
  4. DIt is symmetric about the main diagonal
7.Hard

What is the main advantage of a skip list over a sorted linked list?

  1. AIt uses no extra memory
  2. BGuaranteed O(1) search because every node stores a pointer to every other node
  3. CIt stores keys without order
  4. DExpected O(log n) search by using several levels of forward pointers
8.Hard

A Fenwick tree (binary indexed tree) over an array of n numbers supports which operations in O(log n)?

  1. APrefix-sum queries and single-element updates
  2. BSorting the array and binary search
  3. CFinding the median in O(1)
  4. DInserting elements at any position

Answer key

  1. 1. B · Key–value pairs located by a hash function
  2. 2. A · Push
  3. 3. C · It stores elements without duplicates
  4. 4. D · A fixed-size queue
  5. 5. D · The heights of the left and right subtrees differ by at most 1
  6. 6. D · It is symmetric about the main diagonal
  7. 7. D · Expected O(log n) search by using several levels of forward pointers
  8. 8. A · Prefix-sum queries and single-element updates

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