Quick Sort and Binary Search
Quick Sort and Binary Search
M. P. Geetha,
Department of CSE,
Sri Ramakrishna Institute of Technology,
Coimbatore
Quick-sort is a randomized sorting algorithm
based on the divide-and-conquer paradigm:
A[i]≤p A[i]>p
The partition algorithm
partition (l,h)
{
pivot = A[l];
i=l; j=h;
while(i<j)
{
do
{
i++;
}while(A[i]<pivot);
do
{
j++;
}while(A[j]>pivot);
if(i<j)
swap(A[i],A[j]);
}
swap(A[l],A[j]);
return j;
}
Quicksort algorithm
quicksort (l,h)
{
if(l<h)
{
j=partition(l,h);
quicksort(l,j);
quicksort(j+1,h);
}
}
Binary Search
Searching
Searching is a process of finding a particular element
among several given elements.
The search is successful if the required element is
found.
Otherwise, the search is unsuccessful.
Searching Algorithms
Searching Algorithms are a variety of algorithms
used for the purpose of searching.
}
Time Complexity Analysis:
Best Case :
If number of elements in the list is 1 and the key is
present means then Time complexity T(n) = 1
Worst Case:
Otherwise Recurrence Relation, T(n) = T(n/2)+1
T(n) = 1 n=1
T(n/2)+1 n>1