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 which order does a postorder traversal of a binary tree visit nodes?

  1. ANode, then left subtree, then right subtree
  2. BLeft subtree, then right subtree, then node
  3. CRight subtree, then node, then left subtree
  4. DLeft subtree, then node, then right subtree
2.Easy

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

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

Which structure is typically used to implement a priority queue?

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

What is the cost of inserting an element in the middle of an array of n elements?

  1. AO(n), because later elements must shift
  2. BO(n²), because each element moves n times
  3. CO(1), because the index is known
  4. DO(log n), because of binary search
5.Medium

AVL trees and red-black trees guarantee:

  1. AThat keys are stored in insertion order
  2. BO(log n) height through rebalancing
  3. CConstant-time search in every case
  4. DThat no node has two children
6.Medium

The keys 50, 30, 70, 20, 40 are inserted in this order into an empty binary search tree. What is the left child of 30?

  1. A70
  2. B50
  3. C20
  4. D40
7.Hard

What is the running time of breadth-first search on a graph with V vertices stored as an adjacency matrix?

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

Why are B-trees used in databases and file systems?

  1. AThey use less memory than any array, so the entire index always fits in main memory
  2. BThey need no rebalancing
  3. CThey store data unsorted
  4. DTheir high branching factor keeps the tree shallow, reducing slow disk reads

Answer key

  1. 1. B · Left subtree, then right subtree, then node
  2. 2. B · Push
  3. 3. B · A heap
  4. 4. A · O(n), because later elements must shift
  5. 5. B · O(log n) height through rebalancing
  6. 6. C · 20
  7. 7. B · O(V²)
  8. 8. D · Their high branching factor keeps the tree shallow, reducing slow disk reads

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