Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

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:

For books, if you're interested, there are:

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.

share|improve this answer
    
What do you think about this course? Looks like they have a lot of interesting info in there about algorithms. academicearth.org/courses/programming-abstractions –  Shaan Oct 26 '11 at 2:51
    
@Shaan - Some of those videos are relevant, #9-11, and the algorithms from #13 - 16. But most of the videos are Java/C++ heavy, and I don't know how much much they specifically use those languages in the discussion of algorithms. You should take a look at the slides and videos by Skiena (linked in my answer), which present the ideas using pseudocode, without cluttering it up using any language specific constructs (those Stanford videos will use pointers, which are mostly a C construct). –  birryree Oct 26 '11 at 2:57
    
Oh thanks so much for the advice and for taking a look! Really appreciate it! –  Shaan Oct 26 '11 at 20:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.