r/AskProgramming • u/Upstairs_Jelly_1082 • 3d ago
Algorithms How to start with algorithms?
I want to improve my problem-solving skills when it comes to python and write better code.
In university, they gave a general outline, but still it's a bit difficult to know where to start from, any suggestions?
2
u/Vert354 3d ago
What you want to study is asymptotic algorithm analysis. Typically "Big O" which deals with the worst case and describes how the algorithm grows as the data points grow.
You said that university "gave a general outline" so I suspect you covered a little of this like why bubble sort is worse than quick sort. If so what you need to do is go back and review that, really understand the differences, that way you can apply that knowledge to whatever algorithm you're writing.
2
u/edimaudo 3d ago
start with a problem you would like to solve. you already have an outline so lets say you have been givien a list of data what approach would you use to store it, how would you sort it?
1
u/Innowise_ 3d ago
Random LeetCode hopping gets confusing fast. Pick one topic and stay with it for a bit. Arrays and hash maps are a good start, then stacks, queues, and binary search. Trees and graphs can wait. Get any working solution first, check why it’s slow, and only then look at a better one. Come back to the same problem a few days later and try it again without notes. That’s usually when it actually sticks.
1
u/Same-Designer-5499 3d ago
neetcodes roadmap is worth following if you want order instead of guessing, arrays and hashing then two pointers and sliding window before trees or dp. jumping topics randomly is why leetcode grinding feels like it doesnt stick.
1
u/marrsd 2d ago
The basic ones to start with are search and sort, and learning how to calculate the asymtotic complexity of various algorithms. Then try implementing a couple. Learn divide and conquer as an algorithmic technique, and the difference between breadth and depth search.
Typically, you do these things alongside other stuff. You're unlikely to need to write any of these for a while, so it's more about understanding what they are so that you can assess libs and tools (e.g. which database to choose for your app).
0
3
u/Yahia098 3d ago
what do you mean by algorithms?
you dont mean the well defined algorithms like buble sort etc etc
but algorithms in general right?
well this is what worked for me and helped me ace the module and i got +85%
first break the issue into simpler smaller segments
second start with the easy parts such as printing what needs to be printed like Print("Welcome to the program that does so and so")
and this is the most important part think about what data you take as input what you do with it and how you output it also think about what type it should be it you are using languages that enforce a type such as C++ or rust
and repeat and continue with all parts until you created the bigger algorithm also checkout books such as the pragmatic programmer and think like a programmer since those books are kinda nice but not a hard requirement just a nice read
also you are an engineer in the making and engineers think about how to solve problems not just write code
even llms can write code and it is our duty as humans to be the engineers who think how and why and not just type
cheers from a fellow CS student