Note. Asymptotic analysis of algorithms [0018]
- 27 April 2026
Note. Asymptotic analysis of algorithms [0018]
- 27 April 2026
We begin with a preliminary example.
Example 1. Sorting a list
- 27 April 2026
- J.P. Loo
Example 1. Sorting a list
- 27 April 2026
- J.P. Loo
Consider a list of two numbers, and a task: to sort the list in ascending order.
We will assume that only one operation is permitted.
Operation 1.1. Comparison-cum-swap
- 27 April 2026
- J.P. Loo
Operation 1.1. Comparison-cum-swap
- 27 April 2026
- J.P. Loo
One may compare any two adjacent numbers, and, if they are in the wrong order, swap them.
How many comparison-cum-swaps do we need, on a list of two numbers, to sort it in ascending order? Clearly: one. For instance: if the list is , the comparison-cum-swap immediately shows that they are in ascending order, so we are done. Alternatively, if the list is , the comparison-cum-swap immediately shows they are in the wrong order, they are swapped, and then we are done.
Suppose the list contains three elements: for instance, . How many comparison-cum-swaps do we need? One isn’t enough; we’d only be able to consider two of the numbers, and so the third number would have no effect on the final putatively sorted list we produce. What about two?
Two might be enough to verify that a list is sorted, if we’re lucky. Given , we need only observe that and .
However, two is not enough, in general, to sort a list (rather than simply to check whether it is actually sorted). Consider: every comparison-cum-swap leads to at most two possible orderings of some list . So if there are two comparison-cum-swaps, there are at most orderings the procedure yields. But there are in fact six possible correct orderings of the list:
- ,
- ,
- ,
- ,
- , and
- .
We can pose the question for a problem of arbitrary size.
Problem 1.2. List-sorting
- 27 April 2026
- J.P. Loo
Problem 1.2. List-sorting
- 27 April 2026
- J.P. Loo
Given a list of numbers to sort, as a function of , how many comparison-cum-swaps do we need?
Similarly, other problems of arbitrary size can be posed.
Problem 2. Travelling salesman
- 27 April 2026
- J.P. Loo
Problem 2. Travelling salesman
- 27 April 2026
- J.P. Loo
Given cities and the distances between them, what is the shortest path by which the salesman may visit each of them at least once?
Problem 3. 3-SAT
- 27 April 2026
- J.P. Loo
Problem 3. 3-SAT
- 27 April 2026
- J.P. Loo
Given a formula over literals in conjunctive normal form each of whose clauses has at most three literals, is there a satisfying assignment?
A generalisation of the argument above in fact gives the answer to the question for sorting: approximately (Hoare, Quicksort
). The complexity of 3-SAT is open, but widely conjectured to be exponential.
Definition 5. Tight bounds
- 27 April 2026
- J.P. Loo
Definition 5. Tight bounds
- 27 April 2026
- J.P. Loo
Given a monotonically non-decreasing function , we write
Definition 8. Upper bounds
- 27 April 2026
- J.P. Loo
Definition 8. Upper bounds
- 27 April 2026
- J.P. Loo
Given a monotonically increasing function , we write
We can now restate the result of Hoare (Quicksort
).
Proposition 9. Quicksort II
- 27 April 2026
- J.P. Loo
Proposition 9. Quicksort II
- 27 April 2026
- J.P. Loo
The task of sorting a list of numbers takes comparison-cum-swaps.