Friday 28 March 2014

Sorting and efficiency! These two are the topics I learned for the past few weeks. I find it a little bit complecated. The code seems to be very complex at first and it took me few days to finally understand the code.

The type of sorting that is the most complicated for me is the merge sort because it divides each item in the list recursively, then sort it and finally merge it again. It turns out that, though merge sort seems to be a little bit complicated, this type of sorting is pretty fast compared to other types of sorting such as bubble sort and selection sort. The worse case of merge sort is nlogn, which means if there is a list with length n, the list will take at most nlogn to be sorted. Worse case is the time that it takes the most to implement a program. The opposite of worse case, called the best case scenario, is the quickest time that a program can run.

Here is an example of merge sort. Let L = [6, 3, 7, 2, 9, 1]. When merge sort is implemented, list L is broken down into two parts and each part will be broken down into two smaller pieces until there is only a single piece. Then, the term in the even position will be compared to the term next to it (for example, term at index 0 with index 1, index 2 with index 3, etc). The two terms will be merged together and the term with lower value will be placed before the term with larger value. After this is done, each two-merged term will be compared to the one next to it and, similar to the previous merging step, the term wil lower value will be placed before the larger one. This step is done when the list is already sorted correctly.

There is more than one sorting type that is discussed in the lecture notes and class, such as bubble sort, selection sort, insertion sort, shell sort, quick sort, tim's sort and count sort. However, I only explained the merge sort in detail because this is the type of sort that challenges me the most becaus it takes more time to understand it compared to the other sorting type. Also, this sorting type is very efficient as the worse case scenario can be presented in nlogn compared to, say, bubble sort, selectiom sort, and insertion sort that has a worse case scenario of n^2, which is considered to be slower than merge sort.

Thursday 6 March 2014

For the past two weeks, I learnt about linked list. Linked list is a data structure that has each node pointing to another node. Each node can only point to exactly one other node. A node has a value that is called cargo, and the very last node of linked list points to an empty list. 

It is easier to understand linked list concept by picture:
In the picture above, node with value 2 is called the head because this node is the first node in the list and no other nodes are pointing to this node. Node with cargo 2 is pointing to node with cargo 6, which is called the tail (to be more precise, node 6, 4, and 7 are all called the tail of node with cargo 2). Let's take a look at the head (node cargo 2). There are two boxes: 1) the left box with value of 2, and 2) the right box with number 2184. The left box is the cargo of the node, while the right box is the memory address of the value of the next node (the node that node with cargo 2 is pointing to). The node with cargo 7 is pointing to Null, which means that node cargo 7 is the last node of this linked list.

I didn't find any difficulties to understand the concept of linked list. What I am struggling is when I am asked to write the class LinkedList and write some methods for class LinkedList, such as the method __setitem__, __delitem__, __insert__, and __len__. I am not certain why I am finding it difficult. Maybe it is because I am not yet good at writing code. I guess I only way to improve my programming language skill is to write codes more and seek help from instructors and TAs.

Even though I find some difficulties, I still find this topic to be very interesting. Furthermore, I find the materials in CSC148H1 more interesting than CSC108H1 because CSC148H1 focuses more in the concepts of different kind of data structures, whereas CSC108H1 only focuses on the Python languages.

Friday 28 February 2014

Recursion is one of the most useful tools in programming as it allows program to run more efficiently and effectively by calling the function itself over and over again. An example of recursion can be found in the first assignment in this course.

In the 5th step of the first assignment of the course, I am required to implement the move method from TOAHModel class over and over again. The first step is to move n -  i many cheeses from the original stool to one of the intermediate stool. This can be done by creating a recursive function that instruct cheeses from the original stool to be moved to one of the intermediate stools for n - i many times. Then, I used recursion function to move i cheeses from the original stool to the destination stool, again, by using recursion. Lastly, I moved n - i cheeses that are stored in one of the intermediate stool into the destination stool. Because of recursion, this implementation can be expressed in only about 15 lines excluding the headers, doctrings, and comments. However, without the help of recursion, it might take longer lines to execute this implementation.

I find the concept of recursion to be very simple to grasp. I can easily understand what I am required to do and how recursion is needed to get the functions to run. However, I often struggle when I have to write the recursion body. It is difficult because it requires me to think creatively and cleverly to find the corrent code in order for the functions to run. I am still wondering how I can improve my creative thinking skills so that I can quickly write the correct code in recursive functions. At this time, the best solution that I can think of to improve my problem solving skills is to face a lot of recursion problems and try to find the correct code.

Recursion function is useful expecially when programmers face problems that require them to execute the same function over and over again but using different arguments. For example, the nested_depth function from the lecture requires us to repeat the body of the function if the item in the list is a list, and it will require us to use recursion until the item in that list is not a list. Programmers use recursion to instruct the function to do the same thing with different arguments until it meets the expectation of the question. This is why recursion is useful because otherwise, programmers have to keep duplicating the body of the function, which is not very effective and efficient. 

Thursday 6 February 2014

This week I learnt more about recursion. I didn't find recursion to be difficult. I really enjoy learning about this tool and I believe that recursion will be helpful in writing more effective and efficient code. In addition, I am starting to work on my assignment 1 this week. The assignment seems to be quite challenging because it requires me to think outside the box to figure out how to write a correct program that is effective and efficient code. I think I will use recursion in this assignment and I am looking forward to finish my first assignment in this course soon.

Monday 3 February 2014

Last week, I learnt about recursion and I enjoy last week's lectures. I find recursion to be an amazing tool in programming because I think recursions help programmers to write more effective and efficient programs. The part of the lecture that I enjoy the most is when the instructor (Danny Heap) showed the class how to draw in Python by importing class Turtle and it uses recursion to make the drawings. What I am looking forward after learning about recursions is to write programs that use recursions, such as writing a program to calculate the area under the curve of a particular function (integration) and some mathematical inductions.

Thursday 23 January 2014

I found it difficult to learn computer programming because I do not have the background in programming. I took programming courses in grade 10 and grade 11, but I do not feel that those courses prepare me for computer programming courses in university. I passed CSC108H1 and my mark was decent (it's slightly above the average), but I feel that my programming skill is still very little compared to my peers.

For the first three weeks in class, I learnt about how to write classes.The first time I learnt about writing classes is when I took CSC108H1 and it was only discussed for 1/2 weeks. This is why I found it difficult to keep up with the course. It seems that I have to spend so much time (2 days or even more in a week) to read the readings and understand the materials well.

I think the key to get better and better in learning object-oriented programming languages is to practice and write code regularly. Learning object-oriented programming languages is like learning piano: if you practice a lot, then you will get better and better, but if you don't then you won't get good at it. I am trying to keep practicing whenever I have the time to do so, though this is difficult to do since I also have other courses with pretty high course workload.

One last thing that I think is extremely important when learning about something difficult is to have the desire to learn the material and to never give up even though I keep receiving marks that I am not satisfied with.I believe that the desire to keep learning and trying is the key to become a successful person and that is why I won't give up learning computer programming.