This week, the lecture covered materials about measuring performance of an algorithm. Usually, the measurement depends on the size of an input, especially when talking about search algorithms. So, computer scientists classify an algorithm depending on how many "steps" it takes when the input, n, is large. The big-O notation tells us at most how long an algorithm takes, i.e. O(n), O(log n), O(n^2), etc. The slower the equation inside O grows, the better the algorithm is compared to another one that grows faster. Binary Search algorithm's complexity is O(log n), which is apparently is very good. When talking about complexity, it is assumed that log has a base of 2.
The exercises were pretty challenging for me. This time, I had to think about the problem before I could even start to code. Part B gave me the most trouble. I am not too certain if my algorithm is correct. It has passed my test cases but I may have missed some case that would cause a fault. If my program turn out to be fine, then I would feel relieved and be confident when approaching similar type of problems.
No comments:
Post a Comment