Documente Academic
Documente Profesional
Documente Cultură
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
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
)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.
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.
'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.
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<