The last week of the second term is around the corner! Only two more 148 lectures are left and I am almost done my year one! However, maybe the profs wanted us to feel the opposite rather excitement, so they decided to give us a hard midterm on last Wednesday. Well, at the beginning, I thought I might just give up this course or even CS. Thank God that I came up with the answers for each questions even though they were not perfect. Anyways, something is better than nothing on a test.
In these few weeks, we came across with sorting again just like what we did last term in 108. We first had some review on bubble sort, insertion sort, and selection sort. Afterward, the topic Big-Oh was added. Big-Oh function is the upper bound of the worst case run-time model of a particular algorithm. First of all, let's list out some of the new sorting algorithms that I learned in this week.
Assume we have a list of [8, 9, 0, 2, 5, 4, 3, 6, 1, 7]. Let's see what the sorting algorithms with do with it.
1) Quick Sort
We first need an element to be the pivot. We can just take the last element by convenience. Then, we split the list into two halves; the first half is those elements that smaller than 7, the other half consists those bigger than 7. Now, we have two other new lists: [0,2,5,4,3,6] and [8,9]. We then repeat the same process again by using recursion, taking the last element as pivot and split the list into two halves. At the end, we can combine all the elements from the smallest one to the biggest one and this gives us a sorted list.
2) Merge Sort
We need two function for this sorting method. The first one is called merge. We combine two sorted list into one sorted list by using Merge function. The other one is a function that recursively return Merge function on the two halves of a list. If we have [8, 9, 0, 2, 5, 4, 3, 6, 1, 7]. We will split this list again and again down to [8], [9],[0], [2],[5], [4], [3], [6], [1], [7], then we call merge in each pair. Then we get [89], [02],[54],[36],[17]. Then we do the same thing again and at the end we would have a sorted list.
The efficiency of each sorting can be compared by their worst case runtime on the same object. The quick sort is faster than merge sort since the worst case big-oh of quick sort is n^2 and nlogn for merge sort.
Monday, March 31, 2014
Monday, March 10, 2014
Tree and LinkedList
In these few weeks, we learned about LinkedList object and Tree object. I have met several type of Tree representation such as TreeList - a list of lists, binary Tree - a class contains root and children, and also binary search tree - something that I need to work on now. These different objects give me a lot of opportunities to understand python more. My passion in computer science keeps on growing because of this, too.
In lab, I finally met a fixed partner where I don't need to switch every time I go. And we help each other a lot. Unlike me, she is quite having a tough time with this course. However, she caught things up very fast after I explained some abstract concepts to her. I found it difficult while dealing with the Queue class implemented with the LinkedList. The enqueue and dequeue methods take us a lot of time that we can'y finish the whole assignment. It's quite challenging since we need to figure out which end of the LinkedList we should be doing the enqueue or dequeue. Basically, I think LinkedList is like a nested list, and we need to go very deep of it to look for the tail and do enqueue or dequeue methods. That's the hardest part to solve this puzzle.
The first test result wasn't ideal. I consider myself as a qualified candidate for the admission of ComSci. However, the test result gave me a warning. I should try harder and think deeper in the next few weeks. Hopefully, I can reach my goal in the upcoming test and exam.
You can do it, Chris!
In lab, I finally met a fixed partner where I don't need to switch every time I go. And we help each other a lot. Unlike me, she is quite having a tough time with this course. However, she caught things up very fast after I explained some abstract concepts to her. I found it difficult while dealing with the Queue class implemented with the LinkedList. The enqueue and dequeue methods take us a lot of time that we can'y finish the whole assignment. It's quite challenging since we need to figure out which end of the LinkedList we should be doing the enqueue or dequeue. Basically, I think LinkedList is like a nested list, and we need to go very deep of it to look for the tail and do enqueue or dequeue methods. That's the hardest part to solve this puzzle.
The first test result wasn't ideal. I consider myself as a qualified candidate for the admission of ComSci. However, the test result gave me a warning. I should try harder and think deeper in the next few weeks. Hopefully, I can reach my goal in the upcoming test and exam.
You can do it, Chris!
Subscribe to:
Posts (Atom)
