Lower Bound
For
Comparison Sort
Ankit Agarwal
12/CS/061
HIT,Haldia
Purpose of Lower Bound Theory
-To decide whether a given algorithm is the most
efficient possible one.
-A lower bound g(n) is determined for an algorithm
that takes time f(n),written as
f(n)=Ω(g(n))
or, |f(n)| ≥ c|g(n)| ,n>n0
where c and n0 is some positive constant.
Lower Bound in Sorting
-A technique to show the permutation of integers
from 1 to n for an array A[1…n] of n distinct values
in the form of a tree following a particular sorted
order.
-The algorithm used here is called comparison-
based algorithm and the sorting procedure as
comparison sort.
Decision Tree(Comparison Tree)
Decision Tree Model
Input : A sequence of numbers x1,x2,x3….xn with the required
order(either increasing or decreasing).
Program : Labelled tree with non-leaf node label-i:j
where i and j are array indices.
Edge Labels-”<=” or “>”
Output : Leaf node labels.
Excecution : Begins at the root.
At node labelled i:j ,xi is compared with xj
Excecution follows branch with the appropriate label.
When the excecution arrives at any leaf ,its label is the
output.
Decision Trees
• Provides an abstraction of comparison sorts. In a
decision tree, each node represents a comparison.
Insertion sort applied on x1, x2, x3
1:2
2:3 1:3
3:1 1<2<3 3>1>2 2:3
2>1>3 2>3>1 1>2>3 1>3>2
Input Instance : x1=20, x2=30, x3=10
Generalisation
Suppose input x=∏(1,2,3,….n)where ∏ is a permutation.
Thus , (1,2,….n)=∏^-1(x)
If ∏^-1 denotes the sorted order ,then the algorithm must output
∏^-1 for this input.
Thus,∏- 1must appear as the label of atleast one leaf.This holds
for all permutations =>tree atleast n! leaves.
Each tree node can have at most 2 outgoing edges : with labels
“<=”or”>”
Thus, k ≥ log2 n!
where k is the height of the decision tree
Let T(n) be the minimum number of comparisons that are
sufficient to sort n items in the worst case.
Now,we know that in a binary tree,if all the internal nodes are at
levels less than k,then there are at most 2^k external nodes(one
more than the number of internal nodes).
Therefore,
k=T(n)
Since,T(n) is an integer, we get the lower bound
T(n) ≥ log2 n! [as k ≥ log2 n!]
By Stirling’s approximaton,
e(n/e)^n ≤ n! < e(n+1/e)^n+1
or, n! ≈ ((2∏n)^1/2)(n/e)^n
Using this relation,
log n!=nlogn-n/ln2+(1/2)logn+O(1)
Therefore,
T(n)=Ω(nlogn)
Another Approach
T(n) ≥ log n!
n!= n.(n-1).(n-2)……(n/2)….3.2.1
-------------------
n/2 terms
>(n/2).(n/2).(n/2)….(n/2)times
>(n/2)^(n/2)
Therefore,
T(n) ≥ log n!
> log (n/2)^(n/2)
> (n/2)log (n/2)
Removing the insignificant terms,we get
T(n)=Ω(nlog n)
Some Well-Known comparison sorts
Quick sort
Heap sort
Merge sort
Intro sort
Insertion sort
Selection sort
Bubble sort
Odd-even sort
Cocktail sort
Cycle sort
Merge insertion (Ford-Johnson) sort
Smoothsort
Timsort
Conclusion
-Sorting algorithms have a lower bound of nlogn in
comparison tree.
-To sort an array faster than Ω(nlogn),we must use
some other operations besides comparisons.
-Bucket Sort is a technique that uses key values as an
index into an array rather than comparing elements,
thus having a lower bound less than nlogn.
Algorithms

Algorithms

  • 1.
    Lower Bound For Comparison Sort AnkitAgarwal 12/CS/061 HIT,Haldia
  • 2.
    Purpose of LowerBound Theory -To decide whether a given algorithm is the most efficient possible one. -A lower bound g(n) is determined for an algorithm that takes time f(n),written as f(n)=Ω(g(n)) or, |f(n)| ≥ c|g(n)| ,n>n0 where c and n0 is some positive constant.
  • 3.
    Lower Bound inSorting -A technique to show the permutation of integers from 1 to n for an array A[1…n] of n distinct values in the form of a tree following a particular sorted order. -The algorithm used here is called comparison- based algorithm and the sorting procedure as comparison sort. Decision Tree(Comparison Tree)
  • 4.
    Decision Tree Model Input: A sequence of numbers x1,x2,x3….xn with the required order(either increasing or decreasing). Program : Labelled tree with non-leaf node label-i:j where i and j are array indices. Edge Labels-”<=” or “>” Output : Leaf node labels. Excecution : Begins at the root. At node labelled i:j ,xi is compared with xj Excecution follows branch with the appropriate label. When the excecution arrives at any leaf ,its label is the output.
  • 5.
    Decision Trees • Providesan abstraction of comparison sorts. In a decision tree, each node represents a comparison. Insertion sort applied on x1, x2, x3 1:2 2:3 1:3 3:1 1<2<3 3>1>2 2:3 2>1>3 2>3>1 1>2>3 1>3>2 Input Instance : x1=20, x2=30, x3=10
  • 6.
    Generalisation Suppose input x=∏(1,2,3,….n)where∏ is a permutation. Thus , (1,2,….n)=∏^-1(x) If ∏^-1 denotes the sorted order ,then the algorithm must output ∏^-1 for this input. Thus,∏- 1must appear as the label of atleast one leaf.This holds for all permutations =>tree atleast n! leaves. Each tree node can have at most 2 outgoing edges : with labels “<=”or”>” Thus, k ≥ log2 n! where k is the height of the decision tree
  • 7.
    Let T(n) bethe minimum number of comparisons that are sufficient to sort n items in the worst case. Now,we know that in a binary tree,if all the internal nodes are at levels less than k,then there are at most 2^k external nodes(one more than the number of internal nodes). Therefore, k=T(n) Since,T(n) is an integer, we get the lower bound T(n) ≥ log2 n! [as k ≥ log2 n!] By Stirling’s approximaton, e(n/e)^n ≤ n! < e(n+1/e)^n+1 or, n! ≈ ((2∏n)^1/2)(n/e)^n Using this relation, log n!=nlogn-n/ln2+(1/2)logn+O(1) Therefore, T(n)=Ω(nlogn)
  • 8.
    Another Approach T(n) ≥log n! n!= n.(n-1).(n-2)……(n/2)….3.2.1 ------------------- n/2 terms >(n/2).(n/2).(n/2)….(n/2)times >(n/2)^(n/2) Therefore, T(n) ≥ log n! > log (n/2)^(n/2) > (n/2)log (n/2) Removing the insignificant terms,we get T(n)=Ω(nlog n)
  • 9.
    Some Well-Known comparisonsorts Quick sort Heap sort Merge sort Intro sort Insertion sort Selection sort Bubble sort Odd-even sort Cocktail sort Cycle sort Merge insertion (Ford-Johnson) sort Smoothsort Timsort
  • 10.
    Conclusion -Sorting algorithms havea lower bound of nlogn in comparison tree. -To sort an array faster than Ω(nlogn),we must use some other operations besides comparisons. -Bucket Sort is a technique that uses key values as an index into an array rather than comparing elements, thus having a lower bound less than nlogn.