### Learn Algorithms, Part I

#### Hacker News Comments about Learn Algorithms, Part I

*All the comments and stories posted to Hacker News that reference this course.*

This was a homework assignment in Robert Sedgewick's Algorithms course on Coursera!

https://www.coursera.org/learn/algorithms-part1

Great class and fun assignment!

⬐ fizwhizWasn't the first assignment about detecting percolation using the union find datastructure? IIRC, sedgwick's class doesn't cover dynamic programming directly at all.

⬐ ChickenosaurusSeam carving is the second assignment of Algorithms Part II. I also highly recommend Princeton's Algorithms course on Coursera.

⬐ fizwhizAh, I haven't taken Part II of the course. Probably not a bad idea to start :)

For more on percolation, the first exercise in this course is pretty cool:

> I wonder if there are similar courses on CS algorithms for people who didn't study CS in college.

This might be a bit more challenging and less hand holding than the nand2tetris course but if you are up for it, why not go with the best? Sedgewick Algorithm book has been one of the standard algorithm books in universities for a long time.

https://algs4.cs.princeton.edu/home/

⬐ volkischQuestion: Why not CLRS instead of Sedgewick's book/course?

If you prefer watching videos/working through a MOOC for this stuff, I can highly recommend Robert Sedgewick's Algorithms I on Coursera: https://www.coursera.org/learn/algorithms-part1

If you don't know his name, you should - he's written some of the best books on these algorithms and his MOOC is similarly rich in visualizations and concrete examples that help you develop the intuition for the algorithms. Also incidentally his doctoral advisor was Donald Knuth, who he evidently learned a lot from.

maybe take a look how he teaches: https://www.coursera.org/learn/algorithms-part1

Good for you young jedi. I started coding around that age as well. I made the mistake of not going through comp-sci but have still been able to work for Google, publish books, lead teams and companies and products. You'll do just fine.

You have the ability to write some code! If you want to get a jumpstart, you should take the princeton algorithms course (for free!): https://www.coursera.org/learn/algorithms-part1

Or read the textbook by sedgewick that accompanies the course. https://algs4.cs.princeton.edu/home/

There is very little math in there - it may take some elbow grease and mentorship to help to convey some of the ideas - but I believe that you could implement and solve most everything in there. That was my path - I had a teacher at the age of 14 who would explain to me how different algorithms worked and I would go and implement them. Drawing a circle (in memory - it was in C!) or sorting a list (we did bubblesort first IIRC!)

I think you could do it! I believe in you! The course material is approachable - much more so than basically every other algorithms/data-structures material I've found. it may take you some time but you'll be soooo far ahead with your thinking about code.

If you ever start working with Object oriented languages like Java, another book that may help you when you've gone down the road a bit is the Head First Design Patterns book. http://shop.oreilly.com/product/9780596007126.do It's very easy to read, mostly pictures. It is made to be very easy to read (all of the books in that series are so look around at them.)

It's helpful to do both - code and also take in some material, but at 12 I imagine some of the material may be a bit daunting. You're doing really well - keep it up.

> If you come up with a fast sorting algorithm how would you go about making a case it's faster than currently used ones on real world data?

For analysing sorting algorithms - and related things which that leads into - there are established ways to determine their best, average, and worst case runtimes for input of a given size.

If you're interested in learning this stuff, the video's here are useful and not math heavy:

https://www.coursera.org/learn/algorithms-part1

Technically it's explained using java. But it's mostly done using primitive data types (eg int, float, byte, ...).

So it's very easy to follow along and copy the implementation, but translated to a different language (Go in my case, as I don't do java at all).

Interviewing is its own skill!! To get into eg Google you have to go through the rites of passage of learning to interview. That's not true of all positions. I give take-away assignments now. I want to see you can turn in good code. That's all I really care about. How you get there doesn't matter, your decisions do.

The Golden Rule: When in doubt, use a hashmap. Almost all code challenges are about finding an algorithm or datastructure to fit the problem/solution. Many of them are solvable efficiently via a hashmap.

Preparation

- Practice on a whiteboard

- Do mock interviews with the most skilled people you can find and get feedback! This is critical to glean any information about how you're actually doing! I could volunteer to do that for you remotely if you like. Send me your contact info. I'm a distributed systems guy but could walk you through some problems and tell you how you're doing with whatever you're using for tech very likely still. Drop a note on how to connect if you're comfortable.

