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 data structure works on the principle "last in, first out"?

  1. ALinked list
  2. BStack
  3. CHash table
  4. DQueue
2.Easy

The depth of a node in a tree is:

  1. AThe number of nodes in its subtree
  2. BThe number of edges from that node to the deepest leaf
  3. CThe number of edges from the root to that node
  4. DThe number of children of that node
3.Easy

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

  1. ADequeue
  2. BPush
  3. CInsert
  4. DEnqueue
4.Medium

A road network has 100,000 junctions, each connected to about 4 others. Which representation is most suitable?

  1. AA single sorted array of vertices
  2. BAdjacency list
  3. CA binary heap of edges
  4. DAdjacency matrix
5.Medium

Which abstract data type does Dijkstra's algorithm use to choose the next vertex to process?

  1. AA stack
  2. BA FIFO queue
  3. CA set with no ordering
  4. DA min-priority queue
6.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. CThe leftmost node of its right subtree
  4. DIts parent, always
7.Hard

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

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

Which property keeps every B-tree perfectly balanced?

  1. AEvery node has exactly two children
  2. BAll leaves are at the same depth
  3. CThe keys are stored only in the root
  4. DEach node stores one key

Answer key

  1. 1. B · Stack
  2. 2. C · The number of edges from the root to that node
  3. 3. A · Dequeue
  4. 4. B · Adjacency list
  5. 5. D · A min-priority queue
  6. 6. C · The leftmost node of its right subtree
  7. 7. A · To make it very unlikely that an attacker can pick many keys that all collide
  8. 8. B · All leaves are at the same depth

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