Thursday, August 4, 2016

ITINT5: tree maximum path sum (II)

August 4, 2016

Blog 1: July 6, 2015
http://juliachencoding.blogspot.ca/2015/07/itint5-tree-maximum-path-sum.html

First writing in C# (July 6, 2015)
https://gist.github.com/jianminchen/754d29e47c491cfc271f764fb5dd8a61

Review comments (August 4, 2016, after 13 months):
1. first, the input argument res - variable name - not accurate - res should be maxValueCrossRoot
2. function name: maxTreePathSumRe is confusing, will be better called "maxTreePathSumEndByRoot"
3. line 121, 122 can be merged into one line statement - easy to read 
4. add some design spec for the function - maxTreePathSumRe

Blog 2: August 4, 2016
C# code practice: 2nd writing
https://gist.github.com/jianminchen/c9be400e7bee71734ee7c454635846cf

review comments:
1. Line 138 - 150, function ArrayMaximum
No need, call Array.Max();

3rd writing:
https://gist.github.com/jianminchen/3b2c8e0e84e52cbca2a7ec435b29a2e4

highlight of changes:
1. line 124, use Array.Max(), remove the function: ArrayMaximum(int[])

Use Language Integrated Query (LINQ) - Array.Max(), detail see the blog:
http://juliachencoding.blogspot.ca/2016/06/array-class-c-c-javascript-java.html

LINQ - Enumerable Methods Reference:
https://msdn.microsoft.com/en-us/library/bb342261(v=vs.100).aspx

Blogs to read:
Choose topic: extended merge sort
Algorithm: count inversions

count inversions - extended merge sort
1. http://jane4532.blogspot.ca/2013/06/zz-google-onsite-interview.html
2. http://www.geeksforgeeks.org/counting-inversions/
3. http://www.cs.umd.edu/class/fall2009/cmsc451/lectures/Lec08-inversions.pdf
4. https://www.cp.eng.chula.ac.th/~piak/teaching/algo/algo2008/count-inv.htm


No comments:

Post a Comment