- Take an algorithms course before you interview. (The princeton sedgewick one is great and easy to grokk. see coursera: https://www.coursera.org/learn/algorithms-part1 )

During:

- Write tests for your code during the interview to demonstrate production quality code.

Especially if interviewing for eg Google. They don't give super tricky problems in every interviews (eg during phone screen) - focus on writing good code that is tested and will compile and run after the interview, not writing mediocre code fast.

- It's okay to incrementally improve your solution. Talk through your thinking. Start at the naive solution and then work toward optimal. Eg give two lists, find any number from list a sums to any number from list b. To start, you could write a couple quick tests on the board to make sure you understand the problem. Then you could reason about solutions - say you could use nested for loops. That's O(n squared) which isn't suitable as a solution. So you ask if the data is sorted. If they say no, you can sort lists, iterate through one and binary search on the larger list to get to an asymptotically linearithmic solution. That's suitable so you write that fairly swiftly. To improve you discover you only need to sort one list so you change the solution to only sort the larger one and iterate through the smaller. If there is extra time you might start to reason about how you can move toward a linear solution. Remember I said the golden rule is use a hashmap? Why don't you make a hashmap out of one of the lists and iterate through the other one to find values in the map? Don't just sit there and take it away to the corner and try to solve it.

God Mode: - WAYYYY before you take the interview: Stop using an IDE at work if you're working in a statically typed language. Use emacs, or vscode or whatever you fancy. Moving to emacs made my brain learn the qualities of the language at an intimate level faster than anything else. You check the docs if you forget the api until you stop forgetting the API. It slows you down a bit at first so it's an investment but whatever - tack 25% on your estimates for a few weeks. You can revert to the IDE for larger refactoring work.

https://www.coursera.org/learn/algorithms-part1

The princeton one on coursera is really great and easy to read. Buy the book and take the course. Sedgewick is my hero. It doesn't require a lot of math in contrast to the Stanford coursera one. It's much easier for the general person to follow IMO. https://www.coursera.org/learn/algorithms-part1

Focusing on a limited set of resources in a way that exercises your problem-solving skills would be the key. Here is one plan:

1) Select a category such as "stacks and queues" from the Cracking coding interview (CCI) book and read all the questions. This will give you a sense of the type of questions being asked.

2) Sign up for the algorithms 1 and 2 courses ( https://www.coursera.org/learn/algorithms-part1 , https://www.coursera.org/learn/algorithms-part2 ) in the audit mode(free). Pick the correct modules such as "stacks" and "queues" and watch all the videos.

3) Come back to the questions in the book CCI and try to solve the problems yourself. If you get stuck, look at the solutions for hints but still try to do them yourself.

4) Do the same for all major topics such as strings, linked lists, recursion etc.

Unfortunately, you are not going to remember all of you've learned. You need spaced-repetition so repeat the above method 2-3 times for each topic.

Once you have the foundation, you will be able to tackle the harder questions that you may find somewhere else or in the interview.

I've used sites like these when I am stuck with a problem and I would like a hint. But learning the theory is important. The resources I've used recently to train myself are:

- Competitive programmer's handbook: https://cses.fi/book.html

- InterviewBit: https://www.interviewbit.com/

- Sedgewick's DS&A course/book https://www.coursera.org/learn/algorithms-part1 http://algs4.cs.princeton.edu/home/

A similar site, with C++ using [some] STL can be found here: http://www.techiedelight.com/data-structures-and-algorithms-...

⬐ JareTechiedelight is a cesspool site which tries to send notifications to your browser, disables selection, copy & paste, and even tries to hide the context menu. God I hate these sites.

On the other hand, the Competitive Handbook is pretty entertaining.

⬐ jared123why do u want to copy anything?? u can directly run the code or download the code if you want.. and every website try to push notifications nowdays.. even google. what's wrong in that?? You can simply refuse it if you're not interested. And disabling these functions helps in preventing plagiarism.

Good advice! I have an older version, in which the implementations are explained in Pascal. I understand that newer issues cover java. I'd believe the book goes well with his coursera course:

Robert Sedgewick's course [1] and associated book/booksite [2] have a good overview of Union-Find problem and various algorithms to solve it.

