1. Submitted to- Submitted by-
Mrs. Randeep Bhatia Ms. kajal sharma
(AP in cs dept) MCA5th sem
1718781
2. SORTING
Sorting and searching are the two most common
operations performed on data stored in
Computers . Most of the data structures that we
have studied so far are primarily designed to make
sorting and searching easier and more efficient on
the data stored in the structure.
sorting refers to the process
of arranging data in a particular order such as
ascending or descending order . An ascending
sort of five integers{20,10,60,45,25}produces
3. {10,20,25,45,60}where as descending sort produces
{60,45,25,20,10}.
The main objective of sorting is to organize
the data so meaningful .
Methods of sorting
• Internal sorting-In Internal sorting ,all of the data which
is to be sorted can be held in primary memory(ram) during
the sorting algorithms.
• External sorting-In external sorting ,all the data to be
sorted can’t be held in the primary memory at one time of
the data has to be sorted in secondary storage devices
such as hard disk, floppy disk etc.
5. Merge sort
Merge sort is a well known sorting algorithm
invented by john von Neumann in 1945.It is based
on the divide and conquer strategy in which we
divide the data into smaller pieces , recursively
conquer each piece and merge the result until the
original list is rebuild to a sorted one .
The merge sort algorithm divides the given
list to be sorted into two subsists of approximately
half size , sorts each subsists independently and
then merge the two subsists into a single sorted list.
6. Original list
We begin merge sort by first dividing the original
array into two sub arrays of approximately equal size.
Thus we divide the array into sub arrays as follows
Original list is divided into two halves
Example :-
7. our aim is to sort each sub array so that it can be
merged later. Now consider the left sub array
which is again divided into two sub arrays as
Left sub array subdivided into two halves
To each of these sub arrays again apply the same
method that divides each of these into sub arrays of
one element each
8. Merging of sub arrays
Right sub array subdivided into two halves
our aim is to sort each sub array so that it can be
merged later. Now consider the left sub array which
is again divided into two sub arrays as
9. To each of these sub arrays again apply the same
method that divides each of these into sub
arrays of one element each
Dividing technique
11. Advantages
• It can be applied to files of any size.
• Reading of the input during the run –creation
step is sequential.
• If heap sort is used for the in-memory part of
the merge ,its operation can be overlapped.
12. Disadvantages
• It requires extra space.
• Merge sort requires more space than other
sort.
• Merge sort is less efficient than other sort.