Saturday, December 23, 2017

Code review: At least 2 paths down the binary tree have the same sum

Dec. 23, 2017

Introduction


It is my most favorite algorithm in the world in June 2016. I had to go through the transition to accept myself as a software programmer, and learn how to improve myself through this simple algorithm. I did the practice and then stopped without writing an optimal solution in June 2016. Now after more than 12 months, I know that at the time I do not have high standards on practice at all.

Here is the algorithm I practice in June 2016.

I reviewed the code on Dec. 23, 2017 and asked the question on code review website. Here is the code review web link.

June 2016


It is tough to deal with frustration, what I did is to write a blog to study the failure on June 5, 2016. I was so excited to go over one day meeting with the most highest standard software company. And then I experienced so many issues through meetings. One thing is that I did not perform very well on the similar algorithm using C# LINQ.

Add one more paragraph


One thing I like to do is to add one more paragraph on the code review. Since I do not get any upvote after 24 hours, so I like to step out and do something to help myself.

Here is the paragraph:

Code improvements
I decided to make a few improvements based on my last practice over 18 months ago. Internal class is used instead of external class. I choose to use camel case for public method, and rename the function DuplicateCheckingPathSum to make the function name self-documenting. Specially I took 10 - 20 minutes to go over those stackoverflow links to learn LINQ and also ASP.NET C# class and I found that those links are really helpful for me to warm up LINQ. It is tough for me to see that after 18 months I still do not make big progress on LINQ and the functional programming syntax still looks like foreigners to me.
Most of important change is that I learn better recursive function design after 18 months. I was surprised that I ended my last practice with so many issues. The base case should be selected to avoid duplicated count of each path. I like to see the depth first search algorithm specially a recursive function is written in very structured way, base case is very clear and also the recurrence formula afterwards.

Follow up 



Dec. 25, 2017
Early in the morning I got code review, and I was so excited to read the review. Here is the link of code review.



No comments:

Post a Comment