Study again the back tracking algorithm using recursive solution, rat in maze, a classical problem. Made a few of mistakes through the practice, one is how to use two dimension array, another one is that "not all return path returns value", not so confident that "return false" at the end of function.
重温二年前做过的算法题, Rat in Maze, 为自己惭愧! 二年前的练习, 没有任何的参考网页信息, 也没有算法讨论, 尝试改进. 感觉到自己的差距, 这次练习, 着重强调把算法能背出来. 一步一步写出来, 发现几个错误. 二维数组不熟悉, 耽误了十几分钟; 另外, 就是, "return false" 在递归函数最后一句, 先是忘了. 总之, 这个经典题目, 十分钟写不出来; 需要二个数组, 边界条件检测, 一点印象没有.
Here are my favorite blogs about this problem:
1. http://www.geeksforgeeks.org/backttracking-set-2-rat-in-a-maze/
2. http://algorithms.tutorialhorizon.com/backtracking-rat-in-a-maze-puzzle/
3. https://www.cs.bu.edu/teaching/alg/maze/
Julia's C# pratice:
https://github.com/jianminchen/AlgorithmsPractice/blob/master/RatInAMaze_BackTracking.cs
And then, try to find more discussion about this problem, came cross blogs to challenge my analysis skills. 搜一下Google, 找到一个很有深度的网页, 看了以后, 体验一下代码, 感觉比自己的水平高了几个档次.
http://blogs.msdn.com/b/mattwar/archive/2005/02/03/366498.aspx
http://blogs.msdn.com/b/mattwar/archive/2005/02/11/371274.aspx
More code to read and then play:
http://www.evercrest.com/ext/CheeseAppropriator.cs
and C# practice:
https://github.com/jianminchen/AlgorithmsPractice/blob/master/MousingAround.cs
January 10, 2016
Review the algorithm
No comments:
Post a Comment