Sunteți pe pagina 1din 16

Comparison Of All Sorting Algorithms

Presentation By G.Gopi Krishna Reddy

Sorting
The Process of rearranging the elements so 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.

Properties
The t&o 'ain properties of sorting techni("es are! Stable! )f the sorting algorithm preser%es the relati%e order of any t&o e("al elements$then the sorting algorithm is sta#le. In Place! )f an algorithm does not re("ire an e tra memory space e cept for fe& memory "nits$then the algorithm is said to #e in place.

Sorting Algorithms
*ario"s sorting algorithms are B"##le Sort Selection Sort )nsertion Sort +"ic, Sort 'erge Sort

B"##le Sort
This is one of the most simplest sorting techni("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

Time Comple ity.B"##le sort/


The time comple ity of #"##le sort in all three cases .#est$a%erage 0 &orst/is
T.n/ 2 3.n45/

1hich is not efficient compare to other sorting techni("es.

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

Time Comple ity.Selection sort/


The time comple ity of selection sort in all three cases .#est$a%erage0&orst/ is
T.n/ 2 3.n45/

1hich is not efficient compare to other sorting techni("es.

)nsertion Sort
)n this techni("e the gi%en list is di%ided into t&o parts!sorted part(left) 0unsorted part(right). The "nsorted elements can #e placed any of the positions in the sorted part so that elements to&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 decreasing the "nsorted list. 7inally$once the #o"ndary mo%es to the right most position$the elements to&ards the left of #o"ndary represent the sorted list.

Time Comple ity.)nsertion sort/


The Time comple ity of insertion sort is! 1orst case! T.n/ 2 O.n45/ A%erage case! Best case!
T.n/ 2 3.n45/

T.n/ 2 8.n/

+"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 and elements to&ards right of ,ey element are greater than ,ey element. Sort the left part of the array rec"rsi%ely. Sort the right part of the array rec"rsi%ely.

Time Comple ity.+"ic, sort/


The time comple ity of +"ic, sort is! 1orst case! T.n/ 2 O.n log n/ A%erage case! Best case!
T.n/ 2 O.n log n/ T.n/ 2 3.nlog5n/

'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 part of 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 into a single sorted %ector is called simple merge.

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.nlog5n/

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 efficient techni("e &hen compare to all other sorting techni("es.

T:A6K ;O<

S-ar putea să vă placă și