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.
Friday, 28 March 2014
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.
Subscribe to:
Posts (Atom)
