Wednesday 4 December 2013

Sorting Algorithms

This is the last week of your CSC148 SLOG.  As well as any other
entries this week, you should write on sorting algorithms selection
sort, quick sort, merge sort, and efficiency.

There are infinite many different types sorting algorithms one can write. Sorting algroithms come in handy when you have a large list of numbers or words and you want them to  be sorted from greatest to smallest or smallest to greates and in the case of words they can be sorted alphabeticallly.  The selection sort is when you look at the minimum value  in the list and you switch it with the current positon you are at. An example would be [1,5,6,2] the first sort would be [1,2,6,5] and the next one would  be [1,2,5,6]. The selection sort algorithm has an efficiency of 0(n^2) which is okay for lists that aren't super huge but wont be effective with large lists. The idea of quick sort is to choose a pivot point in the list and compare it to every value in the list. If it is less than the pivot then it moved to before the pivot and all values that are larger than the pivot is moved to after the pivot. And continue to do this recursively in each sub section of the list. Quick sort has an efficiency of O(nlogn) which is less efficient than selection sort. Finally Merge sort is when you divide the list into halves and sort each half then merge the results together. Merge sort has the same efficiency as quick sort

No comments:

Post a Comment