Sunday, September 23, 2007

Sorting


Sorting

In data Structure there are so many kind of sorting available. Bubble sort,selection sort, insertion sort,quick, heap, shell and merge sort.
Sorting basically arrange the element in ascending or descending order.
All the sorting method, i like bubble sort. In this method to arrange element in ascending order to begin with the other element is compared with the element then they are interchanged. Then the 1st element is compared with2nd element, if it is found to be greater then they are interchanged this way all the elements is compared with next element and interchanged.
Selection sort: This method is simplest, to sort the data in ascending order, the other element is compared with all the elements if the other elements is found to be greater then the compared element then they are interchanged.
Quick sort: Quick sort is faster then any of the sorting method. The basic strategy of quick sort is to divide and conquer.
Insertion sort: Insertion sort is used when a particular element inserted at appropriate position. In this method 1st element compare with other element. In the second step 2nd element is compared with the other and 1st element. Every step an element is compared with all elements before inserted it.
Merge sort: merging means combining two sorted lists into one sorted list for this the elements from both sorted lists are compared. The smaller of both the elements is then sorted in the third array. The sorting is completed when all the elements from both the lists are placed in the third list.

No comments: