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 a tree, what is a leaf?

  1. AA node with no children
  2. BA node with no parent
  3. CThe node with the largest value
  4. DA node with exactly one child
2.Easy

In a tree, what are sibling nodes?

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

What does each node in a doubly linked list contain?

  1. AData and a pointer to the next node only
  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 two pointers, one to the next node and one to the node after that
4.Medium

How is a new element inserted into a binary heap?

  1. AInsert it at its sorted position by shifting all of the larger elements one place right
  2. BPlace it at the end of the array and sift it up while it violates the heap property
  3. CRebuild the whole heap from scratch
  4. DPlace it at the root and sift it down
5.Medium

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

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

AVL trees and red-black trees guarantee:

  1. AThat no node has two children
  2. BConstant-time search in every case
  3. CThat keys are stored in insertion order
  4. DO(log n) height through rebalancing
7.Hard

A segment tree is typically used to:

  1. ASort strings alphabetically by storing each prefix in a separate tree node
  2. BAnswer range queries (such as range sums) and updates in O(log n)
  3. CStore a graph's edges
  4. DImplement a stack
8.Hard

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

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

Answer key

  1. 1. A · A node with no children
  2. 2. D · Nodes that share the same parent
  3. 3. B · Data, a pointer to the next node and a pointer to the previous node
  4. 4. B · Place it at the end of the array and sift it up while it violates the heap property
  5. 5. B · A fixed-size queue
  6. 6. D · O(log n) height through rebalancing
  7. 7. B · Answer range queries (such as range sums) and updates in O(log n)
  8. 8. B · O(V²)

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