Sorting:
Sorting and searching are fundamental operations in computer science. refers to the operation of
arranging data in some given order. Such as increasing or decreasing, with numeric data or
alphabetically, with string data.
Selection Sort:
Suppose an array A with N elements A[0], A[1], . . . A[N-1] Is in memory. The Selection sort
algorithm for sorting A works as follows. First find the smallest element in the list and put it in
the first position. Then find the second smallest element in the list and put it the second position.
And so on.
Pass 1: Find the location LOC of the smallest in the list of N elements A[0], A[1], . . . . . A[N-1],
and then interchange A[LOC] and A[0]. Then: A[0] is sorted.
Pass 2: Find the location LOC of the smallest in the sublist of N-1 elements A[1], A[2], . . . A[N-
1], and interchange A[LOC] and A[1]. Then: A[0], A[1] is sorted. Since A[0] ≤ A[1].
............................................................
............................................................
Pass N-1: Find the location LOC of the smallest A[N-2] and A[N-1], and then interchanged
A[LOC] and A[N-1]. Then: A[0], A[1], A[2], . . . . A[N-1] is sorted.
Quick Sort(An Application of STACKS):
Let A be a list of n data items “sorting A” refers to the operation of rearranging the elements of
A so that they are in some logical order. Such as numerically ordered when A contains numerical
data, or alphabetically ordered when A contains character data.
Quick sort is an algorithm of the divide-and-conquer type. That is, the problem of sorting a set is
reduced to the problem of sorting two smaller sets.