Friday, March 25, 2016
Week 10 Algorithm
We encountered algorithm this week. Here are some types of Big-O:
1) lg(n):
First of all, in computer science, the favorite base is 2, not e or 10.
Therefore, lg(n) could represent the number of times which we divide n by 2 until we reach 1. This idea is the same as the number of times which we double 1 until we reach n.
2) n:
This is such a case that we have dealt with many times before. It is simply linearly increasing. For example, when we try to check whether a certain integer is in a non-ascending list, we are doing the n algorithm.
3) n^2:
Many sort strategies we have learned in CSC108 belong to this type. For example, the bubble sort is to search for the maximum or minimum and put it at the first position and keeps sorting on the unsorted parts. The step of searching will take n times, and this step will also be applied n times. Therefore, we finally get n * n times, which is n^2
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment