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 the peek (or top) operation on a stack do?

  1. ARemoves the top element and returns it
  2. BRemoves all elements from the stack
  3. CReturns the top element without removing it
  4. DReturns the bottom element of the stack
2.Easy

Which data structure is most suitable for the "undo" feature in a text editor?

  1. AQueue
  2. BStack
  3. CHash set
  4. DGraph
3.Easy

In a tree, what is a leaf?

  1. AThe node with the largest value
  2. BA node with no children
  3. CA node with no parent
  4. DA node with exactly one child
4.Medium

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

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

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

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

How long does a search for a word of length L take in a trie with a fixed alphabet?

  1. AO(n), where n is the number of words
  2. BO(L × n)
  3. CO(log n), where n is the number of words
  4. DO(L), independent of how many words are stored
7.Hard

For each element of an array you want the next greater element to its right, in O(n) total time. Which structure helps?

  1. AA hash table of all elements
  2. BA stack that keeps elements waiting for their answer
  3. CA binary search tree rebuilt for each element
  4. DA queue that holds every pair of elements
8.Hard

Which property keeps every B-tree perfectly balanced?

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

Answer key

  1. 1. C · Returns the top element without removing it
  2. 2. B · Stack
  3. 3. B · A node with no children
  4. 4. A · A fixed-size queue
  5. 5. D · O(V²)
  6. 6. D · O(L), independent of how many words are stored
  7. 7. B · A stack that keeps elements waiting for their answer
  8. 8. B · All leaves are at the same depth

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