SlideShare a Scribd company logo
Design and
Analysis of
Algorithms
DYNAMIC PROGRAMMING
PART II
Maximum Value Contiguous Subarray
Maximum Increasing Subsequence
Coin Change
Algorithms Dynamic Programming - Part II 1
 Instructor
Prof. Amrinder Arora
amrinder@gwu.edu
Please copy TA on emails
Please feel free to call as well

 Available for study sessions
Science and Engineering Hall
GWU
Algorithms Dynamic Programming - Part II 2
LOGISTICS
Algorithms
Analysis
Asymptotic
NP-
Completeness
Design
D&C
Greedy
DP
Graph
B&B
Applications
Algorithms Dynamic Programming - Part II 3
WHERE WE ARE
 Done
 Done
 Finishing today..
 Done
 http://video.google.com/videoplay?docid=16073867
32227802988#
 http://people.csail.mit.edu/bdean/6.046/dp/
Algorithms Dynamic Programming - Part II 4
DP (CONT.)
 Given an Array A(1..n)
 To find A(i..j) such that the sum of the terms in the
subarray is maximized.
 Insights
 If no negative terms in the array, then of course, we just select
the entire array.
 So, this problem is meaningful only when we have negative
numbers
 We can find sum of all contiguous subarrays in O(n3) time.
 Can we do better?
Algorithms Dynamic Programming - Part II 5
MAXIMUM VALUE CONTIGUOUS
SUBSEQUENCE
MaxValue = - infinity
for i = 1 to n {
for j = i to n {
currSum = findSubArraySum(i,j)
if CurrSum > MaxValue, then MaxValue = CurrSum
}
}
Procedure FindSubArraySum(i,j)
Double sum = 0
For int k = i to j {
sum = sum + A[k]
}
return sum
}
Algorithms Dynamic Programming - Part II 6
ALGORITHM MVCS1
Brute Force
Search!
O(n3) time
Procedure InitSubArraySums() {
for int i = 1 to n {
double sum = 0
for int k = i to n {
sum = sum + A(k)
SubArraySum[i][k] = sum
}
}
}
InitSubArraySums();
MaxValue = - infinity
for i = 1 to n {
for j = i to n {
currSum = SubArraySum[i][j]
If currSum > MaxValue, then MaxValue = currSum
}
}
Algorithms Dynamic Programming - Part II 7
ALGORITHM MVCS2
Still a full search,
but don’t
recompute sums
O(n2) time
 What can be a greedy variation of MVCS algorithm?
 What can be a D&C version of MVCS algorithm?
 How about Dynamic Programming?
Algorithms Dynamic Programming - Part II 8
USING OTHER TECHNIQUES FOR MVCS
Using Dynamic Programming Template
1. N: MVCS(i): value of MVCS ending at position i.
2. O: Prove Optimal Substructure Holds (What is our
claim?)
3. R: MVCS(i) = max {MVCS(i-1) + A[i],A[i]}
4. A: Start from left, and keep track of maximum
MVCS(i) encountered.
1. For I = 1 to n
Algorithms Dynamic Programming - Part II 9
MVCS3
O(n) time
 Using the Array used in class
 A[]: 22, -17, -71, 12, -22, 81, -10, 63
 MVCS[]: 22, 5, -66, 12, -10, 81, 71, 134
Algorithms Dynamic Programming - Part II 10
SAMPLE RUN OF MVCS3
 Given array A(1..n)
 Find a subsequence (not necessarily contiguous) that
is strictly increasing.
 For example
 {1, 7, 2, 8, 4, 1, 6, 11, 3, 15, 5, 12, 14}
Algorithms Dynamic Programming - Part II 11
LONGEST INCREASING SUBSEQUENCE
Longest subsequence is of length 7:
{1, .., 2, .., 4, .., 6, 11, .., .., .., 12, 14}
 Given array A(1..n)
 LIS(i) = longest strictly increasing subsequence that
