Dynamic Programming Quiz space complexity

Is there a reason that “When space complexity must be minimized.” isn’t a good answer for when dynamic programming is NOT be the appropriate algorithmic approach?

Here is question 10 in the quiz:

  1. In which scenario would dynamic programming NOT be the appropriate algorithmic approach?

When space complexity must be minimized.
When subproblems are independent and don’t overlap.
When the problem can be broken into smaller subproblems.
When the problem requires finding an optimal solution.

https://www.freecodecamp.org/learn/python-v9/quiz-dynamic-programming/quiz-dynamic-programming

This is from the review:

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.

https://www.freecodecamp.org/learn/python-v9/review-dynamic-programming/review-dynamic-programming

To me, it seems like “When space complexity must be minimized.” is correct because dp uses more space to optimize time. “You need to optimize for time complexity at the cost of space complexity.

“When subproblems are independent and don’t overlap.” also seems correct because from the review “The problem can be broken down into overlapping subproblems.”

Is it a situation where one answer is MORE correct out of two correct answers?

Hi @pkdvalis

Introduction to Dynamic Programming

* Overlapping Subproblems: The same smaller problems appear multiple times when solving the larger problem. Instead of recalculating these subproblems repeatedly, we store their solutions.

When the same smaller problems repeat, then dynamic programming is appropriate.

If they are independent and don’t overlap, then DP isn’t the right approach.

Happy coding

That’s right, I agree, but:

Is dynamic programming the right approach when space complexity needs to be minimized?

@Teller Happy New Year! Have a good evening

Maybe look at real world applications for dynamic programming.

Generally with optimisations there are tradeoffs.

Happy coding

Exactly. I’m just going from the theory lesson here and I’m only interested in how the lesson relates to the quiz:

When to Use Dynamic Programming
Dynamic programming is effective when:

  • The problem can be broken down into overlapping subproblems.
  • You need to optimize for time complexity at the cost of space complexity.

So it seems like both of these quiz answers are correct, no? Am I missing something?

In which scenario would dynamic programming NOT be the appropriate algorithmic approach?

  • When space complexity must be minimized.
  • When subproblems are independent and don’t overlap.

Although, this seems to be a counterpoint:

Key advantages of tabulation

  • Easy to optimize: Can reduce space complexity to O(1) since we only need the last two values.

DP seems to fit for 3 of the options.

Ok, so you agree there’s a problem with the quiz question?

I think is a case of the odd one out. Through a process of elimination, only one option is left.