Tag Archives: algorithm

Triangle

http://oj.leetcode.com/problems/triangle/ The problem statement is deceptive by mentioning path from “top” to “bottom”. I was fooled at first and tried to compare all the ways from the top to the bottoms. However, it is impractical since there are O(2^(n-1)) such … Continue reading

Posted in Computer Science, LeetCode | Tagged , , , | Leave a comment

Sum Root to Leaf Numbers

http://oj.leetcode.com/problems/sum-root-to-leaf-numbers/ Another problem from Leetcode that I came up with two different solutions. The first solution idea is to get paths from root to leaves first, compute the sum later. Those paths can be easily discovered by depth first search, … Continue reading

Posted in Computer Science, LeetCode | Tagged , , , , | Leave a comment

Dijkstra’s Algorithm

2014/3/5: How stupid I was for not recognizing Dijkstra as a special case of A* without heuristic cost. It makes the algorithm much easier to understand and implement. We only need to consider vertices as states and put them to … Continue reading

Posted in Algorithms, Computer Science | Tagged , , , , , | Leave a comment