ends at i.
 LIS(i) = max {LIS(j)} + 1, such that j < i, and A[j] <
A[i]
[Or A[j] ≤ A[i] if we are looking for that condition]
Algorithms Dynamic Programming - Part II 12
LONGEST INCREASING SUBSEQUENCE
 What is the time complexity of this algorithm?
Algorithms Dynamic Programming - Part II 13
LIS
 Using the Array used in Class
 {1, 7, 2, 8, 4, 1, 6, 11, 3, 15, 5, 12, 14}
 {1, 2, 2, 3, 3, 1, 4, 5, 3, 6, 4, 6, 7}
 What are the LIS values?
Algorithms Dynamic Programming - Part II 14
SAMPLE RUN OF LIS
 Given a set of coins with values v1, v2, … vn such that
v1 = 1, v1 < v2 < v3 < v4 < … < vn
 We want to make change for a given value S using as
few coins as possible
Algorithms Dynamic Programming - Part II 15
COIN CHANGE
 http://people.csail.mit.edu/bdean/6.046/dp/
Algorithms Dynamic Programming - Part II 16
AN INTERESTING SET OF PROBLEMS
Algorithms Dynamic Programming - Part II 17
80% OF
SUCCESS IS
SHOWING UP.
Algorithms Dynamic Programming - Part II 18
REST 80% OF
SUCCESS IS
BEING
PRESENT!
CS 6212
Analysis
Asymptotic
NP-
Completeness
Design
D&C
Greedy
DP
Graph
B&B
Applications
Algorithms Dynamic Programming - Part II 19
WHERE WE ARE
 Done
 Done
 Done
 Done

More Related Content

What's hot (20)

Unit 3 daa
Unit 3 daa
Nv Thejaswini
 
Lecture 8 dynamic programming
Lecture 8 dynamic programming
Oye Tu
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Amrinder Arora
 
DP
DP
Subba Oota
 
Dynamic programming - fundamentals review
Dynamic programming - fundamentals review
ElifTech
 
Backtracking & branch and bound
Backtracking & branch and bound
Vipul Chauhan
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
Gayathri Gaayu
 
unit-4-dynamic programming
unit-4-dynamic programming
hodcsencet
 
Dynamic programming
Dynamic programming
Jay Nagar
 
Skiena algorithm 2007 lecture16 introduction to dynamic programming
Skiena algorithm 2007 lecture16 introduction to dynamic programming
zukun
 
Design and Analysis of Algorithms
Design and Analysis of Algorithms
Arvind Krishnaa
 
Branch and bound technique
Branch and bound technique
ishmecse13
 
DS ppt
DS ppt
kirupasuchi1996
 
Design & Analysis Of Algorithm
Design & Analysis Of Algorithm
Computer Hardware & Trouble shooting
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
Amrinder Arora
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
Amrinder Arora
 
Design and Analysis of algorithms
Design and Analysis of algorithms
Dr. Rupa Ch
 
design and analysis of algorithm
design and analysis of algorithm
Muhammad Arish
 
Unit 3
Unit 3
Gunasundari Selvaraj
 
algorithm Unit 3
algorithm Unit 3
Monika Choudhery
 
Lecture 8 dynamic programming
Lecture 8 dynamic programming
Oye Tu
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Amrinder Arora
 
Dynamic programming - fundamentals review
Dynamic programming - fundamentals review
ElifTech
 
Backtracking & branch and bound
Backtracking & branch and bound
Vipul Chauhan
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
Gayathri Gaayu
 
unit-4-dynamic programming
unit-4-dynamic programming
hodcsencet
 
Dynamic programming
Dynamic programming
Jay Nagar
 
Skiena algorithm 2007 lecture16 introduction to dynamic programming
Skiena algorithm 2007 lecture16 introduction to dynamic programming
zukun
 
Design and Analysis of Algorithms
Design and Analysis of Algorithms
Arvind Krishnaa
 
Branch and bound technique
Branch and bound technique
ishmecse13
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
Amrinder Arora
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
Amrinder Arora
 
Design and Analysis of algorithms
Design and Analysis of algorithms
Dr. Rupa Ch
 
design and analysis of algorithm
design and analysis of algorithm
Muhammad Arish
 

Similar to Dynamic Programming - Part II (20)

Design and Analysis of Algorithm-Lecture.pptx
Design and Analysis of Algorithm-Lecture.pptx
bani30122004
 
Longest increasing subsequence
Longest increasing subsequence
S.Shayan Daneshvar
 
Dynamic programmng2
Dynamic programmng2
debolina13
 
Dynamic Programing.pptx good for understanding
Dynamic Programing.pptx good for understanding
HUSNAINAHMAD39
 
Module 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer method
JyoReddy9
 
Introduction to dynamic programming
Introduction to dynamic programming
Amisha Narsingani
 
Dynamic programming
Dynamic programming
Gopi Saiteja
 
Algorithm Design Technique
Algorithm Design Technique
Bharat Bhushan
 
Dynamic Programming
Dynamic Programming
Bharat Bhushan
 
8_dynamic_algorithm powerpoint ptesentation.pptx
8_dynamic_algorithm powerpoint ptesentation.pptx
zahidulhasan32
 
Chapter 5.pptx
Chapter 5.pptx
Tekle12
 
Dynamic pgmming
Dynamic pgmming
Dr. C.V. Suresh Babu
 
Learn about dynamic programming and how to design algorith
Learn about dynamic programming and how to design algorith
MazenulIslamKhan
 
AAC ch 3 Advance strategies (Dynamic Programming).pptx
AAC ch 3 Advance strategies (Dynamic Programming).pptx
HarshitSingh334328
 
L21_L27_Unit_5_Dynamic_Programming Computer Science
L21_L27_Unit_5_Dynamic_Programming Computer Science
priyanshukumarbt23cs
 
week 9 lec 15.pptx
week 9 lec 15.pptx
SulamanHassan
 
The Volcano/Cascades Optimizer
The Volcano/Cascades Optimizer
宇 傅
 
Annotaed slides for dynamic programming algorithm
Annotaed slides for dynamic programming algorithm
johnathangamal27
 
9 - DynamicProgramming-plus latihan.ppt
9 - DynamicProgramming-plus latihan.ppt
KerbauBakar
 
Lesson 14 - Dynamic Programming III.pptx
Lesson 14 - Dynamic Programming III.pptx
ZiaUrRehmanSafi
 
Design and Analysis of Algorithm-Lecture.pptx
Design and Analysis of Algorithm-Lecture.pptx
bani30122004
 
Longest increasing subsequence
Longest increasing subsequence
S.Shayan Daneshvar
 
Dynamic programmng2
Dynamic programmng2
debolina13
 
Dynamic Programing.pptx good for understanding
Dynamic Programing.pptx good for understanding
HUSNAINAHMAD39
 
Module 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer method
JyoReddy9
 
Introduction to dynamic programming
Introduction to dynamic programming
Amisha Narsingani
 
Dynamic programming
Dynamic programming
Gopi Saiteja
 
Algorithm Design Technique
Algorithm Design Technique
Bharat Bhushan
 
8_dynamic_algorithm powerpoint ptesentation.pptx
8_dynamic_algorithm powerpoint ptesentation.pptx
zahidulhasan32
 
Chapter 5.pptx
Chapter 5.pptx
Tekle12
 
Learn about dynamic programming and how to design algorith
Learn about dynamic programming and how to design algorith
MazenulIslamKhan
 
AAC ch 3 Advance strategies (Dynamic Programming).pptx
AAC ch 3 Advance strategies (Dynamic Programming).pptx
HarshitSingh334328
 
L21_L27_Unit_5_Dynamic_Programming Computer Science
L21_L27_Unit_5_Dynamic_Programming Computer Science
priyanshukumarbt23cs
 
The Volcano/Cascades Optimizer
The Volcano/Cascades Optimizer
宇 傅
 
Annotaed slides for dynamic programming algorithm
Annotaed slides for dynamic programming algorithm
johnathangamal27
 
9 - DynamicProgramming-plus latihan.ppt
9 - DynamicProgramming-plus latihan.ppt
KerbauBakar
 
Lesson 14 - Dynamic Programming III.pptx
Lesson 14 - Dynamic Programming III.pptx
ZiaUrRehmanSafi
 
Ad

More from Amrinder Arora (20)

Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Amrinder Arora
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search Traversal
Amrinder Arora
 
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Amrinder Arora
 
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Amrinder Arora
 
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Amrinder Arora
 
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Amrinder Arora
 
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Amrinder Arora
 
Online algorithms in Machine Learning
Online algorithms in Machine Learning
Amrinder Arora
 
NP completeness
NP completeness
Amrinder Arora
 
Algorithmic Puzzles
Algorithmic Puzzles
Amrinder Arora
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1
Amrinder Arora
 
Set Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom Filters
Amrinder Arora
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci Heaps
Amrinder Arora
 
R-Trees and Geospatial Data Structures
R-Trees and Geospatial Data Structures
Amrinder Arora
 
Tries - Tree Based Structures for Strings
Tries - Tree Based Structures for Strings
Amrinder Arora
 
Splay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data Structures
Amrinder Arora
 
BTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTs
Amrinder Arora
 
Binary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red Black
Amrinder Arora
 
Graphs, Trees, Paths and Their Representations
Graphs, Trees, Paths and Their Representations
Amrinder Arora
 
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data Structures
Amrinder Arora
 
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Amrinder Arora
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search Traversal
Amrinder Arora
 
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Amrinder Arora
 
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Amrinder Arora
 
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Amrinder Arora
 
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Amrinder Arora
 
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Amrinder Arora
 
Online algorithms in Machine Learning
Online algorithms in Machine Learning
Amrinder Arora
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1
Amrinder Arora
 
Set Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom Filters
Amrinder Arora
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci Heaps
Amrinder Arora
 
R-Trees and Geospatial Data Structures
R-Trees and Geospatial Data Structures
Amrinder Arora
 
Tries - Tree Based Structures for Strings
Tries - Tree Based Structures for Strings
Amrinder Arora
 
Splay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data Structures
Amrinder Arora
 
BTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTs
Amrinder Arora
 
Binary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red Black
Amrinder Arora
 
Graphs, Trees, Paths and Their Representations
Graphs, Trees, Paths and Their Representations
Amrinder Arora
 
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data Structures
Amrinder Arora
 
Ad

Recently uploaded (20)

Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 

