2014年3月30日星期日

SLOG: recursion

Recursion recently becomes our new topic after the learning of basic idea of OOP. It can be briefly described as a progress that function repeatedly runs itself until it reaches some sorts of conditions or goals, otherwise, it would keep looping. It is somehow similar to the ideal of using ‘while loop’, but in this case, it put the function itself back into the code, which increases a lot of challenges and deficiencies.  Binary tree would be a great example to show the use of recursion. Since it needs a majority of times of looping to get answer, recursion becomes amazingly suitable to binary tree search. I remembered the time when teacher show how the recursion works and use it to draw out the picture, and it was shocked and amazing.


An achievement that we got in this week was that we finished the assignment one, the one that needed to automatically find the running times of Tower of Haoni. But instead, we used cheese this time. To be frank, it is so difficult to use recursion cause it required a lot of thinking while using it, even though it needs only single-one line code in a function. Those people who did not learn computer science before would feel unconfident to use recursion.

SLOG: Sorting and Efficiency

Sorting and Efficiency

During these weeks, sorting becomes one of the most significant parts that we focus on after learning the recursion. It is basically an idea that rearranges the elements which are disorder and unorganized in a sequence back into some sorts of orders by repeatedly organizing, for instance, a sequence with 2, 1, 3, 5, 4, can be rearranged to the order that is from the smallest elements to the biggest elements, which is 1, 2, 3, 4, 5.  By using the methods of sorting, it would be contribute to saving times, for we can follow the order we want to design a program.  This makes me remember the idea of bubble sort that our CSC108 teacher taught us.

There are many sorting methods that have been developed for sorting the sequences back in order. During the class times, we have learned three types of different ways relating to sorting, which are the selection sorting, the quick sorting and mega sorting. No matter how it varies its ‘name’, the significant parts is the efficiency, to use the least times to do the most works, this leads us to a part that we needs to distinguish the worst, average, and best cases of those sorting methods, and I believe this is the most challenged parts that barriers me.  To give an example, selection sorting uses a recursive algorithm. In average case, it needs to take ‘nlog(n)’ times to finish the works if the list is set up by randomly, however, if the list has already a sorted list, then, it needs to take twice the times to finish to work. To be frank, it is a tough part when I was learning in class.

Also, the lab goes much more challenging than the past, I remembered that there is a lab handout that my classmates and I spent the entire class period to solve, but instead, we met a tough barrier in the first question that needed us to arrange them in ‘inorder’ and could not get any meaningful progress. That was a frustration. But I believe this is the meaning of the lab that required us to put hundred percent attentions towards the questions and figure them out in order to improve our skills.