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 queue operation that removes the element at the front?

  1. ADequeue
  2. BInsert
  3. CPush
  4. DEnqueue
2.Easy

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

  1. AStack
  2. BQueue
  3. CBinary tree
  4. DHeap
3.Easy

A graph consists of:

  1. AOnly a root and leaves
  2. BVertices (nodes) connected by edges
  3. CKeys and hashes only
  4. DRows and columns
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

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

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

What is the cost of inserting an element in the middle of an array of n elements?

  1. AO(log n), because of binary search
  2. BO(n), because later elements must shift
  3. CO(1), because the index is known
  4. DO(n²), because each element moves n times
7.Hard

Which data structure supports an LRU (least recently used) cache with O(1) get and put?

  1. AA binary search tree only
  2. BA stack only
  3. CA hash map combined with a doubly linked list
  4. DA single sorted array
8.Hard

Which property keeps every B-tree perfectly balanced?

  1. AAll leaves are at the same depth
  2. BEvery node has exactly two children
  3. CEach node stores one key
  4. DThe keys are stored only in the root

Answer key

  1. 1. A · Dequeue
  2. 2. B · Queue
  3. 3. B · Vertices (nodes) connected by edges
  4. 4. B · 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. B · O(n), because later elements must shift
  7. 7. C · A hash map combined with a doubly linked list
  8. 8. A · All leaves are at the same depth

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