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 is the name of the stack operation that adds an element to the top?

  1. AEnqueue
  2. BPush
  3. CPeek
  4. DPop
2.Easy

What is a deque (double-ended queue)?

  1. AA queue that only allows removal at the back
  2. BTwo separate queues sharing one array
  3. CA queue sorted by priority
  4. DA structure that allows insertion and removal at both ends
3.Easy

In an adjacency list representation of a graph, what is stored for each vertex?

  1. AThe shortest path to every other vertex
  2. BThe total number of edges in the graph
  3. CA list of its neighbouring vertices
  4. DA row of V Boolean values
4.Medium

Why can a binary heap be stored in an array without any pointers?

  1. AAll keys in a heap are equal
  2. BIt is a complete binary tree, so positions follow simple index formulas
  3. CHeaps never contain more than 100 elements
  4. DArrays automatically keep the keys in sorted order, so no pointers are needed
5.Medium

What is the worst-case height of a binary search tree with n nodes if keys are inserted in sorted order?

  1. A√n
  2. Bn (it becomes a linked list)
  3. C1
  4. Dlog₂ n
6.Medium

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

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

How can you detect whether a singly linked list contains a cycle using O(1) extra memory?

  1. ACount the nodes until the count exceeds the list length field
  2. BMove one pointer by one step and another by two steps and check whether they meet
  3. CSort the list and look for duplicates
  4. DStore every visited node in a hash set
8.Hard

What does a splay tree do after each access?

  1. ARebuilds the whole tree in balanced form
  2. BRotates the accessed node up to the root
  3. CRecolours the nodes on the search path
  4. DMoves the accessed node to a leaf

Answer key

  1. 1. B · Push
  2. 2. D · A structure that allows insertion and removal at both ends
  3. 3. C · A list of its neighbouring vertices
  4. 4. B · It is a complete binary tree, so positions follow simple index formulas
  5. 5. B · n (it becomes a linked list)
  6. 6. B · A fixed-size queue
  7. 7. B · Move one pointer by one step and another by two steps and check whether they meet
  8. 8. B · Rotates the accessed node up to the root

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