Data Structures and Algorithms: practice problems and exam questions

Big-O notation, the running time of common algorithms and the trade-offs between arrays, linked lists, trees, hash tables and graphs.

Cram pack (PDF)Formula sheets, method steps and practice problems with full solutions, ready to print.

Topics in this course

  1. Algorithms & complexitykey terms and facts · applying the concepts · cases and analysismultiple choice
  2. Data structureskey terms and facts · applying the concepts · cases and analysismultiple choice
  3. Graph theorydegrees and edges · Euler paths and trees · shortest paths and spanning treescalculations

Exam tips for Data Structures and Algorithms

  • For nested loops, multiply the number of iterations; for loops in sequence, keep the larger term.
  • Know the cost of search, insert and delete for each data structure.
  • Halving the input at each step gives logarithmic time.

Worked examples

Algorithms & complexityEasy

Which notation describes an upper bound on growth?

  1. ABig Omega
  2. BLittle omega
  3. CBig O
  4. DBig Theta
Show hints
  1. "At most".
  2. Two wrong answers are now crossed out. One of the remaining two is right.
Show the answer and explanation

Why this is the answer

O gives an upper bound, Ω a lower bound and Θ a tight bound.

Answer

C · Big O
Data structuresMedium

How does extract-min work in a binary min-heap?

  1. ARemove the last element of the array
  2. BMove the last element to the root and sift it down
  3. CRemove the root and shift all elements one place left
  4. DSearch all leaves for the new minimum
Show hints
  1. Keep the tree complete, then fix the order.
  2. Two wrong answers are now crossed out. One of the remaining two is right.
Show the answer and explanation

Why this is the answer

The last element fills the hole at the root and is swapped with its smaller child until the heap property holds, taking O(log n).

Answer

B · Move the last element to the root and sift it down

How practising works

  • “Practise this course” mixes problems from all its topics, like a real exam.
  • Every problem has new values, so you learn the method instead of an answer.
  • Stuck? Open a small hint first, and the full explanation only when you need it.
  • Mock exams are timed and have no hints, and you get your score and a full review at the end.

Related courses