Thursday, 28 November 2013

Sortof a Pun Related to Sorting

Selection Sort: This sort works by splitting the list into two parts: a sorted half and a non-sorted half. The algorithm then looks through the sorted half and puts the smallest element at the end of the sorted half.This occurs until the whole list is in the sorted half. Because the algorithm has to go through the whole list for every element of the list Selection Sort is O(n^2)

Merge Sort: Merge sort recursively separates the list into its smallest case (1 element) then takes two small lists and looks at the first elements. It then repetitively puts the smallest element in a new list until both the smallest lists are empty (or until one is empty and the rest of the other can go into the new list). The continues until all the 'mini-lists' are merged together into one big sorted one. Because Merge Sort divides the problem into smaller problems it has O(nlogn)

Quick sort: This chooses a point in the list then puts all smaller elements on one side and all the bigger elements on the other side. Now the point is at the right index. Quick sort then recursively Quick sorts the two sides. Quick sort also splits the problem into smaller problems and as such has a O(nlogn)


1 comment:

  1. You sir, have Class with those puns. If both Merge and Quick sort have the same run-time? Is either one better?

    ReplyDelete