The different sorts in the lab all had different O(n) values. O(n) is a term made to represent the limiting value and speed in which a functions divides tasks. Selection sort would have a run time of O(n^2), as it compares every item with every other item in the list to see what element s the smallest. Insertion sort has the same O(n) value because it needs to compare each element with every other item in the list. The run time of bubble sort is also O(n^2), because it compares every possible pair in the list. Quick sort has a value of O(nlgn), although the worst run time is still O(n^2), the function partitions it into two lists continuously, while returning a number each iteration. Python's Tim sort has a run time of O(nlgn), which it works out through adaptive sorting methods.
Memoization was also discussed in class a way a function could be slower than it could possibly be. This is because of redundant recursive calls such as seen in the fibonacci sequence which calls f(n-2) two times(f(n-l) same value is on next recursive iteration). This is a waste of a call and also a waste of time. For these reasons we analyze programs and their efficiency to develop products that are the best they possibly can be. Sorting has shown me how and why efficiency is so very important as a CS subject.

No comments:
Post a Comment