Sorting – 1
Mergesort
Quicksort

This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*
The efficiency of handling data can be substantially improved if the data is sorted
according to some criteria of order. In a telephone directory we are able to locate a phone
number, only because the names are alphabetically ordered. Same thing holds true for
listing of directories created by us on the computer. Retrieval of a data item would be
very time consuming
if we don’t follow some order to store book indexes, payrolls, bank
accounts, customer records, items inventory records, especially when the number of
records is pretty large.
We want to keep information in a sensible order. It could be one of the following
schemes:
−
alphabetical order
−
ascending/descending order
−
order according to name, ID, year, department etc.
The aim of sorting algorithms is to organize the available information in an ordered form.
There are dozens of sorting algorithms. The more popular ones are listed below:
−
Selection Sort
−
Bubble Sort
−
Insertion Sort
−
Merge Sort
−
Quick Sort
As we have been doing throughout the course,
we are interested in finding out as to
which algorithms are best suited for a particular situation. The efficiency of a sorting
algorithm can be worked out
by counting the number of comparisons and the number of
data movements involved in each of the algorithms.
The order of magnitude can vary
depending on the initial ordering of data.
How much time does a computer spend on data ordering if the data is already ordered?
We often try to compute the data movements, and comparisons for the following three
cases:
best case ( often, data is already in order),
worst case( sometimes, the data is in reverse order),
and average case( data in random order).
Some sorting methods perform the same operations regardless of the
initial ordering of
data. Why should we consider both comparisons and data movements?