Total Pageviews

Tuesday, 3 December 2013

Different Sorting Algorithms + Last SLOG!

This is the last week of this Slog. I really liked this course. Was really interesting but also hurt my pride quite a bit. CSC 108 was so much easier than this course. I felt like the top of the world during that course. But this course I realized how big the competition is in computer science. There were many peers who were way beyond my level. They knew so much more programming than I ever did. Some already know around 5 different languages. And in lectures there were discussions at times that totally did not make too much sense but some students seemed to know a lot and were always raising their hands. I realize after taking this course how much of a long road computer science entails.

Now on to the sort methods. Lets discuss three different sort methods and their efficiency. First we begin with Selection Sort!

Selection Sort required n-1 passes in order to completely sort the list. During each pass the largest number is compared to numbers ahead of it until a number is found that is greater than it or it reaches the end of the list. Then the number is either placed before a bigger number or is placed at the end of the list if its the biggest number. During the first pass the biggest number is placed at its proper position and then during the next pass the 2nd largest number and so on.
Selection Sort is in big O of N^2
The problem is that as the list becomes bigger and bigger it takes too long for the list to be sorted. It is for this reason that selection sort is not very good for sorting really big lists.

Merge Sort is a recursive sort algorithm which recursively splits the list in half until two halves are split or in some cases there is a single number on left on its own (base case). In this case the list is already sorted. The two halves are sorted together and then the pieces keep joining together until the whole list is sorted. Merge sort is in big O of nlogn.
Selection Sort is more efficient than selection sort with it comes to larger lists. nlogn insures that every single number does not need to be sorted one by one. Instead the splitting makes the job much faster

Quick Sort is similar to Merge Sort but instead of splitting in half it finds a pivot value and then
uses the pivot value to split the list recursively. Quick Sort for the most part is more efficient than Merge Sort but if the pivot does not properly splits the list, then the efficiency of the sort is hindered.

Quick Sort was the best out of these three sorts from the examples I saw from lecture.

After looking at all the different sort methods I think Quick Sort is one of the harder ones to understand. It takes a while to get used to the idea of how quick sort works.
Merge Sort and Selection Sort are explained so easily and for educational purposes I like these two sorts way better.




1 comment:

  1. You'll catch up in no time if you like what you study and put in the time. We each have our strengths - you 'll be surprised how important knowledge about different fields is to be a creative computer scientist or software engineer. Maybe yours will surprise you.

    ReplyDelete