Data structures and algorithms
Posted by Imaginary_Food_7102@reddit | learnprogramming | View on Reddit | 10 comments
How does one approach learning data structures and algorithms?
I'v been doing codewars mostly, and leetcode seems really hard for me, even on codewars i solve simple problems not heavy algorithmic ones. How do i approach leetcode problems? for example there is X problem where you need to know Y data structure and Z algorithm, should i research about Y data structure and Z algorithm and then solve problem or at first i should just try to solve it without any prior knowledge of the problem.
Sn00py_lark@reddit
https://www.edx.org/certificates/professional-certificate/gtx-data-structures-and-algorithms
https://runestone.academy/ns/books/published/pythonds/index.html
https://neetcode.io/practice/practice/blind75
https://www.coursera.org/specializations/algorithms
https://a.co/d/0jeFtfAn
This is approximately the track most CS majors end up doing. Or alternatively go through a leetcode style course. Like grokking.
itjustbegansql@reddit
Would you recommend a course or a book?
Sn00py_lark@reddit
I prefer books and doing exercises but videos and doing exercises is fine too. The books I mentioned are the kind you can just read start to finish which is sorta courselike (as opposed to algorithms CLRS which is as much a reference manual as progressive course)
FunAd6672@reddit
Leetcode mediums humbled me harder than any college exam ever did. Some of those mediums are straight up lies.
Individual-Brief1116@reddit
Good advice here already. I'd add this: treat it like building something properly at work. You don't jump into complex features without understanding the tools first. Learn one pattern thoroughly, solve 5-10 problems with it until you recognize it instantly, then move to the next. Pattern recognition is really the whole game with leetcode.
Select-Reporter5066@reddit
The trick is not memorizing every structure, it’s knowing what pain each one avoids. Big-O is basically the warning label.
esaule@reddit
Yeah, you don't do leet code to learn algorihtms and data structures.
Learn algorihtms and data structures first in isolation. Textbooks will have appropriate problems at the end of the chapters. Do those. Then solve your problem using your newly found knowledge.
Then look at random problems like leetcode and what not.
Ornery_Policy7718@reddit
One thing that helped a lot : separate the “learning” sessions from the “solving” sessions. When you’re learning a pattern, don’t try to solve hard problems. When you’re in solving mode, don’t stop to learn new concepts. Mixing both kills momentum. Also for Leetcode specifically — start with Easy problems on patterns you already studied, not random problems. The “random” button is a trap when you’re starting out.
Ordinary_Baseball518@reddit
You’re supposed to learn the data structure/algorithm first, then practice applying it through problems. Raw grinding LeetCode without understanding the patterns first just turns into frustration tbh. Almost everyone struggles at the start.
blechnapp@reddit
honestly for DSA the wrong way to learn is by throwing yourself at leetcode problems with no prep. you need the tools first, then the problems become practice instead of frustration.
what works for most people:
learn the patterns first, then practice. neetcode (neetcode.io) has a free roadmap that groups problems by pattern (two pointers, sliding window, BFS, dynamic programming etc). watch the short pattern explanation, then solve a handful of problems that use it.
for new problems, give yourself a hard time limit (most people use 20 to 45 min depending on difficulty). if youre stuck with no progress at that point, dont keep staring. read the solution, understand it line by line, close it, then re-implement from scratch. you learn way more from this than from another hour of staring at the screen.
pattern recognition is the actual skill. after a few dozen problems you start seeing "oh this is sliding window again" instantly, thats when leetcode stops being scary.
dont research data structures in isolation either. learn them inside problems that actually need them, they stick way better that way.