Saturday, February 27, 2016

Week 6 Recursion



This week we mainly discussed the concept of the recursion. In my opinion, recursion is a strategy to deal with a problem set, which includes self-similar problems.

A good way to learn about the idea of the recursion is to trace the function and to figure out how the recursive function works on different depth.
For the number "17", it has depth 0 and doesn't meet the if condition. Therefore, it is a basic case without any recursion, so we get 17.
For "[1, 2, 3]", it has depth 1 and meets the if condition. Therefore, we apply the recursive function on each item in the list, and finally get 6.
For "[1, [2, 3, [4]], 5], it has depth 3. By applying the recursive function three times, we finally get 15.

Friday, February 12, 2016

Week 5 More on Stack, Queue, and Linked List


We have discussed linked-list, stack, and queue last week. For queue and stack, we completed classes based on python built-in ADT, list. However, when popping the first item from the queue, because of the shortage of the list, we have to move other items one position ahead, which will cost extra work. The same situation also occurs when we try to add one item at the beginning of the queue.

Therefore, after studying Linked-list, this week we use the linked-list to represent the Stack or Queue.
For Stack, the prepend could be represented as:

For Queue, the pop front could be represented as:

Saturday, February 6, 2016

Week 4 Stack, Queue, and Liked List

In CSC108, we had learned many basic Abstract Data Types, such as list, dictionary, tuples and so on. This week, we learned some ADTs which act like list, but own unique properties.

Stack & Queue
Stack is a LIFO (last-in, first-out) list, which means it is hard to add or delete in the middle of the stack, but you have the access to the most recently added item.
stack
Queue, unlike stack, is a FIFO (first-in, first-out) list. You are able to add new items at the end of the queue, but can only remove the earliest item.



queue

Linked-List
Linked-list is the most complex list. It is actually a group of nodes.