From 2f60cab8351dced1c72e016b31cf20ad38b0b0cb Mon Sep 17 00:00:00 2001 From: casca <8927157+casca@users.noreply.github.com> Date: Thu, 30 Jan 2020 21:33:47 +0100 Subject: [PATCH] Update combinationSum README to reflect new implementation --- src/algorithms/sets/combination-sum/README.md | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/algorithms/sets/combination-sum/README.md b/src/algorithms/sets/combination-sum/README.md index cb14f1ba..379e0590 100644 --- a/src/algorithms/sets/combination-sum/README.md +++ b/src/algorithms/sets/combination-sum/README.md @@ -38,21 +38,22 @@ A solution set is: ## Explanations Since the problem is to get all the possible results, not the best or the -number of result, thus we don’t need to consider DP (dynamic programming), -backtracking approach using recursion is needed to handle it. +number of result, we don’t need to consider dynamic programming. +We do instead a depth-first traversal of the decision tree, +using an iterative implementation to avoid stack overflows. Here is an example of decision tree for the situation when `candidates = [2, 3]` and `target = 6`: ``` - 0 - / \ - +2 +3 - / \ \ - +2 +3 +3 - / \ / \ \ - +2 ✘ ✘ ✘ ✓ - / \ - ✓ ✘ + 0 + / \ + +3 +2 + / \ \ + +3 +2 +2 + / \ \ + ✓ +2 +2 + \ \ + ✘ ✓ ``` ## References