Monday, 31 March 2014

Sorting and Efficiency

In python, sorting is a method that is usually used to organizes a collection of objects. It is very common to confront some sorting issues in our "daily programming life", and to be honest, we can say it was sorting that actually achieved what Google is (of course, there is no doubt that it is impossible to list all of this kind of examples).
I believe that sorting could not be categorized into just a few classes, yet I have only encountered 7 kinds of them. Quick sort is essentially based on the idea of choosing a pivot and sorting the partitions which are made by the pivot and where it goes. Merge sort always cuts a list in half and then merge the sorted results. All kinds of sorting method have their own shorts and strengths, and it really depends on the efficiency of the sorting method.
To compare their efficiency, we compute a way called big-oh to estimate their running time along with the increasing of the input, and it appears as following:


O(1) < O(log n) < O(n) < O(n log n) < O(n^2) < O (2^n) < O (n!) < O(n^n)

Sunday, 2 March 2014

Recursion

When I started to learn recursion, I tried to use "python", "recursion" as keywords to search some newbie instructions on Google. Unfortunately, almost everything I found was some specific guides for some certain examples. As a python rookie, those were too difficult to be the entry point for me, and what I needed was starting with basics.
Recursion is a programming method which allows you to make functions call themselves to accomplish objects.