Dynamic Programming - Part II

  • 1. Design and Analysis of Algorithms DYNAMIC PROGRAMMING PART II Maximum Value Contiguous Subarray Maximum Increasing Subsequence Coin Change Algorithms Dynamic Programming - Part II 1
  • 2.  Instructor Prof. Amrinder Arora [email protected] Please copy TA on emails Please feel free to call as well   Available for study sessions Science and Engineering Hall GWU Algorithms Dynamic Programming - Part II 2 LOGISTICS
  • 5.  Given an Array A(1..n)  To find A(i..j) such that the sum of the terms in the subarray is maximized.  Insights  If no negative terms in the array, then of course, we just select the entire array.  So, this problem is meaningful only when we have negative numbers  We can find sum of all contiguous subarrays in O(n3) time.  Can we do better? Algorithms Dynamic Programming - Part II 5 MAXIMUM VALUE CONTIGUOUS SUBSEQUENCE
  • 6. MaxValue = - infinity for i = 1 to n { for j = i to n { currSum = findSubArraySum(i,j) if CurrSum > MaxValue, then MaxValue = CurrSum } } Procedure FindSubArraySum(i,j) Double sum = 0 For int k = i to j { sum = sum + A[k] } return sum } Algorithms Dynamic Programming - Part II 6 ALGORITHM MVCS1 Brute Force Search! O(n3) time
  • 7. Procedure InitSubArraySums() { for int i = 1 to n { double sum = 0 for int k = i to n { sum = sum + A(k) SubArraySum[i][k] = sum } } } InitSubArraySums(); MaxValue = - infinity for i = 1 to n { for j = i to n { currSum = SubArraySum[i][j] If currSum > MaxValue, then MaxValue = currSum } } Algorithms Dynamic Programming - Part II 7 ALGORITHM MVCS2 Still a full search, but don’t recompute sums O(n2) time
  • 8.  What can be a greedy variation of MVCS algorithm?  What can be a D&C version of MVCS algorithm?  How about Dynamic Programming? Algorithms Dynamic Programming - Part II 8 USING OTHER TECHNIQUES FOR MVCS
  • 9. Using Dynamic Programming Template 1. N: MVCS(i): value of MVCS ending at position i. 2. O: Prove Optimal Substructure Holds (What is our claim?) 3. R: MVCS(i) = max {MVCS(i-1) + A[i],A[i]} 4. A: Start from left, and keep track of maximum MVCS(i) encountered. 1. For I = 1 to n Algorithms Dynamic Programming - Part II 9 MVCS3 O(n) time
  • 10.  Using the Array used in class  A[]: 22, -17, -71, 12, -22, 81, -10, 63  MVCS[]: 22, 5, -66, 12, -10, 81, 71, 134 Algorithms Dynamic Programming - Part II 10 SAMPLE RUN OF MVCS3
  • 11.  Given array A(1..n)  Find a subsequence (not necessarily contiguous) that is strictly increasing.  For example  {1, 7, 2, 8, 4, 1, 6, 11, 3, 15, 5, 12, 14} Algorithms Dynamic Programming - Part II 11 LONGEST INCREASING SUBSEQUENCE Longest subsequence is of length 7: {1, .., 2, .., 4, .., 6, 11, .., .., .., 12, 14}
  • 12.  Given array A(1..n)  LIS(i) = longest strictly increasing subsequence that ends at i.  LIS(i) = max {LIS(j)} + 1, such that j < i, and A[j] < A[i] [Or A[j] ≤ A[i] if we are looking for that condition] Algorithms Dynamic Programming - Part II 12 LONGEST INCREASING SUBSEQUENCE
  • 13.  What is the time complexity of this algorithm? Algorithms Dynamic Programming - Part II 13 LIS
  • 14.  Using the Array used in Class  {1, 7, 2, 8, 4, 1, 6, 11, 3, 15, 5, 12, 14}  {1, 2, 2, 3, 3, 1, 4, 5, 3, 6, 4, 6, 7}  What are the LIS values? Algorithms Dynamic Programming - Part II 14 SAMPLE RUN OF LIS
  • 15.  Given a set of coins with values v1, v2, … vn such that v1 = 1, v1 < v2 < v3 < v4 < … < vn  We want to make change for a given value S using as few coins as possible Algorithms Dynamic Programming - Part II 15 COIN CHANGE
  • 16.  http://people.csail.mit.edu/bdean/6.046/dp/ Algorithms Dynamic Programming - Part II 16 AN INTERESTING SET OF PROBLEMS
  • 17. Algorithms Dynamic Programming - Part II 17 80% OF SUCCESS IS SHOWING UP.
  • 18. Algorithms Dynamic Programming - Part II 18 REST 80% OF SUCCESS IS BEING PRESENT!
  • 19. CS 6212 Analysis Asymptotic NP- Completeness Design D&C Greedy DP Graph B&B Applications Algorithms Dynamic Programming - Part II 19 WHERE WE ARE  Done  Done  Done  Done