



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




We have established that f(n) ∈ n 2
. Let’s show why f(n) is not in some other asymptotic class. First, let’s show that f(n) ∉ Θ(n). Show that f(n) ∉ Θ(n). If this were true, we would have had to satisfy both the upper and lower bounds. The lower bound is satisfied because f(n) = 8n^2 + 2n - 3 does grow at least as fast asymptotically as n. But the upper
bound is false. Upper bounds requires that there exist positive constants c 2 and n 0 such
that f(n) ≤ c 2 n for all n ≥ n 0.
Informally we know that f(n) = 8n 2 + 2n - 3 will eventually exceed c 2 n no matter how large we make c 2. To see this, suppose we assume that constants c 2 and n 0 did exist such
that 8n^2 + 2n - 3 _ c 2 n for all n ≥ n 0 since this is true for all sufficiently large n then it must be true in the limit as n tends to infinity. If we divide both sides by n, we have
It is easy to see that in the limit, the left side tends to 1. So, no matter how large c 2 is, the statement is violated. Thus f(n) ∉ Θ(n).
Let’s show that f(n) ∉ Θ(n^3 ). The idea would be to show that the lower bound
f(n) ≥ c 1 n 3 for all n ≥ n 0 is violated. (c 1 and n 0 are positive constants). Informally we know this to be true because any cubic function will overtake a quadratic.
If we divide both sides by n^3 :
The left side tends to 0. The only way to satisfy this is to set c1 = 0. But by hypothesis, c 1
is positive. This means that f(n) ∉ Θ(n 3 ).
The definition of Θ-notation relies on proving both a lower and upper asymptotic bound. Sometimes we only interested in proving one bound or the other. The O-notation is used to state only the asymptotic upper bounds.
The Ω−notation allows us to state only the asymptotic lower bounds.
The three notations:
These definitions suggest an alternative way of showing the asymptotic behavior. We can use limits for define the asymptotic behavior. Limit rule for Θ-notation:
for some constant c > 0 (strictly positive but not infinity) then f(n) ∈ Θ(g(n)). Similarly, the limit rule for O-notation is
for some constant c ≥ 0 (nonnegative but not infinite) then f(n) ∈ O(g(n)) and limit rule for Ω-notation:
(either a strictly positive constant or infinity) then f(n) ∈ Ω(g(n)). Here is a list of common asymptotic running times:
MERGE - SORT( array A, int p, int r) 1 if (p < r) 2 then 3 q (p + r)/ 4 MERGE - SORT(A, p, q) // sort A[p..q] 5 MERGE - SORT(A, q + 1, r) // sort A[q + 1..r] 6 MERGE(A, p, q, r) // merge the two pieces
The following figure illustrates the dividing (splitting) procedure. 7 5 2 4 1 6 3 0 1 6 3 0 7 5 2 4
4 1 6 3 07 5 2 4 1 6 3 0 Figure 3.1: Merge sort divide phase
Merging: All that is left is to describe the procedure that merges two sorted lists. Merge(A, p, q, r) assumes that the left sub-array, A[p : q], and the right sub-array, A[q + 1 : r], have already been sorted. We merge these two sub-arrays by copying the elements to a temporary working array called B. For convenience, we will assume that the array B has the same index range A, that is, B[p : r]. (One nice thing about pseudo- code, is that we can make these assumptions, and leave them up to the programmer to figure out how to implement it.) We have to indices i and j, that point to the current elements of each sub-array. We move the smaller element into the next position of B (indicated by index k) and then increment the corresponding index (either i or j). When we run out of elements in one array, then we just copy the rest of the other array into B. Finally, we copy the entire contents of B back into A. (The use of the temporary array is a bit unpleasant, but this is impossible to overcome entirely. It is one of the shortcomings of MergeSort, compared to some of the other efficient sorting algorithms.)
Here is the merge algorithm: