How to breakdown problem/algo

How to breakdown problem/algo
0

I face a tremendous problem when reading a problem on FCC or codewars. I cannot understand what to use and how to use it. I feel like I m not made for it. How does people do it? how can they break the problem and work backward?

1 Like

No one is made, they are built over time via practice, patience and lots and lots of failing.

There isn’t 1 way to break down a problem and “solve” it, in programming or any discipline. The key is there are multiple ways, from experience, off-hand knowledge, domain knowledge and pattern recognition, the list just goes on and on. The more ways to approach a problem, the more potential ways you can find a solution. Finding all these sorts of approaches/patterns usually relies on a mix of experience and research. FCC challenges will show you a way to solve a problem, but it takes some experience to fully understand and utilize that knowledge.

When given a problem, the first key step, that is normally just glossed over, is to understand the problem through and through, what it wants, requires, and what knowledge you need to know. If you skip, or gloss over this step you end up going “Uhhhh”, instead of googling, or you start trying to solve the wrong problem all together. It might seem obvious that you understand the problem, but most of the time you don’t and wont initially. Being able to understand what you need to do, what it requires is the difference between “knowing what you don’t know”, and “not knowing what you don’t know”. You want to know what you don’t know, or know you already know haha. This is different than knowing how to solve the problem. For example, you might need to know you need to loop over an array until you find an item, you might not know of a way to do that, but at least you understand the problem, regardless of what mumbo jumbo is going on around the actual problem.

Knowing how to break a problem down stems from understanding the overall problem in the first place. This applies to problems outside of programming as well. You need some experience and potentially domain knowledge to understand the problem, and know what sort of approaches/patterns you can apply. The more experience you have, the more “tools” you know to tackle a given problem.

Odds are most of the problems you run into when programming have already been solved. You just need to first know about those approaches/patterns/answers and how to implement them to the given case. Take sorting an array by a given property, if you know about .sort method on an array, your golden, if you don’t you might still know how to perform some basic sorting algorithms. Even if you know none of that, but understand you need to sort an array, then you can google “How to sort in X” (Where X is the language your using).

So, you really want to focus on at least knowing what is out there for you to leverage, and understand how to apply them to different situations, and there is one simple way to get that knowledge. Its practice, practice practice. I usually say, fail 500 times and learn 500 new things. If your on codewars getting stuck on level 8 Katas (if that’s what they are called haha) then keep doing them, look at the answers after a while and retry them from scratch. Keep grinding away at these problems and their solutions will eventually stick.

Experience is experience, and the more you practice, the more experience you get. If your struggling good! it means your probably learning something!

Good luck :smile:

5 Likes

Actually I am stuck on level 8. A lot of things come between me and algo e.g. Weak maths, or how do I do this, ur right in a way to google if u know what u want but that is on its own art. I feel overwhelmed by some problem and basically spends hours starring at the screen of what to do followed by closing laptop and ignoring it which I want to break.

then forget coding, take a sample input, a sample output, and take the algorith instructions
switch off your computer, switch off your phone, make sure you are not distubed, take pen and paper, and create an algorithm in words
the smallest steps you need to do to go from that input to that output
try with various inputs, try again
then find a volunteer, give them your algorithm and the input - if they follow your word algorithm, do they manage to get the correct output? (they need to not know challenge instructions and the output or could be biased, you aso could be biased so you could not be the best person to make the trial)
try with various inputs, try that the same input should give the same values, always
if yes, time to do the coding, find the correct operators, statements, functions methods etc, and put them together - now it is the time to make your algorithm understandable by the machine, the algorithm works, but the machine doesn’t know how to read what you wrote so far so you need to use its language

at any point, if you feel you get stuck, you can ask for help

but only trying and trying again will make you get better

also, an editor like repl.it would maybe work better to create your algorithms, you can after you have finished copy them on codewars

I replied with the specific focus if you are stuck on level 8 katas, or similar.

Identifying what is wrong, or the problem at hand applies to your learning process as well. If a level 8 kata takes hours, to figure out, you are either out of your depth, or missing a tiny thing. It sounds like your out of your depth, and if you are finding out the specifics as to what your having trouble with it next. Take for example you don’t know about parts of the JS api’s, or if your looking at the solutions, you don’t understand the given syntax. If this is the case go out and learn the API’s and syntax the solutions use. As I said earlier, failing 500 times means you learn 500 new things. If you can’t figure something out, find the solution, and then study and understand the solution.

Usually if you walk away you want to be thinking about the problem, if you walk away and not think about it is more or less not learning anything.

Programming isn’t something magical only a few understand, its hard work that any one can do but it takes time, grit and an internet connection. The fact your struggling means your learning something, how effectively you use your time to learn is more about the method than the person. The best programmers will stick with the problem, google for hours, read the solution, google some more, understand it at its deepest levels, and move on. They aren’t geniuses (or they might be, but don’t need to be), rather they are problem solvers.

I hate math, I’m weak at it, but I familiarize myself with solutions a number of ways as you can’t solve a programming problem that includes math without understanding the underlying math. Same goes for any domain level problem.

Stick with the problem, attack it from different angles, learn more angles (like the pseudocode method @ieahleen mentions above). There’s only 1 way a person “can’t” learn programming, and thats because they don’t let themselves learn it by giving up. It isn’t easy to learn or do, but anyone can do it.

1 Like

Often, before I even start coding, I pick up a pencil and scratch out the problem, as I see it, in my own words.

I will work through the problem, knowing the starting point and the ending point, like I cheat at mazes. From the starting point, move forward a little. Get stuck? I might jump to the ending point, and try moving back a step closer to the start. Work from one side, then the other.

There will be rabbit holes, or red herrings. I often fall into over-thinking, and need to step back and start again. That’s perfectly okay. Just like Edison, I’ve learned one more of the 99 ways of not making a light bulb.

Once I have a rough idea of the general steps, I start writing (STILL on that pad - remember the pencil?) in pseudocode. Not the formal pseudocode that some use, but step-by-step, in my own words. If a given step seems pretty involved, it may need to get broken down further (in programmer-speak, it may mean one or more functions make up this step).

And often, I find I can’t find the solution. I just don’t have it. Some of these are simply out of my wheelhouse. That’s perfectly all right, we aren’t supposed to be good at everything. But what we are good at, both individually and collectively, is researching and sharing ideas.

If I’m stuck on a problem, and stepping away and letting my subconscious work at it hasn’t helped, I will often ask for peer review. A team of six is my go-to support group, all coders with different strengths, and we’ll sit and whiteboard. I’ll throw out an idea, they might tear it apart or rebuild it differently. Or vice versa.

In short, start in your own words, work through the problem from both sides (what you have and what you want), write pseudocode in your own words, and learn to develop a support team.