Practice Discrete Math

Algorithms / Expected Runtime

Least You Need to Know: Expected Runtime, Random Choices, and Average Analysis

Expected runtime analysis asks for the average running time under a specified source of randomness, often the algorithm's own random choices. This is central for randomized algorithms such as quickselect and quicksort, where worst-case behavior is possible but rare under random pivots.

The least you need to know

Key notation

E[T] expected running time
randomized algorithm algorithm whose own choices use randomness
worst case largest runtime over all inputs or outcomes in scope

Tiny worked example

  • Randomized quickselect chooses pivots randomly.
  • Some pivot sequences are bad, but many are good.
  • Expected analysis averages over all pivot choices.
  • The result is expected linear time even though unlucky runs can be slower.

Common mistakes

How to recognize this kind of problem

Start practice