Add House Robber dynamic programming algorithm in R #210
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a complete and well-documented implementation of the House Robber problem in R.
Overview
The implementation provides solutions for maximizing the amount of money that can be robbed from a row of houses without alerting the police. It includes a space-optimized O(1) DP approach that tracks only two rolling states and an optional tabulation variant for clarity, along with embedded examples.
Features
For each house
i
:take = nums[i] + prev2
(rob current, skip previous)notTake = prev1
(skip current)curr = max(take, notTake)
prev2 = prev1; prev1 = curr
dynamic_programming
scriptsComplexity
Directory
DIRECTORY.md
to include “House Robber” under Dynamic ProgrammingDemonstration
Run the script to execute built-in examples:
From Windows command line:
Rscript "R/dynamic_programming/house_robber.r"