Friday, March 27, 2015

Week11- Thoughts on Test 2

Marks for Test 2 are finally out! Therefore, I decide to write down some thoughts about the test. Even though the score is not high, I have to admit that the test wasn’t as difficult as I supposed, and in fact, it was an interesting one.   I really like the idea of the first question, since we were asked to draw our algorithm out, and this is much easier than the following questions, which require us to write the code.

I was able to answer each question, however, I am not sure whether my code is accurate and can run. I have some difficulty with the last question, and I think it is because I don’t understand NNode very well comparing to LinkedList and Binary node. Overall, I think it is a fair exam, since the last two questions are very similar to our lab questions, and we all have an entire reading weak for preparation. My mark isn’t very nice, but is not that disappointing as well.

Another thing that made me worried is the strike. All labs are cancelled due to the strike. However, our test questions are often very close to lab questions. I think I will ask my assignment partners for help, and see we can finish all the labs together. This will be a good preparation for the final exam.



Friday, March 20, 2015

Week10-Thoughts on Code Efficiency


A crucial idea that I learnt in this course is the importance of efficiency. 

The idea of algorithmic efficiency wasn’t this important in CSC108 when we were mostly dealing with lists with defined length. However, efficiency becomes so important now because it is one of the key elements that ensures high performance of a complex code since it determines the the speed of runtime execution for the code. There are different ways to achieve efficiency, for example, one can reduce the number of functions, and use recursive functions instead of writing a bunch of loop. No matter how, the goal of code efficiency is to reduce resource consumption and  runtime as much as possible.

Today, I also read my old writing in Week5 which is about recursion, and realized that I have a different understanding about the topic now. In my old post, I said that recursion is similar to while loop and for loop, because they are all about repeating calculation. However, I realize that they are very much different in the sense of efficiency. The following code aims to determine whether a sorted list contain a specific number v. It is very efficient because it employs recession. Every time it runs, it divides the list in half, and search the two parts separately at the same time.  This function can also be written by while loop, but will look much longer and take more time to execute. 

class SortedList(list):
    ''' list in non-decreasing order '''

    def __contains__(self, v, start=None, stop=None):
        ''' (SortedList) -> bool
        Return whether SortedList (self) contains v.
        '''
        if start is None:
            start, stop = 0, len(self) - 1
        if start > stop:
            return False
        elif start == stop:
            return self[start] == v
        else:
            mid = (stop + start) // 2
            if self[mid] < v:
                return self.__contains__(v, mid + 1, stop)
            else:
                return self.__contains__(v, start, mid)

Friday, March 13, 2015

Week9-Review on Stack and Queue

I just realized that more than half of the term is completed!!! Among all the topics we covered, I consider Stack and Queue to be the two easiest one for me.  I love this topic because every step of only does one job. It is different from other topics such as recession which we need to complete repeated calculation for one single method. Even though Queue works according to the rule of 'first in first out' and Stack is 'first in last out', there is a great similarity between the fundamental steps of building a Queue and Stack. I am going to decompose the basic steps of a typical Stack and Queue class in this blog. 


So, for the first step, we initialize a Stack or Queue to be empty.










 The second step is to add an object the end of the Stack or Queue

After all objects are added, we can remove them one by one. For Stack, we always remove the last object, and for Queue, we remove the first one.   



 



 

Finally, we ask ourselves whether all the objects are removed from the Stack and Queue. This step is the same for both classes.



 



















Tuesday, March 3, 2015

Week8-Thoughts on Test1


Couple weeks have passed after Test, but I decide to write down some thoughts about it for future reference. I was quite nervous about it, so I copied all the lecture slides onto the cheat sheet. However, I realized that it is completely unnecessary, because I don't really have time to double check my answers according to the original code on my messy cheat sheet. I think I need to record some insights so that I can have some clues for future test preparation. 
1. Review lab materials.  The last two questions is very similar to lab questions.
2. Review a code my re-typing it. Since CSC108, I have known that there is a difference between understanding a code and being able to reproduce it during the test. I often have problem with generating a specific code even though I feel that I have the general understanding of the algorithm. 
3. Use the cheat sheet efficiently. It is unnecessary to have a fill every corner of the paper, having the sheet means to providing me insights for complex problems and confidence for simple ones.
4. Review Assignments. Submitting an assignment does not means to say goodbye to it. Many classical algorithms are repetitive, and can show again on the test. 
5. Read other people's slog. I check my friend Sylvia's slog(http://sylviasuyao.blogspot.ca/) quite often because I know that she has a great overall understanding of the course. When I had difficulty of understanding recursion couple weeks ago, her writing about recursion, especially the article "Recursion Explain with the Flood Fill Algorithm" she linked in her slog helped me a lot. 
All in all, this test wasn’t too difficult. I think the grade should not be disappointing, and I hope that I can apply what I learnt in this test to future tests and assignments.