5 Things I Won't Tell You About Algorithms, Part I

Algorithms, Part I at Coursera by Princeton University would be the best online Algorithms course I’ve ever enrolled in. I highly recommend you to take a look, though there are 5 things I don’t want to - or at least hesitate to tell you about it.

I Gave Up Twice

It’s a shame to tell you that I’ve enrolled in this course more than once. I’ve enrolled to this course at 2014 first, then probably at 2016 I picked up it again. But I never finished it and usually, I stayed at Week 1, Course 1, Video 1.

It’s Dec 2018 already and I found I am still struggling with certain coding contests like leetcode weekly, I think it’s time to review and strengthen again.

The instructors of this course suggested 6 weeks of study, 6-10 hours per week, which is apparently affordable in time and workload. Then why I gave up previously twice? I am lack of patience and endurance. This is a course you need to devote yourself and won’t see any visible impact in a short time, but in long-term the reward is high - at least I believe.

So this time I set punishment like this if I gave up the 3rd time.

Don’t Copy My Code

To force myself to stick to the goal, I created a repository at GitHub to commit assignments I finished and track progress each week. Fortunately, I’ve finished two weeks’ task beforehand and I am still alive.

I would say that the assignments are very good for practicing purpose. You will apply what you have learned in the course and it’s also challenging. Usually, it says that it would cost you 5 hours to finish, but I found that to get a good score you would spend more hours than this.

I literally spent 8 hours on the first assignment Percolation and tried 6 times to get a good score, as I also enhanced the test methodology myself, which you can review the issue #64 I reported.

Try to resolve the problems yourself but in a reasonable time(I am not a student anymore and I don’t have that much time), if you are stuck for a long time you can search for some tips and insights, or go to the forum to see what the mentor replied there. Don’t copy my code man, but you can review them to get some ideas if you really need and want.

The online grade system is very impressive and I am thinking of introducing it into OIT courses I would teach in the future.

I Get Stuck Frequently

Yeah, don’t be upset. If you get stuck in the way, remember, there is a fool like me also get upset, depressed, angry, anxious, suspicious regularly. It’s very clear I don’t have much talent in this area, but hard works would still improve me somewhat.

Percolation Submission Date Score Passed?
December 21, 09:31 AM PST 100/100 Yes
December 20, 10:48 PM PST 93/100 Yes
December 20, 10:41 PM PST 81/100 Yes
December 20, 09:17 PM PST 79/100 No
December 20, 03:31 PM PST 79/100 No
December 20, 03:06 PM PST 52/100 No

The 5th submission passed and the score seems good enough, but actually, there is a bug which I cannot ignore, after resolving it I got a 100, but still the memory usage is not optimized well, which I plan to improve in the future.

I Got The Textbook

Slides of the lectures are good enough for reading purpose, but a thorough and systematical reading would still require a textbook. Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne provides

“essential information that
every serious programmer
needs to know about
algorithms and data structures”

So go and get it, DO NOT HESITATE!

Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne

My Unit TestCase Rocks

Honestly speaking, the unit test mentioned in the course are actually no unit test at all. Simply running main method and compare the result with expected result manually just sucks, I would shamelessly recommend you using JUnit or TestNG to do this. Feel free to use my test cases, they would save you a lot of time. For example, I’ve concluded all the tests provided by the instructor and integrated them into certain unit tests. You may like to check out PercolationTest.java to see whether I am a good, old, and young boy.

public void all() {
In in = new In(this.getClass().getResource("/percolation-test-cases.txt"));
int failed = 0;
while (!in.isEmpty()) {
String line = in.readLine();
String[] array = line.split(",");
Percolation perc = this.from(array[0]);

try {
assertEquals(perc.numberOfOpenSites(), Integer.parseInt(array[1]));
assertEquals(perc.percolates(), Boolean.parseBoolean(array[2]));
} catch (AssertionError e) {
// I want to know how many cases fail and the exact corresponding files
// You can simplify this if you just want to know the first failed case
System.err.println(line + " -> " + perc.numberOfOpenSites() + "," + perc.percolates());

if (failed > 0) {
throw new AssertionError(failed + " test cases failed!");

public void isFull() {
Percolation perc = new Percolation(3);
perc.open(1, 1);
perc.open(3, 1);
assertFalse(perc.isFull(3, 1));

perc.open(1, 3);
perc.open(3, 3);
assertFalse(perc.isFull(3, 3));

perc.open(2, 3);
assertTrue(perc.isFull(3, 3));
assertFalse(perc.isFull(3, 1));

Finally, if you have to purchase one and only one algorithm book and are still hesitating, then get Algorithms, 4th Edition first. Trust me, you will never regret.