I am trying to solve programming challenges on www.interviewstreet.com using PHP. Are there certain techniques I should keep in mind that will optimize the efficiency of the algorithm? For example, I read that using PHP's language constructs versus function calls are faster. Is this true? Any other tips?
Not using functions isn't the mark of algorithmic efficiency. Algorithms themselves are language-agnostic, they are well-defined ways to do something that can be implemented in most any language. Algorithmic efficiency is far more concerned with ideas like "given input of size n, how many steps does a algorithm need to compute answer y?" and "if I increase the input, how does that affect the algorithm?"
Imagine this - what if you were going to sort 100 million items in a list? If your function was something like bubble sort, not using a function call will save you some microsecond of processing, but the actual sorting will take significantly longer and dwarf any gains from not using function calls or any other number of things (plus, not breaking your code up is usually a bad design and bad for maintenance!).
Algorithmic efficiency is usually noted with Big-O Notation and is part of complexity theory. They also relate heavily to data structures, which are things like linked lists, arrays, trees, graphs, etc.
You probably want to read about basic foundational algorithms, data structures and ideas, like:
- Associative arrays
- divide and conquer algorithms
- dynamic programming
- greedy algorithms
- sorting algorithms, which will give you a really good idea about algorithmic efficiency, as there are many different sorts that have different levels of efficiency and real world speed.
For books, if you're interested, there are:
- Algorithm Design Manual - Skiena's presentations here: http://www.cs.sunysb.edu/~algorith/video-lectures/
- Introduction to Algorithms (CLRS) - this is a very math-y book. It's excellent, but very mathematical.
- Algorithms by Robert Sedgewick
- Algorithms by Dasgupta et al. - you can get a free copy of their near-final draft
PS - many times you'll see people who want to optimize the hell out of their code to squeeze as much performance out of it as possible. What should really be asked first is if they picked the right algorithm to do it and are using the correct data structures.