r/CodingForBeginners • • 5d ago

Title: I understand DSA and OS algorithms logically, but struggle to convert that logic into code. How do I overcome this?

I'm currently learning programming and preparing for DSA and Operating Systems.

One problem I've been facing consistently is that I can understand how an algorithm works, what it does, and even follow its step-by-step execution. However, when I actually sit down to implement that algorithm in C or C++, I struggle a lot.

For example, I might understand how an algorithm like FCFS, SSTF, SCAN, or C-SCAN works. I can manually solve problems and understand the logic behind each step. But when I open my code editor and try to write the program from scratch, I often get stuck.

I struggle with questions like:

How do I translate each step of the algorithm into code?

Which variables and arrays should I create?

How do I decide where to use loops and conditional statements?

How do I organize the logic into a proper sequence?

How do I go from understanding pseudocode to writing an actual working program?

It's frustrating because I feel like I understand the concept, but I can't independently implement it.

For those who have experienced something similar:

Is this a normal phase when learning programming?

How can I develop the ability to convert logic into code?

Should I practice writing pseudocode first, or should I directly start coding?

How do you practice implementing algorithms without constantly looking at solutions or tutorials?

Are there any particular exercises or methods that helped you develop this skill?

I'd really appreciate advice from people who have overcome this problem. I want to become capable of implementing algorithms independently rather than just understanding how they work.

One last thing: If this subreddit isn't the right place to ask this question, could you please suggest some other subreddits where I can post it and get relevant advice?

Thanks in advance!

6 Upvotes

5 comments sorted by

2

u/marmotta1955 5d ago

Your approach is partially flawed. You will understand everything much better if you only start with and attempt to solve a simple, real world problem.

1

u/TheUmgawa 5d ago

Flowchart it. My flowcharts these days are informal little things on bar napkins, because I just need the general flow, because I’ve been doing it forever. But, if you learn to read and draw flowcharts, the conditionals and a lot of other things become readily apparent.

Or, your pseudocode isn’t terse enough. Good pseudocode, for a beginner, details every little step, then unpacks into a flowchart at about a 1:1 ratio. Hell, if you’re dealing in a language like C or assembly, really good pseudocode unpacks into code quite readily, because you don’t get much by way of shortcuts.

How did I develop this skill? A flowcharting class in college, before I bailed on CompSci to go play with robots and manufacturing, and about four months of repetition in that class, then probably another six months of programming my own little projects before I stopped doing formal flowcharts and started drawing broad strokes. Now it’s basically, “What has to be resolved before the next frame draw?” So, just a lot of practice.

1

u/Dazzling_Music_2411 5d ago

You say you understand pseudocode. Can you actually write the algorithm in pseudocode?

1

u/DeadlyVapour 3d ago

Like with all things. Practice.

You are like someone who learnt the grammar and vocab of a new language, but still struggle to speak the language.

You just need to keep practicing, and internalising it.

1

u/Additional-Depth-977 1d ago

this is completely normal, you’re trying to jump from “i get it” to “i can manufacture it” in one step; write painfully detailed pseudocode first, then turn each line into code and accept that the