Add Unique Paths algorithm in R#205
Add Unique Paths algorithm in R#205Siddhram wants to merge 1 commit intoTheAlgorithms:masterfrom Siddhram:add-unique_paths
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds a comprehensive implementation of the Unique Paths algorithm to the dynamic programming module, providing multiple solution approaches for counting paths in a grid with movement restrictions.
- Implementation of three distinct algorithms: tabulation DP, space-optimized DP, and top-down memoization
- Addition of obstacle handling variant for blocked grid cells
- Comprehensive testing and performance comparison functionality
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| dynamic_programming/unique_paths.r | New implementation with four different approaches to solve the unique paths problem, including comprehensive documentation and test cases |
| DIRECTORY.md | Updated to include the new unique paths algorithm entry and reformatted list structure from bullet points to dashes |
| - [1 Knapsack Problem](https://github.com/TheAlgorithms/R/blob/HEAD/dynamic_programming/0/0/1_knapsack_problem.r) | ||
| - [1 Knapsack Problem](https://github.com/TheAlgorithms/R/blob/HEAD/dynamic_programming/0/1_knapsack_problem.r) | ||
| - [Coin Change](https://github.com/TheAlgorithms/R/blob/HEAD/dynamic_programming/coin_change.r) | ||
| - [Minimum Path Sum](https://github.com/TheAlgorithms/R/blob/HEAD/dynamic_programming/minimum_path_sum.r) |
There was a problem hiding this comment.
This entry appears to reference a file that was not added in this PR. If this is a new algorithm being added, the corresponding implementation file should be included, or this entry should be removed if it was added in error.
| - [Minimum Path Sum](https://github.com/TheAlgorithms/R/blob/HEAD/dynamic_programming/minimum_path_sum.r) |
| * [Shortest.Common.Supersequence](https://github.com/TheAlgorithms/R/blob/HEAD/string_manipulation/shortest.common.supersequence.r) | ||
| * [Unique.Letters.Count](https://github.com/TheAlgorithms/R/blob/HEAD/string_manipulation/unique.letters.count.r) | ||
|
|
||
| - [Burrows](https://github.com/TheAlgorithms/R/blob/HEAD/string_manipulation/burrows.r) |
There was a problem hiding this comment.
Why did you change the formatting? The list is sometimes automatically generated, so you shouldn't change formatting manually
|
We do not add Leetcode problems |
This PR introduces a complete and well-documented implementation of the Unique Paths problem in R using a top-down dynamic programming (recursion with memoization) approach.
Overview
The Unique Paths algorithm computes the number of distinct paths to reach the bottom-right corner of a grid from the top-left corner. Movement is restricted to right or down directions, and some cells may be blocked.
The algorithm uses recursion with memoization to avoid redundant computations and efficiently calculates the number of valid paths.
Features
Complexity
Time complexity (TC): O(m · n) — each cell is computed at most once.
Space complexity (SC):
Demonstration
Run the following examples in an R session: