For the problem:
Consider an insect in an M by N grid. The insect starts at the bottom left corner, (0, 0), and wants to end up at the top right corner, (M-1, N-1). The insect is only capable of moving right or up. Write a function paths that takes a grid length and width and returns the number of different paths the insect can take from the start to the goal.
For example, the 2 by 2 grid has a total of two ways for the insect to move from the start to the goal. For the 3 by 3 grid, the insect has 6 diferent paths (only 3 are shown above).
Below is the recursive solution:
package main
import "fmt"
func paths(m, n int) int {
var traverse func(int, int) int
traverse = func(x, y int) int {
if x >= m || y >= n {
return 0
}
if x == m-1 && y == n-1 {
return 1
}
return traverse(x+1, y) + traverse(x, y+1)
}
return traverse(0, 0)
}
func main() {
fmt.Println(paths(1, 157))
}
As N increases, below is the effect:
fmt.Println(paths(1, 1)) // 1
fmt.Println(paths(2, 2)) // 2
fmt.Println(paths(3, 3)) // 6
fmt.Println(paths(4, 4)) // 20
fmt.Println(paths(5, 5)) // 70
fmt.Println(paths(6, 6)) // 252
fmt.Println(paths(7, 7)) // 924
Memoization can be applied in fibonacci problem, to reuse previous computations, using tree recursion
Does it make sense to memoiz this path problem? to reuse previous computations
(Note: this problem is meant to apply the idea of tree recursion, as mentioned here.)

big.NewInt(0).Binomial(M+N-2, M-1))paths(3,3)is 3 but not 6? I see 6 paths.