I’ll be honest with you, I suck at algorithms and data structures. Trying to figure the proper approach is a difficult and brain-frying endeavor. And don’t get me started on the recursion, which makes everything 10x more challenging to reason about.
Luckily things get easier with experience, repetition and simple know-how. Old challenges that seemed insurmountable become easier to reason about. That’s why I love to return and rehearse some basic algorithms and data structures from time to time. It just makes you feel better when you finally understand how a linked list works, or a tree traversal is accomplished.
This time I wanted to try a TDD approach (more or less.) By writing a test first, and the implementation with possible refactor it is easier to solve a problem. Instead of staring into an empty code editor you start writing and thinking about the problem.
To write a proper test you need to:
- Understand the problem (What is my goal)
- Explore test cases (Find proper input and output)
And already half of the problem is solved. Now what rests is to create a solution.
What we can do now is:
- Break the problem down into smaller chunks & solve it
- Simplify once all the test are green
- Look & Refactor for performance (Remember that premature optimization is bad)
Problem-solving is an important skill to hone for a developer. By practicing on smaller chunks of code it is easier to gauge one’s level and simply stay motivated.