1 Recall... Computational Complexity
Time Complexity
2 Example: Binary Search
Best case Worst case Average case
3 Exercise: Linear Search 4 Example: Bubble sort
Most of the content is based on Section 2.3 of Rosen’s Discrete Mathematics, and 2.2 of Cormen et al. Introduction to Algorithms.
CS204/209 — Lecture 4: Best, Worst, and Average Case Complexity
1/11
Recall... Computational Complexity
Our goal is to be able to compare algorithms and determine which is the most “efficient”. When we calculate the efficiency of an algorithm, we are essentially trying to quantify how computer resources are required. And the two most important computer resources are time and memory. Usually this is referred to as the computational complexity of the algorithm, and Time complexity is an analysis of the amount of time required to solve a problem of a particular size, while the Space complexity is an analysis of the amount of memory required. For the most part, we take computational complexity to mean Time complexity .
CS204/209 — Lecture 4: Best, Worst, and Average Case Complexity 2/11
Recall... Computational Complexity Time Complexity
Time complexity is usually calculated in terms of the number of times certain operations are carried out by an algorithm, e.g., the number of additions or subtractions, the number of multiplications, the number of comparisons made (if statements). Typically, we count the number of times a certain operation, e.g, a comparison, and give a Big-O estimate. There are three possible cases of interest: Best-case: by sheer, dumb luck, what is the easiest problem we might have to solve? Worst-case: by sheer, bad luck, what is the worst problem we might have to solve? Average-case: what is the mean complexity over all possible sets of inputs.
CS204/209 — Lecture 4: Best, Worst, and Average Case Complexity 3/11
Recall... Computational Complexity Time Complexity
Of these, “best-case” is the easiest and