Sunday, March 23, 2014

Week 9

   During Week 9, we learned about Big-O in class, and solved some BST problems in the lab. At first I had little knowledge of the helper function, but after the lab, I realized that writing a function can make the whole code easier to understand. For example, we want to calculate the factorial of n, we can write the following code:
def _fact(n):
    if n == 0:
        return 1
    return n*_fact(n-1)

def fact(n):
    n0 = int(n)
    if n0 != n:
        raise ValueError
    if n < 0:
        raise ValueError
    return _fact(n)
 
  Big O notation is used to classify algotithms by how they respond to changes in input size, and it usually provides an upper bound on the growth rate of the function. In the runtime problem of python, we call it the worst-case scenario.In CSC240 and CSC165, we have already learned about this concept, so this is easier for me to understand.
  As for the binary search tree(BST), it makes the related sorting algorithms and search algorithms (like in-order traversal) very efficient.

No comments:

Post a Comment