r/AskComputerScience • • Nov 06 '24
How did you guys get so good at algorithms?
I really don't get how some people can just pick up algorithms like it's nothing
I'm in this algorithms and design class and its absolutely fucking me up. Trying to come up with recurrence relations, find out amortized costs using potential functions, and then needing to come up with a proof for everything too...
I can understand the algorithms like Knapsack and Bellman-Ford etc. when they're explained to me, but when it comes to deriving something original using these algorithms as a base, I'm just completely lost. Looking at our posted solutions to said problems as well just adds to my confusion. Maybe I just need more practice, but it just feels so damn defeating to constantly be losing at this
If anyone out there is nutty with algorithms and proofs, how did you guys get so good? How do you think? Are there any good resources out there for this ?
Sorry if this kind of post isn't welcome here, I just wanted to let out little bit of steam
15
u/[deleted] Nov 06 '24
Practice.
6
u/1544756405 Nov 06 '24
I don't know anyone who picked it up like it was "nothing." Everyone I know who got good worked hard.
4
u/HariTerra Nov 06 '24
I assume it's like learning a musical instrument. Seems bizarre and complicated at first, but with enough practice, it becomes intuitive.
1
u/khedoros Nov 06 '24
Doing my classwork, then doing a few dozen practice problems in a competitive environment (i.e. one of the professors hosted monthly programming contests), that I'd discuss with classmates/competitors when we were done.
And I still periodically do runs of Leetcode problems, since so many places have some kind of coding test as part of their interviewing process.
3
u/MagicalPizza21 Nov 06 '24
As a student you'll likely need to learn to recognize patterns more than coming up with truly original algorithms.
1
u/BlobbyMcBlobber Nov 06 '24
Some people have a talent for it, but eventually anyone can understand algorithms, just work on it.
1
u/apendleton Nov 06 '24
A lot of it is just that you build up a mental map over time of general classes of problems, and a set of tools that are appropriate for each class, and when you encounter a new problem, you sort of slot it into one of the mental buckets and apply the things you know to try. So like, this problem feels well-suited to a divide-and-conquer approach, this problem can be modeled as a graph traversal and I know these ways to do one of those, etc.
Outside of class, proofs don't matter unless your goal is academia. In industry, at least in my experience, understanding the complexity in broad terms of different approaches is important because it guides you to the kinds of approaches that are most likely to be most successful when trying to make a slow thing faster, but ultimately you probably only really care about wall-clock runtime, and if your idea is faster when run on real hardware with real datasets or whatnot, what the provable big-O is just isn't that important. Knowing on a gut level like, this is roughly linear, this is roughly logarithmic, this is roughly logarithmic, etc., is fine.
1
u/Big_Minute_9184 Nov 06 '24
Practice, practice, and practice. Do it as much as possible. Also, rest when necessary. I have worked in the industry for 15+ years and repeat algorithms every year. Companies usually ask questions about widely known algorithms. No one will ask you to create a new one in an interview.
1
u/Cybyss Nov 06 '24 edited Nov 06 '24
Practice.
It's like learning algebra. You spend three years on it in junior high & high school. It can sometimes be a difficult class where you feel overwhelmed by the sheer amount of information. When it finally all clicks, however, that's when you realize it's only about a week's worth of real information and you just spent three years applying the same tricks over and over in different ways to new problems.
Algorithms - at least at the undergraduate level / the skills you need for solving LeetCode exercises - are the same way.
1
u/Several_Shake_3606 Nov 06 '24
First, take solved algorithms try to break down the complex algorithms/problems into pieces. Understand each step.
Try to memorize the steps and write them down in your own words without altering the original meaning. As far as I have studied, every algorithm has a core part, and the remaining steps are just the critical parts. So, focus on the core part.
There are levels/complexity of algorithms. I think most people like you and myself get stuck in deriving new algorithms. It requires experience, practice and investigation. That depends upon what level of complexity is your problem? What problem are you trying to solve?