Upload
zeeshan-ali-mohammad
View
220
Download
0
Embed Size (px)
Citation preview
8/13/2019 23730874 Comparison of All Sorting Algorithms
http://slidepdf.com/reader/full/23730874-comparison-of-all-sorting-algorithms 1/16
Comparison Of All SortingAlgorithms
PresentationBy
G.Gopi Krishna Reddy
8/13/2019 23730874 Comparison of All Sorting Algorithms
http://slidepdf.com/reader/full/23730874-comparison-of-all-sorting-algorithms 2/16
Sorting
• The Process of rearranging the elementsso that they are in ascending order or
descending order is called sorting.• E ample! arranging of n"m#ers$ st"dent records.
%ery essential for searching the dictionaries$ telephone directories.
8/13/2019 23730874 Comparison of All Sorting Algorithms
http://slidepdf.com/reader/full/23730874-comparison-of-all-sorting-algorithms 3/16
PropertiesThe t&o 'ain properties of sorting techni("es are!
• Stable ! )f the sorting algorithm preser%esthe relati%e order of any t&o e("al elements$thenthe sorting algorithm is sta#le.
• In Place ! )f an algorithm does not re("ire ane tra memory space e cept for fe& memory"nits$then the algorithm is said to #e in place.
8/13/2019 23730874 Comparison of All Sorting Algorithms
http://slidepdf.com/reader/full/23730874-comparison-of-all-sorting-algorithms 4/16
Sorting Algorithms
*ario"s sorting algorithms are
B"##le Sort Selection Sort )nsertion Sort +"ic, Sort 'erge Sort
8/13/2019 23730874 Comparison of All Sorting Algorithms
http://slidepdf.com/reader/full/23730874-comparison-of-all-sorting-algorithms 5/16
B"##le Sort
• This is one of the most simplest sortingtechni("e and most straight for&ard
method of sorting.• )n this sorting techni("e$ the ad-acent
elements in the list are compared and
e changed if they are o"t of order.• This is also called as Sinking Sort
8/13/2019 23730874 Comparison of All Sorting Algorithms
http://slidepdf.com/reader/full/23730874-comparison-of-all-sorting-algorithms 6/16
Time Comple ity B"##le sort/• The time comple ity of #"##le sort in all
three cases #est$a%erage 0 &orst/is
1hich is not efficient compare to other
sorting techni("es.
T n/ 2 3 n45/
8/13/2019 23730874 Comparison of All Sorting Algorithms
http://slidepdf.com/reader/full/23730874-comparison-of-all-sorting-algorithms 7/16
Selection Sort• )n this techni("e first &e find the smallest item in
the list and &e e change it &ith the first item.• 6e t$o#tain the second smallest item in the list 0
e change it &ith the second element and so on.• Since$ the ne t least item is selected and
e changed appropriately so that elements are
finally sorted $this techni("e is called Selection Sort
8/13/2019 23730874 Comparison of All Sorting Algorithms
http://slidepdf.com/reader/full/23730874-comparison-of-all-sorting-algorithms 8/16
Time Comple ity Selection sort/• The time comple ity of selection sort in all
three cases #est$a%erage0&orst/ is
1hich is not efficient compare to other
sorting techni("es.
T n/ 2 3 n45/
8/13/2019 23730874 Comparison of All Sorting Algorithms
http://slidepdf.com/reader/full/23730874-comparison-of-all-sorting-algorithms 9/16
)nsertion Sort• )n this techni("e the gi%en list is di%ided into t&o
parts! sorted part( left ) 0 unsorted part( right ).• The "nsorted elements can #e placed any of the
positions in the sorted part so that elementsto&ards left of #o"ndary are sorted.• As each item is inserted to&ards the sorted left
part$ the #o"ndary mo%es to the right decreasingthe "nsorted list.
• 7inally$once the #o"ndary mo%es to the rightmost position$the elements to&ards the left of
#o"ndary represent the sorted list.
8/13/2019 23730874 Comparison of All Sorting Algorithms
http://slidepdf.com/reader/full/23730874-comparison-of-all-sorting-algorithms 10/16
Time Comple ity )nsertion sort/• The Time comple ity of insertion sort is! 1orst case!
A%erage case!
Best case!
T n/ 2 3 n45/
T n/ 2 O n45/
T n/ 2 8 n/
8/13/2019 23730874 Comparison of All Sorting Algorithms
http://slidepdf.com/reader/full/23730874-comparison-of-all-sorting-algorithms 11/16
+"ic, sort
• )n ("ic, sort$ partition the array into t&o parts s"ch that elements to&ards left of ,ey
element are less than ,ey element andelements to&ards right of ,ey element aregreater than ,ey element.
• Sort the left part of the array rec"rsi%ely.• Sort the right part of the array rec"rsi%ely.
8/13/2019 23730874 Comparison of All Sorting Algorithms
http://slidepdf.com/reader/full/23730874-comparison-of-all-sorting-algorithms 12/16
Time Comple ity +"ic, sort/• The time comple ity of +"ic, sort is! 1orst case!
A%erage case!
Best case!
T n/ 2 O n log n/
T n/ 2 O n log n/
T n/ 2 3 nlog5n/
8/13/2019 23730874 Comparison of All Sorting Algorithms
http://slidepdf.com/reader/full/23730874-comparison-of-all-sorting-algorithms 13/16
'erge sort• )n merge sort$ a gi%en array of elements is
di%ided into t&o parts.•
The left part of the array as &ell as the right partof the array is sorted rec"rsi%ely.• 9ater$ the sorted left part and the sorted right part
are finally merged into a single sorted %ector.
• The process of merging of t&o sorted %ectors intoa single sorted %ector is called simple merge.
8/13/2019 23730874 Comparison of All Sorting Algorithms
http://slidepdf.com/reader/full/23730874-comparison-of-all-sorting-algorithms 14/16
Time comple ity 'erge sort/• The time comple ity of 'erge sort in all
three cases #est$a%erage0&orst/ is!
T n/ 2 3 nlog 5n/
8/13/2019 23730874 Comparison of All Sorting Algorithms
http://slidepdf.com/reader/full/23730874-comparison-of-all-sorting-algorithms 15/16
Concl"sion• By comparing all the sorting techni("es
'erge sort time comple ity is less in all
three cases time cons"ming is less/.• So$ Merge sort is the most efficienttechni("e &hen compare to all othersorting techni("es.
8/13/2019 23730874 Comparison of All Sorting Algorithms
http://slidepdf.com/reader/full/23730874-comparison-of-all-sorting-algorithms 16/16
T:A6K ;O<