Thursday 28 November 2013

Namespaces and memoizing

This week, we learnt about the namespaces, and the scope of variables. We learnt that a local variable cannot be accessed outside the function definition, while a global variable can be accessed only in the global space. The non local variables can be used outside the function definitions. Other thing we learnt is methods, and that methods of subclass override those of the superclass. Another interesting thing was tracing, where we saw the flow of the control in a recursive function, with the help of a visualizer. We saw how functions were called during each recursion cycle, and how values were returned, leading to the final answer. According to me,the most useful thing thing we saw in the last lecture was code efficiency. We used memoizing technique, where we stored previously calculated values in a table, to reduce identical calls to functions to calculate them. We used it on the fibonacci series and saw the results that we could calculate fib(400) using this technique, as compared to fib(40) without it. This concept was then applied to automate functions.

Friday 22 November 2013

Reduce and information hiding

This week, we learnt an entirely different topic from what we were doing in the past week. The first concept was information hiding. We prevented the user from directly manipulating the values of various variables used in the code. Instead, we made the variable private and used getters and setters to set and use its value.This helps avoids assigning of invalid inputs to the variables, as the input is validated in the setter. Other than that, it also allows us to make some variables as read-only type, by not providing the setter. Once we have all the required methods, we make a new variable as the property of this private variable, and access the getter and setter through it. I was aware about the idea of using getters and setters from my JAVA knowledge and its recent use in CSC 207. But, learnt some innovative methods of using them in this week.

The other concept introduced was reduce, which allowed us to break down any iterator to a single value, by applying an operation on pairs of items in the iterator. This is a very nice technique to extend some of the built-in functions like sum, multiplication. etc and use them in a place where they cannot be used directly. We can also define our own operations. This week,examples like multiplying the items in a list, summing a list containing lists,etc were shown. It is a very nice way of reducing the iterators, when different operations need to be done on the items.

Thursday 14 November 2013

Post term test

This week, we did not get the weekly dosage of CSC 148H1. We lost our Monday lecture to the fall break and the Wednesday one to the term test 2. As mentioned in the previous post, the fall break was an ideal time to finish up incomplete work, as well as relax, and procrastinate. Well, procrastination was undoubtedly there, as I did not have much work to do. I did some assignments for other subjects, and then studied for the test.The second term test was easy, but it was definitely harder than the previous one. What I felt about it was that binary trees were given all the weightage, and sorting algorithms were not tested at all. The first two questions were pretty much the same, and mainly tested the ability to traverse a binary tree. I was expecting the sorting algorithms to be tested, as I feel they have an important role to play in future. Anyways, the test was fun, and am expecting good marks on it.

Friday 8 November 2013

Sorting algorithms

This week, we continued the topic started last time. The big-oh notation. We studied the application of the notation in calculating the orders for various sorting algorithms. The sorting algorithms were explained to us using different sized coffee cups, which was a very nice technique to demonstrate the sorts in a practical way, allowing us to understand them better, rather than just looking at the code and trying to get it. Another advantage of doing it was that we could compare the times taken by each sort, and discuss about their orders easily, thereby coming to a conclusion on the better sort. A few types of sorting algorithms that we discussed were selection sort, quick sort, merge sort and count sort. Each of them used a different method and took different times to complete. Then, we compared them by their running times through a program, with varying size of the input. Selection sort lead initially, but as the size got larger, the factor of n2 came into play and it started taking much longer time. Count sort and the built-in sorts were the long term leaders, but for extremely large inputs, count sort was better. The only reason why it is not used widely is that it cannot sort values in the input that are larger than the input size.

Other things going on in the curriculum are the upcoming fall break and the second term test. The fall break is an ideal time to study, as well as for procrastinating. The term test on November 13 will encourage some studying though. But, it’s a nice time to finish up all the incomplete work, and also relax a bit by not having to attend the university.