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

Which structure is typically used to implement a priority queue?

  1. AA string
  2. BA heap
  3. CA stack
  4. DA singly linked list without order
2.Easy

In a tree, what are sibling nodes?

  1. AA node and its parent
  2. BNodes that have no children
  3. CNodes at the same depth in different subtrees
  4. DNodes that share the same parent
3.Easy

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

  1. APeek
  2. BPush
  3. CEnqueue
  4. DPop
4.Medium

A trie (prefix tree) is especially efficient for:

  1. APrefix searches such as autocomplete
  2. BFinding shortest paths
  3. CStoring matrices
  4. DSorting numbers
5.Medium

How much memory does an adjacency list use for a graph with V vertices and E edges?

  1. AO(E²)
  2. BO(V × E)
  3. CO(V + 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(log n), where n is the number of words
  2. BO(L), independent of how many words are stored
  3. CO(L × n)
  4. DO(n), where n is the number of words
7.Hard

Why do databases often use B+ trees rather than plain B-trees for indexes?

  1. AB+ trees do not need to be balanced
  2. BAll records are in linked leaves, which makes range scans efficient
  3. CB+ trees use binary internal nodes, which reduces the number of disk reads
  4. DB+ trees store data only in the root
8.Hard

The time complexity of decrease-key in a binary heap (given the element's position) is:

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

Answer key

  1. 1. B · A heap
  2. 2. D · Nodes that share the same parent
  3. 3. B · Push
  4. 4. A · Prefix searches such as autocomplete
  5. 5. C · O(V + E)
  6. 6. B · O(L), independent of how many words are stored
  7. 7. B · All records are in linked leaves, which makes range scans efficient
  8. 8. A · O(log n)

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