Sunday 30 March 2014

Week 9 - Complexity

Well, we just finished the 9th week of the course, and started a not so complex topic called complexity. This topic deals with the efficiency of functions, methods, and thus programs.

I found this topic quite interesting, especially observing the different run-times of different functions, and finding out the reasons for their difference even though they have identical inputs and outputs. I would probably say this is the most interesting topic I came across in this course so far.

The following is the maximum_segment function and an image of a lecture slide which shows how the different terms in T(n) grow for the function, as the number of elements n in the list L increases:

def max_segment_sum(L):
   '''(list of int) -> int
   Return maximum segment sum of L.
   '''
   max_so_far = 0
   for lower in range(len(L)):
      for upper in range(lower, len(L)):
         sum = 0
         for i in range(lower, upper+1):
            sum = sum + L[i]
         max_so_far = max(max_so_far, sum)
    return max_so_far



This was particularly an interesting observation, as even though I came across this function before in CSC108, I never thought about its behavior or run-time for different numbers of elements in the list.

Overall, this week went pretty well for me. There wasn't much challenge I had to face. However, the lab was not that easy; we had to deal with some nested functions and recursion. (If you are a freshman in Computer Science, this should sound scary.)

There is more one more positive I can take from this week; I successfully completed and submitted part 1 for Assignment 2. It was actually super-easy. I just tended to think in a too complicated way at the beginning, and thus confused myself. I must say, it was a great idea to include a part of the assignment solely for design; we often spend hours to make a program working, but we rarely think of our design of the code. This part of the assignment definitely helped me in learning to think and come up with design which has fewer lines of code. Thanks to inheritance.

Okay, I guess I have said everything I had in my mind for this week. Hoping for a wonderful weekend and a great coming week!

1 comment: