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. APop
  2. BPush
  3. CEnqueue
  4. DPeek
2.Easy

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

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

What is the name of the queue operation that removes the element at the front?

  1. APush
  2. BDequeue
  3. CEnqueue
  4. DInsert
4.Medium

An application needs fast lookups and also needs to list keys in sorted order and answer range queries. Which structure fits best?

  1. AA stack
  2. BAn unsorted linked list
  3. CA hash table
  4. DA balanced binary search tree
5.Medium

How do you find the minimum key in a binary search tree?

  1. AFollow right children from the root until there is no right child
  2. BLook at the root only
  3. CVisit every leaf and compare them
  4. DFollow left children from the root until there is no left child
6.Medium

How many nodes does a perfect binary tree of height h have, with height counted in edges?

  1. A2h+1 − 1
  2. B2h
  3. Ch2
  4. D2h + 1
7.Hard

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

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

A Bloom filter can answer "is this element in the set?" with:

  1. APossible false negatives but no false positives
  2. BAnswers only for numbers
  3. CPossible false positives but no false negatives
  4. DExact answers always

Answer key

  1. 1. B · Push
  2. 2. B · A list of its neighbouring vertices
  3. 3. B · Dequeue
  4. 4. D · A balanced binary search tree
  5. 5. D · Follow left children from the root until there is no left child
  6. 6. A · 2h+1 − 1
  7. 7. A · Move one pointer by one step and another by two steps and check whether they meet
  8. 8. C · Possible false positives but no false negatives

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