In this week's lectures, we focused on performance of algorithms and the famous (or notorious) Big-Oh notation. Being able to see the efficiency difference between the algorithms we often deal with daily really does help bring my thoughts together. I have been programming for quite a long time now and I have never given a real thought to what goes on behind the program and what makes it more efficient than the other ones. In terms of Big-Oh, O(1), O(n), O(2^n) and such are very straight forward but I find O(lg n) to be one of the most interesting algorithm behaviour. I never understood the definition of logarithm in math class until now. Take binary search as an example, the worst case performance is O(lg n) because it keeps dividing a list in half until the search is either found or not. If there are 8 elements in the list, the worst case would take 3 steps to find an element that exists.
Being able to see the a diverse amount of algorithm behaviours certainly bring my awareness up whenever I am programming. I am now super conscious of my codes and try to keep it as clean as possible without losing too much on overhead.
The most challenging part this week is not so much about the algorithm behaviour, but having to understanding different kind of sortings because I am not too familiar with them. For instance, I have heard of insertion and bubble sort before but I never tried to program it myself so it takes me a bit of time trying to figure out where the codes are heading.
No comments:
Post a Comment