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.

Thursday 23 January 2014

Object-Oriented Programming

          Object-Oriented Programming, which is also known as OOP, carries an significant meaning in the field of computer science and represents almost the whole part of all the mainstream computer languages, such as C++ and Python. Theoretically, Object-Oriented Programming is able to handle whatever any other computer language can handle, however, when it faces some especial modules, Object-Oriented Programming always exerts more predominance.
          Since I have been only exposed to Python and barely touched other languages, it would be too irresponsible to comment a lot on the others. Hence, criticizing from the head of Python to its feet will mainly be today's topic. Although I have merely learnt Python for less than a year, it has already presented me an unambiguous yet splendid world of programming. Not mention all those basic instructions, Python is designed to be extensible and expandable, which allows me to build new module by using class other than just use the original built-in methods. And thanks to this feature, it makes python be able to store and classify information more easily, and achieve more rapid development and maintenance of programs. "Python where we can, C++ where we must", said by Google.
          However, numerous people criticize that comparing to other computer languages, Python takes more time to run a complex program, and I find it is very reasonable to say so. Efficiency is regarded as a significant indicator in programming, especially in Python, yet even if taking a very straight way to deal with a complex situation, Python still needs to "take a lot of effort" to accomplish its job. In week3 lab, which is lab2, the last procedure was to test the efficiency of my Stack and Queue classes. It was obvious that the processing time of Queue class increased evidently along with the increase of the data though the instructions were made as simple as possible. The problem was it took more time for Python to handle the process that inserting an object in a list by moving a bunch of objects backwards than only append an object at the last position.
       Sometimes Python would appear very confusing, especially while I'm trying to build some recursive functions. Recursive functions can return itself so that it really confused me at the first. After being walking in the haze for a while, I find a way out, which would be described as tedious, to ravel out my mind. I started writing down every steps about how the recursion works, and everything just shows up clearly.
       A lot of my friends have questioned me why did I choose to get into computer science. In their mind, it's all about difficult and dull logic, incomprehensible and pale language. I won't deny it because yes, programmers need to pay a lot of painstaking care to their works, yet I will still insist on my way since there is a gorgeous world glowing beyond the keyboards and screens.