2016年4月2日星期六

Slog 11

Slog 11 

I reviewed my Slogs from the first Slog to the latest Slog. I found out that I changed a little ideas about my slog. I think the I should pay more attention to the lecture than reading lecture by my own. I studies the Big Oh part by my own, but I did not get a clear understand about the concept of Big Oh. I read the lecture note but I cannot really understand what it means.
The below is a part from lecture: 


So I went to a different lecture to catch up the material. After the lecture I found out I understand what is Big Oh from the examples I gained from lecture. The merge sort:
def mergesort(lst):
    """ Return a sorted list with the same elements as <lst>.
    
    @type lst: list
    @rtype: lst
    """
    if len(lst) < 2:
        return lst
    else:
        mid = len(lst) // 2 # This is the midpoint of lst
        left_sorted = mergesort(lst[:mid])
        right_sorted = mergesort(lst[mid:])
        # "merge" the two sorted halves (how?)
        return merge(left_sorted, right_sorted)

For merge sort it starts with a list of length of n and divide the length by 2 until it reach a list of length 1, the recursion depth of merge sort is the number of times you need to divide n by 2 to get 1. The number k such that 2^k ≈ n. Using logarithms we get the Big Oh is O(nlogn).


If I did go to lecture every time and listen carefully to the prof I should get less questions in the earlier slog. I think I would be confused about binary search tree or linked list any more.

没有评论:

发表评论