Algorithms. Problem Solving.

For the past few months, I’ve been reading and learning about algorithms and data structures in more detail. (As a side note - maybe sometime later I’ll list and rate all the resources I used/am using to learn programming and computer science-related topics). So, as further I was getting into this topic of algorithms I’ve noticed such a thing that there are so many specific cases and tasks that it seems almost impossible to have in mind all of the approaches to them simultaneously.

I’ll describe what I mean: just one/two weeks ago I was doing LeetCode tasks #373 and #406. The process was: to understand the problem utterly, come up with an algorithm to handle the problem (just writing down your algorithm on paper would be enough), implement it in code to get tests passed (thinking about details of boundaries, using language constructions, etc.) and look at solutions of other people - to find out what can be optimized or where you went wrong. So, after spending some time on the problem and finally getting it right you feel great! You’ve just solved a problem you had been working on for a decent amount of time! But …

Now (after a couple of weeks) I do not remember how I solved the problem! Now I’ll solve this problem almost the same as I would do it a week ago! Well, maybe the problem is that some tasks just didn’t get into my mind because I couldn’t solve them and took a solution from another person. But I wasn’t copy-pasting them - at first, I would understand how the person solved this problem and then wrote the code on my own without looking at the person’s solution. For other tasks, solutions were purely mine.

Side note: actually, I advise you to do the same with every piece of code you see that you want to write. Don’t do “peek, write, peek, write” thing. Look at code once, grasp its logic and write on your own.

Back to the topic. So eventually, for all the tasks I’ve worked on, I understand the solution. Understand the logic and reason behind any step. And nonetheless I can’t solve it one more time! I have to go all the way up from scratch again (most of the time, and also during the process of reflecting on tasks old memories may raise).

But this rule doesn’t work for algorithms and tasks you face frequently. It’s obvious because you just remember better and better the solution to the problem you handle the most often.

As a result, a conclusion I came to: do not try to remember all the algorithms you encounter (although some people are naturally good at it). Try to understand how to solve the problem. This way you learn a problem-solving skill. Don’t worry whether you will remember its solution or not a few weeks later. By facing newer and harder problems your problem-solving skill improves. That’s what you need in the modern world - the ability to fix real-world problems.

Written on July 22, 2023