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. AEnqueue
  2. BInsert
  3. CPush
  4. DDequeue
2.Easy

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

  1. ARemoves the top element and returns it
  2. BReturns the bottom element of the stack
  3. CReturns the top element without removing it
  4. DRemoves all elements from the stack
3.Easy

What is the name of the stack operation that adds an element to the top?

  1. AEnqueue
  2. BPeek
  3. CPop
  4. DPush
4.Medium

In a hash table using open addressing, what is the maximum possible load factor?

  1. AThere is no maximum
  2. B1
  3. C2
  4. D0.5
5.Medium

A node in a binary search tree has a right subtree. Where is its in-order successor?

  1. AIts right child, always
  2. BThe rightmost node of its left subtree
  3. CIts parent, always
  4. DThe leftmost node of its right subtree
6.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
7.Hard

Why might a server choose its hash function at random from a universal family?

  1. ATo make the hash table sorted
  2. BTo remove the need to resize the table
  3. CTo make it very unlikely that an attacker can pick many keys that all collide
  4. DTo guarantee that no two keys can ever collide, whatever keys an attacker sends
8.Hard

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

  1. AFinding the median in O(1)
  2. BInserting elements at any position
  3. CPrefix-sum queries and single-element updates
  4. DSorting the array and binary search

Answer key

  1. 1. D · Dequeue
  2. 2. C · Returns the top element without removing it
  3. 3. D · Push
  4. 4. B · 1
  5. 5. D · The leftmost node of its right subtree
  6. 6. A · A stack
  7. 7. C · To make it very unlikely that an attacker can pick many keys that all collide
  8. 8. C · Prefix-sum queries and single-element updates

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