A tired week
- Quick Sort
- Stack & Queen
I've been through three tests this week, which almost wear me out.I have no energy to make complains. Here comes the slog:
This week, Danny demonstrates a so called 'quick sort' sort method that could sort a list of number very quickly(forgive my plain words).By the help of the super powerful recursion, just few steps, every number are sorted.
Here, is my analyse: For a given series of numbers: L=[6, 2, 5, 7, 1, 4, 3, 8]
First, we choose the first elements as a flag, in this case is 6.
Second, every other number has to compare their number with 6, if it is smaller than it, insert to the left of 6. If it is greater than it, inset to the right of 6.
Then, we get [3, 4, 1, 5, 2, 6, 5, 7, 8]. Now we just have to consider to sort the two sides' numbers of the number 6.
For the left part [3, 4, 1, 5, 2]. We repeat the above first and second steps, take 3 as a flag, then rearrange other numbers, then we get [2, 1, 3, 4, 5].
By some check, repeat these steps until all numbers all sorted. Hence, we do it again, take 2 as a flag, then rearrange orther numbers, then we get[1, 2, 3, 4, 5]. The right side is the same.
Less swap numbers means quicker sort, which is really useful by using recursion to complete such a problem.
Besides, I learned a new ADT(Abstract Data Type). Just like list, tuple and dictionery. We could use class to custom our own wanted ADT.
We can use a stack to check whether parentheses are balanced. It is featured
that the last item in is the first item out, which could be called 'LIFO'.Unlike
stack, queue is converse, which is 'FIFO'.It can be used to simulate the actual
world like a real queue. First people in the line should be the first to get
out.
Ok, that's it. I need to take a bath and have a good rest.
没有评论:
发表评论