# Difference between back tracking and dynamic programming

Posted on

algorithm, data-structures

I heard the only difference between dynamic programming and back tracking is DP allows overlapping of sub problems, e.g.

`fib(n) = fib(n-1) + fib (n-2)`

Is it right? Are there any other differences?

Also, I would like know some common problems solved using these techniques.

## Related posts

- R – ny decryption algorithm that uses a dictionary to decrypt an encrypted algorithm
- Eppstein’s algorithm and Yen’s algorithm for k shortest paths
- Is Dijkstra’s algorithm, dynamic programming
- Manacher’s algorithm (algorithm to find longest palindrome substring in linear time)
- R – Tracking fitness in a genetic algorithm
- C programming language, Floyd’s algorithm
- Adding momentum to back propagation algorithm
- C++ –
No such file error - C++ – Flaws in algorithm and algorithm performance
- Anyone know an example algorithm for word segmentation using dynamic programming?
- C# – Why does .Net use a rounding algorithm in String.Format that is inconsistent with the default Math.Round() algorithm
- The smallest value of n such that an algorithm whose running time is 100n^2 runs faster than an algorithm whose running time is 2^n?
- Dijkstra’s algorithm a greedy or dynamic programming algorithm
- Kruskal’s Algorithm : What is the Algorithm to check if the edges of the graph form a loop or not
- Why are back edges required in the Ford-Fulkerson algorithm
- Algorithm for “neon glow” graphics programming
- Relation between KMP algorithm and Z algorithm
- C# – Get the data back on the prevoius window when click on Back button
- Android – APK upload failed for Alpha version. Errors from apksigner: Digest algorithm and Signature Algorithm Which is not supported on API levels [[16, 17]]
- C# – reassign a partial view’s data back to the model when POSTing back to the controller
- Why would an O(n^2) algorithm run quicker than a O(n) algorithm on the same input
- Python – bulls and cows game — programming algorithm(python)
- Ios – How to pass back data to parent view when using UINavigationController and default Back Button
- Is the greedy best-first search algorithm different from the best-first search algorithm
- Crossover Probability & Mutation Probability in Genetic Algorithm or Genetic Programming
- Is an optimal algorithm a complete algorithm
- R – Prim’s algorithm for minimum spanning trees – confusion in algorithm
- Java – Back propagation algorithm
- Java – Why Arrays.sort is quicksort algorithm, why not another sort algorithm
- How to show that one algorithm is more efficient than another algorithm
- Neural Network – updating weight matrix – back-propagation algorithm
- How is O(N) algorithm also an O(N^2) algorithm
- Java – How does the recursion preorder traversal algorithm go back to parent
- Why 0/1 knapsack using dynamic programming is not polynomial time algorithm
- C# – Is the sorting algorithm used by .NET’s `Array.Sort()` method a stable algorithm
- Matlab – Back propagation algorithm of Neural Network : XOR training
- Javascript –

## Best Solution

There are two typical implementations of Dynamic Programming approach:

bottom-to-topandtop-to-bottom.Top-to-bottom Dynamic Programmingis nothing else than ordinaryrecursion, enhanced with memorizing the solutions for intermediate sub-problems. When a given sub-problem arises second (third, fourth...) time, it is not solved from scratch, but instead the previously memorized solution is used right away. This technique is known under the namememoization(no 'r' before 'i').This is actually what your example with Fibonacci sequence is supposed to illustrate. Just use the recursive formula for Fibonacci sequence, but build the table of

`fib(i)`

values along the way, and you get a Top-to-bottom DP algorithm for this problem (so that, for example, if you need to calculate`fib(5)`

second time, you get it from the table instead of calculating it again).In

Bottom-to-top Dynamic Programmingthe approach is also based on storing sub-solutions in memory, but they are solved in a different order (from smaller to bigger), and the resultant general structure of the algorithm is not recursive. LCS algorithm is a classic Bottom-to-top DP example.Bottom-to-top DP algorithms are usually more efficient, but they are generally harder (and sometimes impossible) to build, since it is not always easy to predict which primitive sub-problems you are going to need to solve the whole original problem, and which path you have to take from small sub-problems to get to the final solution in the most efficient way.