Friday 7 February 2014

Week 5

As Recursion week continues, some of the topics we covered were binary representation, structured lists, recursive functions, tracing recursive functions, writing recursive functions, recursive insight and recursion levels. We first jumped into Binary Representations and how to calculate them.  Using the recursive functions learned last week, we implemented the function in our lab section. The code contained parts where it recalled return values of previous values in order to return the binary representation of the desired number. We could clearly see how the design of recursion is to solve sub problems first and the tackle larger problems.

An interesting part of this week was in lecture where we played a number guessing game, and were informed whether the guess was correct or the number guessed was too high or too low. Where my reaction for a number guessing game would be to guess the first number that pops up in my mind, the path to guessing in lecture was very different. We first split the range of numbers in half thus eliminating half the list.  We then proceeded to continuously cut the list of numbers in half when told if the guess was too high or too low. At the end of the game, the exercise showed how we could calculate the cumber in less than [lg n] steps, for any number n. This same method can be applied to find the midpoint of an item in a sorted list as we eliminate half the list based on the midpoint. We then delved into O(lg n) functions which I am honestly very confused about. My goal for this weekend is to devote time to 148 and catch up with all the material and report next week with all things we cover in Week 6.

Week 4

This week in CSC148, we started with binary numbers and the binary case. We implemented code to calculate the binary representation of any number. This was possible primarily because of the fact that given n -1 binary numbers, we can calculate the nth binary number. For this type of code we learned how to formulate a recursive function. The recursive function acts like a helper function in itself in a way. It is useful when there is a complex problem to solve, as the recursive function draws upon previous return values and uses them like a helper function. Some important strategies we learnt were to firstly solve the base case and then generate all smaller permutations.            
For the base case, we resorted to using smaller numbers in the same function to visualize how the function would work for a simpler case.  This is similar to the method of Induction learned previously in an Introduction to Mathematical Proofs course, where we first solve the base case and then progress into solving for any n+ 1 value. In addition, the base case prevents the program from crashing, as it provides insight as to how the program would function on a larger scale. All in all, I must say that Recursion week has been quite the learning experience. This is definitely material that I need to review and practise a lot more, and hopefully, soon enough, I’ll be writing my own recursive functions.

Friday 24 January 2014

Week 3.

As we approach the end of week three, we have covered how to design new Classes, Object Oriented Analysis, Abstract Data Types and Exceptions. The course content up to this point has been understandable and not over-whelming. The highlights of this week was definitely Dan’s cool reading technique, but on a more Python related note, I found the Exceptions method really useful, particularly in the case for helping with user input. While before I would have utilized a combination of if and else statements to combat anything the user said that was illegal, now I can simply use an Exception. The Exception proves its functionality as it informs the user of actions not recognized on Python, avoiding the use of if and else statements. In addition, we also learned how to handle the Exception  when we do not want our code to stop running in the event of operations that may cause exceptions. 

 The Abstract Data Types and Exceptions were brand new things learnt this week. I surprisingly enjoyed playing with the Stack and Queue methods and creating classes for them. While understanding how to create and implement those classes was frustrating at first, practice and reading definitely helped to further my understanding. This course so far has been most challenging during those awkward moments when my code decided to not run, and I find myself simply staring at the screen wondering what to do. Thankfully I have been able to find my errors and keep carrying on. An example of this would be my initial attempt to create an Exception code and watch it fail to run as I had written and implemented incorrect code. A concept I believe I conquered this week which I had not fully grasped in CSC108 was Classes. Through more practice and reading more examples, creating a class and defining the attributes, objects and methods is slowly becoming second nature this semester.
 As week three draws to a close, I am happy to say that I can now raise an Exception in my code. In conclusion, CSC148 so far has taught us new methods and tools we can use to create better, more efficient code.