AVL Tree:
Dynamic Programming is a commonly used algorithmic technique used to optimize recursive solutions when same subproblems are called again.
The core idea behind DP is to store solutions to subproblems so that each is solved only once.
To solve DP problems, we first write a recursive solution in a way that there are overlapping subproblems in the recursion tree (the recursive function is called with the same parameters multiple times)
To make sure that a recursive value is computed only once (to improve time taken by algorithm), we store results of the recursive calls.
There are two ways to store the results, one is top down (or memorization) and other is bottom up (or tabulation).
When to Use Dynamic Programming (DP)?
Dynamic programming is used for solving problems that consists of the following characteristics:
1. Optimal Substructure:
The property Optimal substructure means that we use the optimal results of subproblems to achieve the optimal result of the bigger problem.
Example:
Consider the problem of finding the minimum cost path in a weighted graph from a source node to a destination node. We can break this problem down into smaller subproblems:
Find the minimum cost path from the source node to each intermediate node.
Find the minimum cost path from each intermediate node to the destination node.
Materials
"Before you optimize, determine what to optimize."
— Charles Antony Richard Hoare