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 binary search tree, values in the left subtree of a node are:

  1. ASmaller than the node's value
  2. BEqual to the node's value
  3. CLarger than the node's value
  4. DIn random order
2.Easy

What is the max-heap property?

  1. AAll leaves contain the maximum key
  2. BEvery left child's key is greater than or equal to its right sibling's key
  3. CEvery parent's key is greater than or equal to its children's keys
  4. DThe keys are sorted from left to right
3.Easy

What does the peek (or top) operation on a stack do?

  1. AReturns the bottom element of the stack
  2. BReturns the top element without removing it
  3. CRemoves the top element and returns it
  4. DRemoves all elements from the stack
4.Medium

Which abstract data type does Dijkstra's algorithm use to choose the next vertex to process?

  1. AA FIFO queue
  2. BA min-priority queue
  3. CA stack
  4. DA set with no ordering
5.Medium

Which data structure is used by depth-first search (iterative version)?

  1. AA stack
  2. BA heap
  3. CA queue
  4. DA hash table only
6.Medium

Which data structure does a running program use to keep track of active function calls and their local variables?

  1. AA binary search tree of frames
  2. BThe heap memory queue
  3. CA hash table of functions
  4. DThe call stack
7.Hard

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

  1. ASorting the array and binary search
  2. BFinding the median in O(1)
  3. CInserting elements at any position
  4. DPrefix-sum queries and single-element updates
8.Hard

What are the time and extra space costs of reversing a singly linked list in place?

  1. AO(n) time and O(1) extra space
  2. BO(1) time and O(1) extra space
  3. CO(n log n) time and O(1) extra space
  4. DO(n) time and O(n) extra space

Answer key

  1. 1. A · Smaller than the node's value
  2. 2. C · Every parent's key is greater than or equal to its children's keys
  3. 3. B · Returns the top element without removing it
  4. 4. B · A min-priority queue
  5. 5. A · A stack
  6. 6. D · The call stack
  7. 7. D · Prefix-sum queries and single-element updates
  8. 8. A · O(n) time and O(1) extra space

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