Tuesday, 11 February 2014

Week 5 - Assignment 1 and more recursion

The week started off with my group mates and I beginning to work on our TOAH assignment. Upon first seeing the assignment, the instructions were confusing and the overall coding was vague to us. We did research and began to understand more of what the concept of stacking cheese was. It turns out it is a very popular problem and the best proposed solution is an algorithm called the Frame Stewart algorithm. This however did not help us in the coding aspects of the first 2 steps in the assignment. We added methods such as add and remove in order to move the cheese around the stools. We also defined global variables in order to be able to work with our lists globally which was taught to us in class this week as well. We used a dictionary to store our stools as keys and a list of integers for our cheeses that is stacked upon the stools as the value. Our various methods such as add and remove will help in moving cheese from one stool to another while altering the global dictionary that we made which is our actual TOAH. We are still working on our assignment and struggling but progress is being made.

What we did in tutorials this week was tracing and writing recursive functions. Even though recursion was talked about in class for a while, the actual application of it was different from simply listening. Initially, my partner and I were running a recursive function with a for loop. However, we failed to return a value in our second else statement which caused the function to continue without stopping. We expected that the recursive function would only work given that we used a for loop. We were told that we could do it without a loop and with simple if and else statements. We then changed our loop into if statements and got the function to run as it should. Our understanding of recursive has increased after the tutorial.


Sunday, 2 February 2014

Week 4 - Recursion in programming

Week 4 in the course introduced to us the concept of recursions in programming. Recursion was mentioned numerous times throughout csc148 and was shown for the first time this week. Since this year was my first time doing computer science, it is my first time seeing recursive functions. Some people had already seen this type of programming in other languages and programming courses they may have taken. After learning about the concepts behind recursion, i can see how this style of coding can be beneficial to many problems. This style of programming allows for the user to get his answer by running the code until the value that it needs is met. The code will continue to run by itself through the recursive function calling itself. Special precautions must be taken however since in some cases, the code may run infinitely long and thus result in an error. Users using recursion must have statements in their code that tells the recursion to stop running when a certain case is met in order to avoid this error.
     Other concepts in computer that was learned this week is creating test cases for our own code. This was done in our tutorial time as we had to write objected oriented programs and then write auto-tests to test our code. This may seem like a waste of time at the moment because our code is short but when our code becomes complex, it will become extremely useful to test it automatically rather than manually. The exercise this week had us explore the exception class and write our own functions that calls upon these functions. This week had been great in learning about recursive functions as well as testing and the exception class.