I highly encourage you to have a look at 5 Rules of Programming, written by Bob Pike (https://users.ece.utexas.edu/~adnan/pike.html)—short and succinct, alas I cannot quote all of them here.
If you want to learn more about algorithms, data structures, and the O(n) (big O) notation, there is the classic academic reference book, Introduction to Algorithms by Cormen, Leiserson, Rivest, and Stein (MIT Press, 3rd edition, 2009), but it could be a little heavy going, though. A lighter read is The Algorithm Design Manual by Steven Skiena, (Springer, 2nd edition, 2008).
A classic example of algorithmic optimization in action is the HashLife optimization for the Game of Life and you might like to read it. One of the descriptions can be found here: An Algorithm for Compressing Space and Time by Thomas Rokicki (2006) http://www.drdobbs.com/jvm/an-algorithm-for-compressing...