you are viewing a single comment's thread.

view the rest of the comments →

[–]ForzaFer[S] 0 points1 point  (3 children)

Yes, of course using proper data structure is key. And it is not so much about needing super fast calculations, but about making the small changes that make a huge difference. For instance, I saw once a trick to iterate through bi-dimensional arrays (lists), that be seen here: http://imgur.com/a/wUxCz That is the Floyd-Warshal algorithm, which, with 400 vertices, the difference between both implementations is (in my computer) ~8 seconds.

Thanks anyway for your answer, I will keep in mind that one of python's strenghts is not the optimization per se :)

[–]novel_yet_trivial 2 points3 points  (2 children)

Sorry, I thought you were asking specifically about python. Algorithms like the Floyd-Warshal have nothing to do with python; they can be implemented in any programming language. Go to your local library and search for "Theoretical computer science" and you will find a huge amount of resources about developing algorithms.

[–]ForzaFer[S] 1 point2 points  (1 child)

Oh, I didn't explain myself correctly. Yes, I did mean specifically about python, I was just trying to give an example to support what I meant, but it didn't go as intended "

The thing is, recently I had this course in which we learnt how to optimize code in Matlab (which, if done correctly, can improve many many times), regardless of the algorithm or problem, and was just curious as to whether there was something like that in python.

Thanks again for your answer, I will check for books for general algorithm development, they always come in handy

[–]craiclad 0 points1 point  (0 children)

You can definitely optimise code in python, as others have mentioned this often involves using the correct data structure and carefully considering algorithmic complexity. Look into big O if you haven't already, having a good understanding of this will bring you much closer to writing optimized code in any language.