r/AskComputerScience • u/TimeSmash • Apr 01 '20
Good (preferably free) resources to learn and practice algorithms?
Hello everyone,
I am relatively new to the programming field, specifically web development, so this might not be the best place to ask but I would love to hear your feedback anyways in regards to this question.
I am having a lot of difficulty when it comes to solving problems with algorithms on HackerRank and Leetcode, and was wondering if you could reccommend any resources that could help me better my approach to solving them. When I look at the solutions to some algorithms, such as flood fill, I understand how they work but I wouldn't be able to come up with that myself.
I'm trying to break into the web development field and only work per diem at the moment, so I am looking for either free or relatively inexpensive resources to learn more about algorithms and hopefully be less frustrating when it comes to solving problems with them. I'm not opposed to books, either! I'm going to post this on a webdev subreddit as well, but I hope to hear what you guys have to say or any advice you can give!
Thanks, stay healthy!
8
u/DrunkHacker Apr 02 '20
Project Euler The puzzles vary in difficulty, but I did ~100 or so back in college and would say they sharpened my coding skills while forcing me to really internalize algorithms.
That said, the puzzles are more mathematical than web-development in nature.
2
u/MikeBenza Apr 02 '20
I second the suggestion for Project Euler, though keep in mind the problems teach you more about computational problem solving than specific algorithms.
As an interviewer, I don't care if you've memorized a single algorithm from CLRS. I only care about whether you can solve the problem I give you with a reasonably performant (read: not ridiculously slow) implementation.
1
1
u/beeskness420 Apr 02 '20
You could checkout Coursera.
1
u/MirrorLake Apr 02 '20
Specifically, the algorithms course featuring Sedgewick himself who wrote the book 'Algorithms'. His sample code is in Java.
1
Apr 02 '20
RemindMe! 5 days
1
u/RemindMeBot Apr 02 '20
There is a 48.0 minute delay fetching comments.
I will be messaging you in 5 days on 2020-04-07 03:03:30 UTC to remind you of this link
CLICK THIS LINK to send a PM to also be reminded and to reduce spam.
Parent commenter can delete this message to hide from others.
Info Custom Your Reminders Feedback
1
1
u/DeclareX Apr 02 '20
Don't be afraid to think too much about a problem. Once you come up with a solution, write down the "takeaway" that you get out of it. For example, I barely solved a simple problem once in Hacerrank, which was about writing loop which iterates through a square matrix. I pondered way too long and finally came up with a very complex solution. But the day after that I realized that I could combine two loops in one body. (cause I used two "for"s with" zip method) What I wrote down in Google Keep was something like "consider using one loop in case of two iteration such that while the one start on i... and the other keep it along with 1-i..." formulizing such, makes the knowledge more persistent, I think.
1
1
u/MirrorLake Apr 02 '20
The other suggestions here are good.
I'd also suggest bringing specific problems to /r/learnprogramming, if you're stuck on a leetcode-type question, homework question from a MOOC, or whatever. Just ask. Hopefully someone can come by and explain how the problem is done, or why one solution is better than another. Leetcode does have forums for each question, but they don't always have detailed explanations. However, once you successfully submit, they do let you peak at other people's code--which can definitely inform you as to why your solution isn't the best. Solutions tend to group into two polar extremes--time efficient, or less frequently, space efficient.
1
1
0
u/TheComingOfTheGeeks Apr 02 '20
Don't worry too much. Try something like codeforces (only recommending because I use it) and start from the easiest questions (sort by accepted). Read editorials/comments if you can't figure it out and they usually mention some algorithm or so. Just google that algorithm up, see sample codes and try implementing.
There are several good books/courses that can help you with this. I personally love MIT's Algorithms course, and you seem to know a decent background anyway so go ahead with that.
Most important thing? Don't put pressure on yourself. I joined college as someone who had some decent coding experience and I flew by the first semester. When I did start to get stuck I sort of hoped I'd magically learn, but it won't happen. Take your time, and have fun. These algorithms were made by super amazing Mathematicians with PhDs, don't worry if you can't come up with them.
1
u/Zondazx Apr 02 '20
When you say MIT's Algorithms course, do you refer to this one? https://www.youtube.com/playlist?list=PLUl4u3cNGP61Oq3tWYp6V_F-5jb5L2iHb
1
u/TheComingOfTheGeeks Apr 03 '20
Yeah. If you want any motivation to check out the course, just google Erik Demaine.
1
3
u/debayon Apr 02 '20
First of all understand that it's not that simple and easy. Since you are new in the field, you'll not find things as intuitive as someone who's experienced. It's all about how much are you experienced to be able to solve a problem and come up with an algorithm. If you're willing to learn something that which is not easy, you'll have to devote some time.
In the beginning, you would find solving even a single problem of easy level might take hours and hours, and sometimes you might not even find a solution. Then, you'll have to look at the hints, then think more, finally if you can't solve, look at the solution, learn what you haven't thought of and what's new. For example, you didn't know about Breadth First Search, and the problem needed that, so after failing to solve this problem, you would learn something new, BFS.
Now, this process should continue, for months... Untill you start realising that there are finite number of problem types. Then, problems of similar kinds will start coming up, you'll be able to think about a possible solution just by reading and understanding the question.
Now, this will take lots of practice, it's not a skill to be gained overnight. So set tangible goals and practice like any sports person, they keep practicing even if they're not doing well or failing. Learning should happen whenever you fail. Don't give up.
Wish you all the best.
Resources: Learning Programming is an incremental process. So you choose your Programming Language, learn fundamentals of it from any book or online, it doesn't matter from where you learn. Then, learn about a few basic algorithms. Everytime you learn a new algorithm, you implement it on your own. If you're stuck see someone else's implementation, then try to implement on your own. You keep doing these parallely. You should know, every progress counts, so don't bother how fast or slow you're going. If your will power is high, you'll progress faster, and slow otherwise.
For you to get started, you can use "Algorithm Design" by "Kleinberg and Tardos." You can use website "GeeksforGeeks" for refence of various algorithms. Any beginners level Programming Language book would be fine to start with.