![]() |
VOOZH | about |
In mathematics, a D describes the number of paths from the southwest corner (0, 0) of a rectangular grid to the northeast corner (m, n), using only single steps north, northeast, or east.
For Example, D(3, 3) equals 63.
Delannoy Number can be calculated by:
Delannoy number can be used to find:
Examples :
Input : n = 3, m = 3
Output : 63
Input : n = 4, m = 5
Output : 681
Below is the implementation of finding Delannoy Number:
129
Below is the Dynamic Programming program to find nth Delannoy Number:
129
Time complexity: O(m*n)
space complexity: O(n*m)
Efficient approach: Space optimization
In previous approach the current value dp[i][j] is only depend upon the current and previous row values of DP. So to optimize the space complexity we use a single 1D array to store the computations.
Implementation steps:
Implementation:
129
Time complexity: O(m*n)
Auxiliary space: O(n)