Saturday, December 16, 2017

Dynamic programming should be daily practice

Dec. 16, 2017

Introduction


It is hard to get used to write bug-free code for dynamic programming. Specially base case handling.

Here is C# code I practiced on Dec. 16, 2017 10:00 AM. The code I wrote had a bug to handle the array with length 1, the product should be 0 instead of 1.

Feelings


This practice I felt much better. First I read the problem statement loud, and then I spent over 5 minutes to go over the test case, and explained the brute force solution and its time complexity. And then go to optimal one, how to apply the two linear scan integrated with left neighbor or right neighbor products with one more multiplication.

First try to explain very clearly the idea, and then it is very easy to write the code just following the idea.

I have practiced this algorithm more than 4 times since March, 2017. I still made an error on edge case. I just added tags for all past practice using Leetcode 238: product of array except itself, so I can easy go over the past practices and review them.


Get organized


It is most important task to get organized, review every practice in one setting. So I can figure out how I develop good understanding of the problem through each mistake, and also get some ideas what to work on next.

Source code is the key information to document how good/ not good I am in terms of algorithm analysis, coding style, and also whiteboard testing.


March 21, 2016, here is the blog about the practice.

Oct. 29, 2017, here is the blog about the practice.

Dec. 16, 2017 practice is Here.

No comments:

Post a Comment