⬐ ApocryphonIndeed, Union-Find is the first subject the course covers, because it uses it as an example of an elementary algorithm.

The Coursera Stanford [0] and Princeton [1] courses start again soon, February 20 to be exact. Not sure which one is better, but to refresh my atrophied CS skills of 10 years I've joined the Stanford course. Not sure how it compares to the Khan Algorithms course. Anyone have any feedback?

[0] https://www.coursera.org/learn/algorithm-design-analysis/

⬐ bootloadEdX as well,

- 6-00-1x https://www.edx.org/course/introduction-computer-science-mit... (started)

- 6.00.2x https://www.edx.org/course/introduction-computational-thinki... (March)

All are good and are pitched at various levels of complexity. The Princeton course uses Java. Okay if you're into that sort of language/thinking. MIT is using Python. Found one using lisp, "Systematic Program Design" ~ https://www.edx.org/xseries/how-code-systematic-program-desi...

⬐ imakecommentsThis is just my opinion and I'm sure it differs from others...

Roughgarden's class is advance and expects mathematical maturity. You may find his course quite fast and rough if you are a beginner.

Sedgwick's class is much easier. He is a bit boring and tries to use "real life" examples (in some instances) from the physical sciences to make the material relatable. This in my opinion detracts from the material. Also, he doesn't always fully explain where he got some of the big ohs here and there.

My advice? Follow MIT's OCW course (it uses CLRS). Supplement it with Algorithms Unlocked, the Khan Academy link in OP and CLRS. If you use those 4 resources and put in the work you'll understand the material.

All 4 sources have Thomas C's DNA touch to it (he is the C in CLRS). So you'll find it consistent when you read from one source to the other. After reading/hearing the same thing about 4 different times in 4 different ways it'll begin to click.

Order of easiness is probably Khan Academy > Algorithms Unlocked > MIT Algorithms Course > CLRS.

Algorithms Unlocked is like "pre-CLRS" and Khan Academy's version is the TL;DR version of Algorithms Unlocked.

Hope this helps.

Below are the links,

https://www.amazon.com/Algorithms-Unlocked-Press-Thomas-Corm...

https://www.amazon.com/Introduction-Algorithms-3rd-MIT-Press...

https://www.khanacademy.org/computing/computer-science/algor...

https://ocw.mit.edu/courses/electrical-engineering-and-compu...

⬐ zumu> Order of easiness is probably Khan Academy > Algorithms Unlocked > MIT Algorithms Course > CLRS.

Where does Roughgarden's course fit in to this?

⬐ augusto2112I'm going through Sedgewick's class right now. Is the MIT OCW's course math heavy? It lists "Mathematics for Computer Scientists" as a prerequisite, I am somewhat familiar with the material, but not in a very deep level. Should I take that one before?

⬐ Cursuviam⬐ 40acresThe main aspects from Mathematics for Computer Scientists that it assumes is knowledge of asymptotic complexity (O(n)) and basic proof writing skills.

Great post, thanks for the resources.

I find there are a lot of online resources for those looking to learn algorithms and data structures but I've had trouble finding the same breadth and depth of resources surrounding the math behind CS (discrete math, probability, etc.). Any suggestions?

⬐ imakecomments⬐ b3b0pRead "Discrete Mathematics" by Epp. Probably the easiest Discrete Math intro I came across.

Great feedback and insight. Appreciated. I'll checkout the MIT OCW and Khan Academy first. I'm hardly a beginner, but my skills feel a bit rusty and want to refresh them.

⬐ imakecomments⬐ sua_3000No problem.

I've taken both Stanford's and Princetons Coursera courses, and powered through the MIT OCW, and I would say this evaluation is spot on.

If you have to pick only one go with the MIT OCW, and snag a copy of CLRS. I got mine from my local lib. and it gave me more than enough time to work through the problem sets from the mooc.

⬐ dwdzAny particular reason that you linked MIT course from 2005 instead newer version from 2015?

Here is Princeton's Algorithm text I've found useful (The code is in JAVA though): http://algs4.cs.princeton.edu/home/

Pair this up with this excellent lecture by the authors Sedgewick and Wayne: https://www.coursera.org/learn/algorithms-part1/home/welcome