Sunday, 23 February 2014

Week 7 – Recursion
                A function in python is a recursive function if it calls itself again within the body of the current function. Recursion is a powerful tool as it was seen in Assignment 1. We had to create a recursive function for Tower of Hanoi with four stools. It saved a great deal of time compared to loops and other methods. One of the most important things in a recursive function is to understand what you are exactly trying to accomplish. If you are trying to calculate the sum of the numbers in nested lists, you would use recursive to get the sum. This makes another issue arise. How do you know when to stop the recursion? You need a well-defined stopping state so it will not lead into an infinite loop. Another thing to note is that there is a maximum number of recursive steps Python can do before it runs out of memory and crashes. You can use recursion for many purposes, such as; factorials, sum of nested numbers and Fibonacci numbers. Recursion is a tool you really need to understand when learning programming, it will help you a great deal and save a lot of time when programming more complex systems. If you question when to or when not to use recursion, just thing about this: Do I have to do the same thing more than once?

                Because Week 7 occurred on a reading week, this blog entry may be a little shorter than the other blog entries. We had no lectures or tutorials this week. We have our first midterm on Wednesday. Reading week gave me the time to let me prepare for the midterm and I feel confident going to write the test. I reviewed all the material and I feel like I need to learn a little bit more about recursive structures to feel fully confident.
               

                Assignment 2 part 1 was handed out a few days ago. I took a quick glimpse at it but I have not begun one bit yet due to midterms. I will put all my time into it after the midterm.

Sunday, 16 February 2014

Week 6 – recursive structures

                Something that I encountered in lectures this week was trees, it was completely new to me. The name tree comes exactly from the tree out there in nature. The trees can grow and shrink. There are roots, branches and leafs. You can only reach a leaf with one unique path. There is only one node in each tree and it is distinguished as root. Each non-root node has only one parent. You can calculate the height of the tree and branching factor of the tree. In class we did many examples with trees using recursion, such as: summing up the number of nodes in the tree, height of this tree, leaves and the branching factor. I enjoyed learning about trees, it gave me new insight on structuring data sets. I understand the majority about trees but there are some areas where I lack. I’ll be going over it during the reading week to gain a much better understanding where I lack. My confidence about trees is high, I feel like I understand the concept and where I could apply it. Now when I see trees outside, I’ll be thinking of trees in computer language.

                This week in the lab we worked on recreating given functions without using certain methods. It was a challenging lab but fun at the same time. We also did some unit testing, something that takes up a lot of time, I think. The hardest part of the lab was Pythagorean triples. We had to find every combination for Pythagorean’s triangle given the hypotenuse. It felt like an achievement once my lab partner and I finished it.


                Assignment one was due on Thursday. I was able to complete it all including the bonus. It felt like my biggest programming achievement to date. The biggest issue I had was with the recursive step. It took me a few hours to complete with my partner. Eventually we got it and moved on after a tiny celebration. We tested for an hour to ensure everything was working properly and we improved our docstrings.

Sunday, 9 February 2014

Week 5 – Stools, names, tracing

    This week’s lectures were a little unusual to me. The professor went over assignment one with us and helped us understand it. We spent an entire lecture just figuring out the requirements of the assignment and asking about difficulties we had with it. This gave me a better understanding of the assignment even though I had not started it at that point. In lecture we also learned about scopes and namespaces. Python looks for names in the following order: local, nonlocal, global and then built-in names. I never knew that we can have two of the same names in different functions, so that was pretty cool to learn! We also looked back at tracing a simple recursive function as further practice to strengthen our skills in recursion. We are told not to trace too far. Once you know the answer to something, just plug it in. It saves a lot of time for doing other things.

    Tutorials this week went smoothly just like last week’s tutorial. I was able to apply my newly attained knowledge to all of the problems presented in this week’s lab. Tracing the recursive functions wasn’t really challenging task for me but it provided me some good practice. However, writing the recursive functions was a much more difficult task for me. It was not impossible to do though; it simply took time and a lot of thought and effort. My partner assisted me with any difficulties I encountered while writing the recursive functions.
            
    Overall with the material covered this week I am fairly confident. I’m completely confident with the names and tracing portion. I will still however need to practice recursion a bit more to be fully confident with it. I feel like my achievement this week was achieved in the lab. I was able to make a recursive function to make a deep copy of a list. It felt nice knowing that I was able to rebuild one of the built in functions in python.

    I started the assignment on Thursday and was able to complete it on Saturday night. The first few steps were easy to understand and implement. The difficulty came when I had to make a recursive function for the four stools problem. That took me a couple hours but I was able to complete it and it felt great! I also did the bonus problem just to get some insurance points if something goes wrong with one of my functions.  

Saturday, 1 February 2014

Week 4: More Recursion

                This week we went back to recursion and got a more in-depth look at recursion. A function that is recursive must call itself at some point within itself. A recursive function needs a well-defined stopping state so it will not run away and cause an error in python. Recursion was new to me and I had trouble understanding it at first. I slowly started getting more comfortable with it after we traced it on the tree burst example in lecture. Recursion is useful for problems that require the function to be used twice or more. I enjoyed when Danny brought his “turtle” to class to give us a visual example of the turtle class in action. The only thing we did this week was recursion, it challenged and frustrated me at the same time. I felt that if I did not learn it, I would fall behind in class. Luckily I started understanding it more by the second lecture of the week. Learning recursion was one of my achievements for this week.

                Overall, my confidence with the material that was done this week I am fairly confident with it. I will reread the lecture slides and trace the recursive functions in my own time at my own pace to gain a better understanding of recursive functions. I’m glad that I can finally find some time to learn about recursion, I’ve been trying to find some time in the past for it but never found any time for it due to my workload. Exercise two was due this week. I started it a bit late but was able to complete it within a fair amount of time. I only had problems with part a on the exercise, part b went flawlessly. The first problem in part a occurred when I forgot to reassigned x after I tried to convert it into an integer. The second error was a silly one… I just forgot to raise the error… quite embarrassing.


                The tutorial this week was enjoyable just like the last one. The teaching assistant is very friendly, knowledgeable and helpful. The tutorial helped me with more thorough testing of my functions by using the unittest class. It took a few minutes to get the hang of it since I usually just use doctest to test my functions. I used unittest only once in CSC108 but I forgot completely about it. The tutorial was a good refresher for more thorough testing of functions. We also got to play around more with inheritance which was not hard to comprehend because of my previous experience with it. The only question lingering in my head if when a loop would be better to use rather than a recursive function.