0% found this document useful (0 votes)
2 views12 pages

Presentation 1: Prepared by Group 15 Aka (Blue Team)

Uploaded by

Youssef Ebrahim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views12 pages

Presentation 1: Prepared by Group 15 Aka (Blue Team)

Uploaded by

Youssef Ebrahim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Prepared by group 15 aka (blue team)

Presentation
Dynamic Programming (dp)

1
16 December, 2024

Supervised by : Dr. Hesham Keshk


Team Members
Ahmed Sameh
Mohamed
Magdy
Mostafa Khaled
Youssef => (Presenter now)

Ebrahim
Introduction to Dynamic
Programming (dp)

• Dynamic Programming (dp) is a powerful problem-solving


technique used to solve complex problems efficiently.
• It optimizes solutions by breaking problems into smaller sub-
problems and reusing results.
Caching in browsers

what happen ?
• Browsers store data like images and
scripts in cache to avoid downloading the
same resources repeatedly.
• Saves time and resources by reusing
previously downloaded data.
What is Dynamic
Programming (dp) ?
Definition
• Dynamic Programming (DP) is not an algorithm or
data structure.
• It is a problem-solving technique that solves
optimization problems by:
⚬ Breaking them into smaller overlapping sub-
problems.
⚬ Storing the results of sub-problems for reuse.

Key Concepts:
• Overlapping Sub-problems
• Optimal Substructure
Key Concepts of Dynamic
Programming

Overlapping Sub- Optimal Substructure Memoization vs.


problems
• The problem can be divided • The solution to the larger • Tabulation
Memoization (Top-Down
into smaller subproblems problem can be derived from Approach): Start solving the main
that are solved multiple the solutions of its problem, breaking it into
times. subproblems. subproblems recursively, and
• Example: In Fibonacci • Example: To find the shortest store results in memory to avoid

number computation, path from A to B, if the recomputation.

calculating fib(n-1) and fib(n- shortest path from A to C and • Tabulation (Bottom-Up

2) overlaps repeatedly. C to B are known, the overall Approach): Solve subproblems

path can be derived. iteratively and store results in a


table, building up to the main
Fibonacci
The Problem
Sequence and • Compute the Fibonacci sequence: Fib(n) = Fib(n-1) +
Fib(n-2).

Dynamic • Example sequence: 0, 1, 1, 2, 3, 5, 8, 13, ...


Approaches:

Programming • Recomputes the same sub-problems repeatedly,


leading to exponential time complexity.

Dynamic Programming Solution:


Use memoization or tabulation to store results of
previously computed Fibonacci numbers.
Fibonacci Sequence and
Dynamic Programming with
Memoization
-1 -1 -1 -1 ..... -1 -1
0 1 2 3 n-1 n
Fibonacci Sequence and
Dynamic Programming with
Tabulation

f(n- f(n-
f(n)
1) 2)
prev prev curre
1 2 nt
Memoization vs. Tabulation in
Fibonacci Sequence
Feature Memoization Tabulation

Definitio Top-down approach Bottom-up approach


n
Solves problems recursively and stores Solves problems iteratively by building
Method
results. a table.
Uses only three variables to store
Storage Uses an array of size n to store results.
results.

Recursive Fibonacci with cache. Iterative Fibonacci method.


Example
Dynamic Programming
Wrap-Up
• Summary:
⚬ Dynamic Programming is a powerful technique to optimize
problem-solving.
⚬ Focuses on solving problems efficiently by reusing solutions to
sub-problems.
• Key Takeaways:
⚬ Understand the problem’s substructure.
⚬ Choose between memoization and tabulation.
• Applications:
⚬ Fibonacci, knapsack problem, shortest path, and many more
optimization problems.
Thank
you

You might also like