Friday, 26 February 2016

Week 6 - Recursion

We finally learned recursion this week!

Recursion refers to the technique in which a function calls itself to accomplish a task. There are two types of recursion, structural and generative. Structural recursion is one where one of the parameters of the recursive function is a recursive data type. In generative recursion, the parameters are not recursive objects but they are still used to recursively carry out a task. An example of a recursive data type is a nested list.

 Recursion is used when the way the whole is found out is the same as the way each part is found out. While some recursive code can be written using for loops instead, it is not always possible. Recursion is also more readable and it is useful when dealing with data structures like trees. 

After that, we were introduced to two more built-in features: conditional/functional if and any(). Functional if is used when we want some expression to be evaluated when a condition is satisfied and another expression otherwise. For example, in a case where we return something if condition x is true, and return another if otherwise. Any is used to check if there is at least one thing that is true in a given list.

I look forward to learning more about recursion and to using it in some application soon.

Friday, 12 February 2016

Week 5 - Linked Lists

This week we delved deeper into the topic of linked lists.

 I learned that the idea of linked lists can be perceived in two different ways. One as a nested list and another as a chain of nodes. While the latter is the more common notion, during implementation, the different methods of a linked list may be based on either conception. Thinking of linked lists as a chain of nodes involves approaching them as a collection of individual nodes which know the next node (and the previous if we are implementing a bidirectional linked list) and a wrapper class that groups them and holds the collective information. The notion of nested lists involves approaching each node as a list containing another node which in turn is another list containing another node and so forth. In the second case, there is no need of a wrapper class. It is interesting to know that there is more than one perspective one can take on when implementing linked lists. In my opinion, having multiple perspectives of the same thing is beneficial in allowing one to adopt a point of view that best suits the requirements.

So far, I find data structures very interesting and look forward to learning more data structures.


Saturday, 6 February 2016

Week 4 - Stacks, Queues and Linked lists

Days are going by fast and CSC148 is getting more and more interesting day by day.

 This week we learned linked lists, stacks and queues. When I studied stacks and queues on my own they seemed like data structures that one would only see examples of in a professional setting. This week's lectures proved me wrong. I was surprised to hear that something like checking for matching parentheses, which we take advantage of everyday, is implemented using stacks.

Another topic I enjoyed was linked lists. At first sight, it seemed like a replica of lists (although the usage is the same, to store a list of objects) but several noteworthy, yet subtle differences became manifest. For one, unlike lists, linked lists don't need a long block of memory.  Second, when deleting things from a linked list, one doesn't need to move the rest of the items. One need only change the reference of the element that was pointing to it to the next element. Both these features will be especially useful in making large scale processes, that are heavy on memory, have optimal efficiency.

I think I learned very important data structures this week that will help improve my programming skills. I look forward to learning more data structures in the rest of the course!