From 4760d3514ed7ed5adad923978a99cc0352b98fb5 Mon Sep 17 00:00:00 2001 From: Kolade Chris <65571316+Ksound22@users.noreply.github.com> Date: Wed, 4 Mar 2026 12:52:39 +0100 Subject: [PATCH] feat(curriculum): add dynamic programming review for JS cert (#65991) Co-authored-by: Zaira <33151350+zairahira@users.noreply.github.com> Co-authored-by: majestic-owl448 <26656284+majestic-owl448@users.noreply.github.com> --- client/i18n/locales/english/intro.json | 6 ++ .../6999b92ca334e9cf237dc92d.md | 84 +++++++++++++++++++ .../blocks/review-dynamic-programming-js.json | 11 +++ .../structure/superblocks/javascript-v9.json | 5 +- 4 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 curriculum/challenges/english/blocks/review-dynamic-programming-js/6999b92ca334e9cf237dc92d.md create mode 100644 curriculum/structure/blocks/review-dynamic-programming-js.json diff --git a/client/i18n/locales/english/intro.json b/client/i18n/locales/english/intro.json index 91df227d554..de30ac1e73e 100644 --- a/client/i18n/locales/english/intro.json +++ b/client/i18n/locales/english/intro.json @@ -3335,6 +3335,12 @@ "In this lab, you will implement a function that converts an adjacency list representation of a graph into an adjacency matrix representation." ] }, + "review-dynamic-programming-js": { + "title": "Dynamic Programming Review", + "intro": [ + "Before you're quizzed on dynamic programming, you should review what you've learned about it." + ] + }, "quiz-dynamic-programming-js": { "title": "Dynamic Programming Quiz", "intro": [ diff --git a/curriculum/challenges/english/blocks/review-dynamic-programming-js/6999b92ca334e9cf237dc92d.md b/curriculum/challenges/english/blocks/review-dynamic-programming-js/6999b92ca334e9cf237dc92d.md new file mode 100644 index 00000000000..9acf9cf124f --- /dev/null +++ b/curriculum/challenges/english/blocks/review-dynamic-programming-js/6999b92ca334e9cf237dc92d.md @@ -0,0 +1,84 @@ +--- +id: 6999b92ca334e9cf237dc92d +title: Dynamic Programming Review +challengeType: 31 +dashedName: review-dynamic-programming-js +--- + +# --description-- + +## Introduction to Dynamic Programming + +- **Definition**: Dynamic programming is an algorithmic technique that solves complex problems by breaking them down into simpler subproblems and storing the results to avoid redundant calculations. +- **Overlapping Subproblems**: The same smaller problems appear multiple times when solving the larger problem. Instead of recalculating these subproblems repeatedly, we store their solutions. +- **Optimal Substructure**: The optimal solution to the problem contains optimal solutions to its subproblems. This means we can build up the best solution by combining the best solutions to smaller parts. + +## Dynamic Programming Solutions + +- **Memoization (Top-Down Approach)**: Memoization stores the results of expensive function calls and returns the cached result when the same inputs occur again. + +```js +function climbStairsMemo(n, memo = {}) { + // If already calculated, return cached value + if (memo[n] !== undefined) { + return memo[n]; + } + + // Base cases: 1 way for 1 step, 2 ways for 2 steps + if (n <= 2) { + return n; + } + + // Calculate once and store in memo for future use + memo[n] = + climbStairsMemo(n - 1, memo) + + climbStairsMemo(n - 2, memo); + + return memo[n]; +} +``` + +- **Tabulation (Bottom-Up Approach)**: Tabulation builds the solution from the ground up, filling a table with solutions to subproblems. + +```js +function climbStairsTabulation(n) { + if (n <= 2) { + return n; + } + + // Create an array to store solutions from 0 to n + const dp = new Array(n + 1).fill(0); + + // Base cases + dp[1] = 1; // 1 way to reach step 1 + dp[2] = 2; // 2 ways to reach step 2 + + // Build up the solution iteratively + for (let i = 3; i <= n; i++) { + // Ways to reach step i = ways to reach (i-1) + ways to reach (i-2) + dp[i] = dp[i - 1] + dp[i - 2]; + } + + return dp[n]; +} +``` + +## Real-World Applications Using Dynamic Programming + +- **Route Optimization**: GPS systems use dynamic programming algorithms to find shortest paths between locations. +- **Text Processing**: Spell checkers and autocomplete features often rely on dynamic programming to calculate edit distances between words. +- **Financial Modeling**: Investment strategies and portfolio optimization frequently employ dynamic programming techniques. +- **Resource Allocation**: The knapsack problem and its variants appear in scheduling, budgeting, and resource management. + +## When to Use Dynamic Programming + +You should consider using dynamic programming in the following scenarios: + +- The problem can be broken down into overlapping subproblems. +- The problem exhibits optimal substructure. +- A naive recursive solution would involve repeated calculations. +- You need to optimize for time complexity at the cost of space complexity. + +# --assignment-- + +Review Dynamic Programming topics and concepts. diff --git a/curriculum/structure/blocks/review-dynamic-programming-js.json b/curriculum/structure/blocks/review-dynamic-programming-js.json new file mode 100644 index 00000000000..7edff299f8f --- /dev/null +++ b/curriculum/structure/blocks/review-dynamic-programming-js.json @@ -0,0 +1,11 @@ +{ + "name": "Dynamic Programming Review", + "isUpcomingChange": true, + "dashedName": "review-dynamic-programming-js", + "helpCategory": "JavaScript", + "blockLayout": "link", + "challengeOrder": [ + { "id": "6999b92ca334e9cf237dc92d", "title": "Dynamic Programming Review" } + ], + "blockLabel": "review" +} diff --git a/curriculum/structure/superblocks/javascript-v9.json b/curriculum/structure/superblocks/javascript-v9.json index 751fd2f29fc..f31b48f078d 100644 --- a/curriculum/structure/superblocks/javascript-v9.json +++ b/curriculum/structure/superblocks/javascript-v9.json @@ -322,7 +322,10 @@ { "dashedName": "dynamic-programming", "comingSoon": true, - "blocks": ["quiz-dynamic-programming-js"] + "blocks": [ + "review-dynamic-programming-js", + "quiz-dynamic-programming-js" + ] }, { "dashedName": "functional-programming",