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 a strange sort of a programmer. I am a software engineer by profession and I have written programs in more than one language in various capacities. I know quite a bit about various programming languages and software development in general (that comes with experience and active skill building).

However, I have a problem. I am bad at algorithms. I have made various attempts to teach myself and finally be able to say, I know this algorithm and can implement it well in a programming language. My attempts sometimes began with preparing for an interview where they would ask such questions and ended with them. I just start and get lost I guess. I know the things to learn from (MIT course on algorithms, and so many other resources there). I know, I should just put my head down, be determined and write algorithms/programs on paper and implement it in practice. But, I just seem to be not able to. I run into the mentality of "I don't need this algorithm in my job, or for some reason in the immediate future, and I am good at few things, so I will learn this when I need to..".

I really want to get over this. What is a good time frame to set myself and any advice to how I should approach this mentally and otherwise?

share|improve this question
4  
most of programming is is not coding algorithms –  ratchet freak Jun 8 '13 at 23:12
2  
It sounds as though you aren't able to learn them when you need to. Step one is accepting that. –  Telastyn Jun 8 '13 at 23:47
    
@Telastyn you are right in a way. –  Amit Jun 9 '13 at 0:07
    
"In many applications, algorithm plays almost no role, and certainly presents almost no problem.” — C.A.R. Hoare –  microtherion Jun 9 '13 at 1:27
    
Reminds me of myself and regular expressions. I use them so infrequently that I've never made a dedicated effort to learn them. But when I need them, I spend hours learning them all over again... –  ajax81 Oct 13 '13 at 2:13
show 2 more comments

closed as primarily opinion-based by gnat, MichaelT, Dan Pichelman, Ozz, Jim G. Oct 14 '13 at 11:43

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

Learn data structures.

No, really.

Find out why moving to the next item in a singly-linked list in the forward direction takes O(1) time, but moving to the previous item takes O(n).

Find out why searching for an item in an unstructured list takes O(n), but searching for an item in a balanced binary tree takes O(log(n)), and searching for an item in a hash table takes O(1). Understand why searching a list that is already sorted takes the same amount of time as searching in a binary tree.

You will always be able to use this knowledge. It's not about performance. Well, it is, actually, but it's more about understanding why these things work the way they do. Once you have a basic understanding of the design tradeoffs, you can begin to apply these design principles to your own code.

Note that it's perfectly OK to learn things like frameworks, libraries and languages syntax just in time. But learn the fundamentals (data structures, sorting algorithms, if-then, while, structured programming, functions, language design) just in case.

share|improve this answer
1  
I think this is a great way of approaching learning algorithms because it makes it all the more relevant to everyday coding. And by looking at data structures in this way, it makes it immediately relevant compared to attempting to learn algorithms from a book only to not need to apply what you've learned. –  Theomax Jun 9 '13 at 9:38
    
Agreed. Understanding time complexities as they relate to things like iteration and building up of data structures has helped me immensely to get a better grasp on the fundamentals behind what makes a good algorithm, rather than just trying to memorize specific algorithms by rote –  KChaloux Oct 14 '13 at 14:40
add comment

Think up a solution in your own terms

I took magic lessons in a group setting when I was a kid (twelve years old). I remember blurting out "How did you do that?" when the magician performed a trick in front of us. His response shaped my life... "Michael, if you truely want to know how this trick is done you must think how you would do it."

He taught me to think in my own terms. If my solution took seventeen clunky steps I didn't care... I came up with a solution. Then as I looked at the solution I realized I could combine this step with that step and tweak this a little and eliminate that.

That's how it works. Create your algorithm so it works. The start using stepwise refinement to see if the solution can be tweaked or refined into less steps or a more elegant solution. After several revisions you will have a pretty tight alogorithm.

share|improve this answer
add comment

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