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

Which structure is typically used to implement a priority queue?

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

What is the root of a tree?

  1. AThe top node with no parent
  2. BThe node with the largest value
  3. CA node with no children
  4. DAny node in the middle
3.Easy

Which data structure works on the principle "last in, first out"?

  1. ALinked list
  2. BHash table
  3. CQueue
  4. DStack
4.Medium

How is a new element inserted into a binary heap?

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

What is the time complexity of searching for a key in a balanced binary search tree?

  1. AO(n log n)
  2. BO(n)
  3. CO(log n)
  4. DO(1)
6.Medium

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

  1. ALook at the root only
  2. BVisit every leaf and compare them
  3. CFollow right children from the root until there is no right child
  4. DFollow left children from the root until there is no left child
7.Hard

Which property keeps every B-tree perfectly balanced?

  1. AThe keys are stored only in the root
  2. BEach node stores one key
  3. CAll leaves are at the same depth
  4. DEvery node has exactly two children
8.Hard

Deleting a node with two children from a binary search tree is usually done by:

  1. ARemoving the whole subtree
  2. BReplacing it with its in-order successor (or predecessor) and deleting that node
  3. CRebuilding the subtree below it from scratch and reinserting every key it contained
  4. DSwapping it with the root

Answer key

  1. 1. A · A heap
  2. 2. A · The top node with no parent
  3. 3. D · Stack
  4. 4. C · Place it at the end of the array and sift it up while it violates the heap property
  5. 5. C · O(log n)
  6. 6. D · Follow left children from the root until there is no left child
  7. 7. C · All leaves are at the same depth
  8. 8. B · Replacing it with its in-order successor (or predecessor) and deleting that node

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