Reading Algorithms and Estimating Cost

  1. Counting Operations in a Small Algorithm

    A cost model names the operations it counts and treats the resulting count as a function of input size.

    Undergraduate
  2. Best and Worst Cases for One Input Size

    Best and worst cases compare complete inputs of the same size and report the smallest or largest cost under a specified model.

    Undergraduate
  3. Average Cost Needs an Input Distribution

    An expected operation count depends on which inputs or outcomes are likely, so state the distribution before computing an average.

    Undergraduate
  4. Reading Big-O Upper Bounds

    A big-O upper bound limits growth up to a multiplicative constant once the input is large enough.

    Undergraduate
  5. Counting the Work of Nested Iteration

    The cost of nested loops is the sum of the inner work over each outer step. The inner amount can vary across steps.

    Undergraduate
  6. Cost with Two Independently Varying Input Sizes

    When two inputs can grow independently, keep both sizes in the bound so it remains useful for unbalanced cases.

    Undergraduate
  7. Logarithmic Work from Repeated Halving

    Repeatedly halving a positive search interval reduces its length to a constant after a logarithmic number of steps.

    Undergraduate
  8. Separating Time and Extra Space

    Time describes operations performed. Extra space describes how much live storage the procedure uses beyond its declared input and output.

    Undergraduate
  9. Why Most Appends Are Cheap

    A growing array can have occasional expensive appends even when the total number of copies over a long sequence is small.

    Undergraduate
  10. Counting Temporary Space by Lifetimes

    A peak-space estimate counts the objects alive at once. Reusing temporary storage can reduce that peak while leaving total work similar.

    Undergraduate
  11. Counting Work Saved by Short-Circuit Evaluation

    A Boolean search can return once its answer is determined. Count elements evaluated rather than elements in the original source.

    Undergraduate
  12. Why Removing the First Array Element Costs Work

    A contiguous array that preserves order normally moves later elements left after removing an item near its front.

    Undergraduate
  13. A Small Worked Loop Invariant

    A loop invariant is a claim true before the loop and after every iteration. It links current state with the part of the input already processed.

    Undergraduate
  14. Early Returns and Worst-Case Running Time

    An early return can reduce work for some inputs without changing the worst-case growth rate.

    Undergraduate
  15. Comparing Scaling with Empirical Timings

    Comparing timings at several input sizes can reveal trends, while an operation-count argument explains why a trend is expected to persist.

    Undergraduate
  16. Constant Factors and Scaling

    Two procedures can have the same growth class and different costs at sizes that an application actually sees.

    Undergraduate
  17. When Output Size Lower-Bounds the Work

    An algorithm that explicitly produces many output records must perform enough operations to emit them all.

    Undergraduate
  18. Trading Storage for Fewer Comparisons

    A stored lookup can replace a repeated search when building and querying the lookup is cheaper for the workload.

    Undergraduate
  19. Sorting by Counting Keys

    Counting sort builds frequencies over a bounded range of integral keys and uses those counts to determine the sorted output positions.

    Undergraduate
  20. Checking Pseudocode Against Worked Examples

    Before implementing an algorithm, trace a small example that exercises its update rules, boundaries, and output interpretation.

    Undergraduate
  21. Finding the First True Value of a Predicate

    Binary boundary search can find the earliest true value in an ordered domain when all later values are also true.

    Undergraduate
  22. Two Pointers for a Sum in Sorted Data

    For two distinct positions in a sorted list, comparing the sum of the smallest and largest remaining entries can eliminate one endpoint.

    Undergraduate
  23. Sliding a Fixed-Length Window

    A fixed-length window can update a running total by removing the departing value and adding the incoming one.

    Undergraduate
  24. Checking a Greedy Choice on a Counterexample

    A greedy algorithm chooses a locally preferred candidate at each step. An example can refute a rule, while a proof must cover all allowed cases.

    Undergraduate
  25. Finding a Lower Bound Among Duplicate Values

    The lower bound of a target in a sorted sequence is the earliest position whose value is at least the target, or the end if no such position exists.

    Undergraduate
  26. Separating Preprocessing from Query Cost

    Some algorithms invest work once to make later queries cheaper. Compare the combined costs over the expected number of queries.

    Undergraduate
  27. A Decision Result and a Witness

    A decision answers whether a condition is satisfied. A witness supplies the object or positions making a positive answer verifiable.

    Undergraduate
  28. When Arithmetic Is Treated as Constant Cost

    Some algorithm models count operations on a fixed-size word in constant time. Large integers can require work on many words.

    Undergraduate
  29. Why Nesting Depth Alone Does Not Give the Cost

    Nested loops can do little repeated work when their total number of advances is bounded by input length.

    Undergraduate
  30. Input Shapes That Matter for Sorting Cost

    Sorted, reverse-sorted, and repeated-key inputs can exercise different branches of the same sorting implementation.

    Undergraduate