The importance of using the right data structure

Have you ever read The Algorithm Design Manual? No? Well, I’m not saying you should, but it might be useful and it wouldn’t hurt. The name might give you a hint about its content, but for me, it’s the way this content is explained that makes this book great. I think the way the author presents its' concepts, giving real-life examples, makes all the difference. And of course, the famous Catalog of Algorithmic Problems is an invaluable resource....

November 14, 2013

Python decorators

In Python, functions are first-class objects. This only means that, like everything else, they’re objects. That can be a handy feature because that way we can pass functions as arguments to other functions. And also we can use functions as return values of other functions. Confusing, uh? Let’s see that with an example. def receiver(new_func): new_func() def return_function(): def func_to_return(): print "I was returned" return func_to_return receiver(func_received) func_returned = return_function() func_returned() If we run this, without any surprise we get:...

November 7, 2013

Sorting - can we do better than O(nlogn)?

Generally when we think about sorting elements in a list, we’re thinking about comparison sorting algorithms. Very well known algorithms of this kind are, for example, Quicksort or Merge Sort. So what do we mean when we say O(nlog)? This type of notation (called big O notation) describes us the limit an algorithm can have, in terms of its input. We’re normally interested either on their average or worst case....

November 3, 2013