SlideShare a Scribd company logo
2
David Luebke 2
Review: Amortized Analysis
● To illustrate amortized analysis we examined
dynamic tables
1. Init table size m = 1
2. Insert elements until number n > m
3. Generate new table of size 2m
4. Reinsert old elements into new table
5. (back to step 2)
● What is the worst-case cost of an insert?
● What is the amortized cost of an insert?
Most read
David Luebke 1
CS 332: Algorithms
Dynamic Programming
David Luebke 2
Review: Amortized Analysis
● To illustrate amortized analysis we examined
dynamic tables
1. Init table size m = 1
2. Insert elements until number n > m
3. Generate new table of size 2m
4. Reinsert old elements into new table
5. (back to step 2)
● What is the worst-case cost of an insert?
● What is the amortized cost of an insert?
David Luebke 3
Review:
Analysis Of Dynamic Tables
● Let ci = cost of ith insert
● ci = i if i-1 is exact power of 2, 1 otherwise
● Example:
■ Operation Table Size Cost
Insert(1) 1 1 1
Insert(2) 2 1 + 1 2
Insert(3) 4 1 + 2
Insert(4) 4 1
Insert(5) 8 1 + 4
Insert(6) 8 1
Insert(7) 8 1
Insert(8) 8 1
Insert(9) 16 1 + 8
1
2
3
4
5
6
7
8
9
David Luebke 4
Review: Aggregate Analysis
● n Insert() operations cost
● Average cost of operation
= (total cost)/(# operations) < 3
● Asymptotically, then, a dynamic table costs
the same as a fixed-size table
■ Both O(1) per Insert operation
nnnnc
n
j
j
n
i
i 3)12(2
lg
01
<−+=+≤ ∑∑ ==
David Luebke 5
Review: Accounting Analysis
● Charge each operation $3 amortized cost
■ Use $1 to perform immediate Insert()
■ Store $2
● When table doubles
■ $1 reinserts old item, $1 reinserts another old item
■ We’ve paid these costs up front with the last n/2
Insert()s
● Upshot: O(1) amortized cost per operation
David Luebke 6
Review: Accounting Analysis
● Suppose must support insert & delete, table
should contract as well as expand
■ Table overflows ⇒ double it (as before)
■ Table < 1/4 full ⇒ halve it
■ Charge $3 for Insert (as before)
■ Charge $2 for Delete
○ Store extra $1 in emptied slot
○ Use later to pay to copy remaining items to new table
when shrinking table
● What if we halve size when table < 1/8 full?
David Luebke 7
Dynamic Programming
● Another strategy for designing algorithms is
dynamic programming
■ A metatechnique, not an algorithm
(like divide & conquer)
■ The word “programming” is historical and
predates computer programming
● Use when problem breaks down into recurring
small subproblems
David Luebke 8
Dynamic Programming Example:
Longest Common Subsequence
● Longest common subsequence (LCS) problem:
■ Given two sequences x[1..m] and y[1..n], find the
longest subsequence which occurs in both
■ Ex: x = {A B C B D A B }, y = {B D C A B A}
■ {B C} and {A A} are both subsequences of both
○ What is the LCS?
■ Brute-force algorithm: For every subsequence of x,
check if it’s a subsequence of y
○ How many subsequences of x are there?
○ What will be the running time of the brute-force alg?
David Luebke 9
LCS Algorithm
● Brute-force algorithm: 2m
subsequences of x to
check against n elements of y: O(n 2m
)
● We can do better: for now, let’s only worry
about the problem of finding the length of LCS
■ When finished we will see how to backtrack from
this solution back to the actual LCS
● Notice LCS problem has optimal substructure
■ Subproblems: LCS of pairs of prefixes of x and y
David Luebke 10
Finding LCS Length
● Define c[i,j] to be the length of the LCS of
x[1..i] and y[1..j]
■ What is the length of LCS of x and y?
● Theorem:
● What is this really saying?



−−
=+−−
=
otherwise]),1[],1,[max(
],[][if1]1,1[
],[
jicjic
jyixjic
jic
David Luebke 11
The End

More Related Content

What's hot (20)

5.3 dynamic programming 03
5.3 dynamic programming 035.3 dynamic programming 03
5.3 dynamic programming 03
Krish_ver2
 
Dynamic programming class 16
Dynamic programming class 16Dynamic programming class 16
Dynamic programming class 16
Kumar
 
DP
DPDP
DP
Subba Oota
 
Lecture 8 dynamic programming
Lecture 8 dynamic programmingLecture 8 dynamic programming
Lecture 8 dynamic programming
Oye Tu
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
Amit Kumar Rathi
 
Dynamic programming - fundamentals review
Dynamic programming - fundamentals reviewDynamic programming - fundamentals review
Dynamic programming - fundamentals review
ElifTech
 
dynamic programming Rod cutting class
dynamic programming Rod cutting classdynamic programming Rod cutting class
dynamic programming Rod cutting class
giridaroori
 
Dynamic pgmming
Dynamic pgmmingDynamic pgmming
Dynamic pgmming
Dr. C.V. Suresh Babu
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programming
hodcsencet
 
Dynamic programming1
Dynamic programming1Dynamic programming1
Dynamic programming1
debolina13
 
Dynamic programming Basics
Dynamic programming BasicsDynamic programming Basics
Dynamic programming Basics
Kvishnu Dahatonde
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
Respa Peter
 
Dynamic Programming
Dynamic ProgrammingDynamic Programming
Dynamic Programming
Sahil Kumar
 
Daa:Dynamic Programing
Daa:Dynamic ProgramingDaa:Dynamic Programing
Daa:Dynamic Programing
rupali_2bonde
 
Introduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of OptimalityIntroduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of Optimality
Bhavin Darji
 
DS ppt
DS pptDS ppt
DS ppt
kirupasuchi1996
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1
Amrinder Arora
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
hodcsencet
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
Amrinder Arora
 
Matrix mult class-17
Matrix mult class-17Matrix mult class-17
Matrix mult class-17
Kumar
 
5.3 dynamic programming 03
5.3 dynamic programming 035.3 dynamic programming 03
5.3 dynamic programming 03
Krish_ver2
 
Dynamic programming class 16
Dynamic programming class 16Dynamic programming class 16
Dynamic programming class 16
Kumar
 
Lecture 8 dynamic programming
Lecture 8 dynamic programmingLecture 8 dynamic programming
Lecture 8 dynamic programming
Oye Tu
 
Dynamic programming - fundamentals review
Dynamic programming - fundamentals reviewDynamic programming - fundamentals review
Dynamic programming - fundamentals review
ElifTech
 
dynamic programming Rod cutting class
dynamic programming Rod cutting classdynamic programming Rod cutting class
dynamic programming Rod cutting class
giridaroori
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programming
hodcsencet
 
Dynamic programming1
Dynamic programming1Dynamic programming1
Dynamic programming1
debolina13
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
Respa Peter
 
Dynamic Programming
Dynamic ProgrammingDynamic Programming
Dynamic Programming
Sahil Kumar
 
Daa:Dynamic Programing
Daa:Dynamic ProgramingDaa:Dynamic Programing
Daa:Dynamic Programing
rupali_2bonde
 
Introduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of OptimalityIntroduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of Optimality
Bhavin Darji
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1
Amrinder Arora
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
hodcsencet
 
Matrix mult class-17
Matrix mult class-17Matrix mult class-17
Matrix mult class-17
Kumar
 

Viewers also liked (19)

Randomized Algorithms in Linear Algebra & the Column Subset Selection Problem
Randomized Algorithms in Linear Algebra & the Column Subset Selection ProblemRandomized Algorithms in Linear Algebra & the Column Subset Selection Problem
Randomized Algorithms in Linear Algebra & the Column Subset Selection Problem
Wei Xue
 
Chap08alg
Chap08algChap08alg
Chap08alg
Munkhchimeg
 
Elements of dynamic programming
Elements of dynamic programmingElements of dynamic programming
Elements of dynamic programming
Tafhim Islam
 
Class warshal2
Class warshal2Class warshal2
Class warshal2
Debarati Das
 
Mathematical analysis of Graph and Huff amn coding
Mathematical analysis of Graph and Huff amn codingMathematical analysis of Graph and Huff amn coding
Mathematical analysis of Graph and Huff amn coding
Dr Anjan Krishnamurthy
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
BG Java EE Course
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
Maher Alshammari
 
Solving The Shortest Path Tour Problem
Solving The Shortest Path Tour ProblemSolving The Shortest Path Tour Problem
Solving The Shortest Path Tour Problem
Nozir Shokirov
 
Average case Analysis of Quicksort
Average case Analysis of QuicksortAverage case Analysis of Quicksort
Average case Analysis of Quicksort
Rajendran
 
21 backtracking
21 backtracking21 backtracking
21 backtracking
Aparup Behera
 
5.5 back track
5.5 back track5.5 back track
5.5 back track
Krish_ver2
 
Subset sum problem Dynamic and Brute Force Approch
Subset sum problem Dynamic and Brute Force ApprochSubset sum problem Dynamic and Brute Force Approch
Subset sum problem Dynamic and Brute Force Approch
Ijlal Ijlal
 
Huffman codes
Huffman codesHuffman codes
Huffman codes
Nargis Ehsan
 
Covering (Rules-based) Algorithm
Covering (Rules-based) AlgorithmCovering (Rules-based) Algorithm
Covering (Rules-based) Algorithm
ZHAO Sam
 
Backtracking
BacktrackingBacktracking
Backtracking
Vikas Sharma
 
Lect6 csp
Lect6 cspLect6 csp
Lect6 csp
trivedidr
 
Backtracking
BacktrackingBacktracking
Backtracking
Sally Salem
 
Queue- 8 Queen
Queue- 8 QueenQueue- 8 Queen
Queue- 8 Queen
Ha Ninh
 
(Binary tree)
(Binary tree)(Binary tree)
(Binary tree)
almario1988
 
Randomized Algorithms in Linear Algebra & the Column Subset Selection Problem
Randomized Algorithms in Linear Algebra & the Column Subset Selection ProblemRandomized Algorithms in Linear Algebra & the Column Subset Selection Problem
Randomized Algorithms in Linear Algebra & the Column Subset Selection Problem
Wei Xue
 
Elements of dynamic programming
Elements of dynamic programmingElements of dynamic programming
Elements of dynamic programming
Tafhim Islam
 
Mathematical analysis of Graph and Huff amn coding
Mathematical analysis of Graph and Huff amn codingMathematical analysis of Graph and Huff amn coding
Mathematical analysis of Graph and Huff amn coding
Dr Anjan Krishnamurthy
 
Solving The Shortest Path Tour Problem
Solving The Shortest Path Tour ProblemSolving The Shortest Path Tour Problem
Solving The Shortest Path Tour Problem
Nozir Shokirov
 
Average case Analysis of Quicksort
Average case Analysis of QuicksortAverage case Analysis of Quicksort
Average case Analysis of Quicksort
Rajendran
 
5.5 back track
5.5 back track5.5 back track
5.5 back track
Krish_ver2
 
Subset sum problem Dynamic and Brute Force Approch
Subset sum problem Dynamic and Brute Force ApprochSubset sum problem Dynamic and Brute Force Approch
Subset sum problem Dynamic and Brute Force Approch
Ijlal Ijlal
 
Covering (Rules-based) Algorithm
Covering (Rules-based) AlgorithmCovering (Rules-based) Algorithm
Covering (Rules-based) Algorithm
ZHAO Sam
 
Queue- 8 Queen
Queue- 8 QueenQueue- 8 Queen
Queue- 8 Queen
Ha Ninh
 
Ad

Similar to Dynamic programming in Algorithm Analysis (20)

lecture 23
lecture 23lecture 23
lecture 23
sajinsc
 
AA_Unit 1_part-I.pptx
AA_Unit 1_part-I.pptxAA_Unit 1_part-I.pptx
AA_Unit 1_part-I.pptx
swapnilslide2019
 
Chapter One.pdf
Chapter One.pdfChapter One.pdf
Chapter One.pdf
abay golla
 
Alg_Wks1_2.pdflklokjbhvkv jv .v.vk.hk kv h/k
Alg_Wks1_2.pdflklokjbhvkv jv .v.vk.hk kv h/kAlg_Wks1_2.pdflklokjbhvkv jv .v.vk.hk kv h/k
Alg_Wks1_2.pdflklokjbhvkv jv .v.vk.hk kv h/k
227567
 
complexity analysis.pdf
complexity analysis.pdfcomplexity analysis.pdf
complexity analysis.pdf
pasinduneshan
 
Hash table
Hash tableHash table
Hash table
Rajendran
 
AA_Unit 1_part-II.pdf
AA_Unit 1_part-II.pdfAA_Unit 1_part-II.pdf
AA_Unit 1_part-II.pdf
swapnilslide2019
 
DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptx
NishaS88
 
lecture3.pptlecture3 data structures pptt
lecture3.pptlecture3  data structures ppttlecture3.pptlecture3  data structures pptt
lecture3.pptlecture3 data structures pptt
SyedAliShahid3
 
Lecture 3 insertion sort and complexity analysis
Lecture 3   insertion sort and complexity analysisLecture 3   insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysis
jayavignesh86
 
Matt Purkeypile's Doctoral Dissertation Defense Slides
Matt Purkeypile's Doctoral Dissertation Defense SlidesMatt Purkeypile's Doctoral Dissertation Defense Slides
Matt Purkeypile's Doctoral Dissertation Defense Slides
mpurkeypile
 
Lec1.pptx
Lec1.pptxLec1.pptx
Lec1.pptx
AsadbekIbragimov1
 
Control System Homework Help
Control System Homework HelpControl System Homework Help
Control System Homework Help
Matlab Assignment Experts
 
01 - Analysis of Efficiency.pptx
01 - Analysis of Efficiency.pptx01 - Analysis of Efficiency.pptx
01 - Analysis of Efficiency.pptx
Ishtiaq Rasool Khan
 
Algorithms
AlgorithmsAlgorithms
Algorithms
DevMix
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
Tariq Khan
 
algorithmanalysis and effciency.pptx
algorithmanalysis and effciency.pptxalgorithmanalysis and effciency.pptx
algorithmanalysis and effciency.pptx
ChSreenivasuluReddy
 
2 chapter2 algorithm_analysispart1
2 chapter2 algorithm_analysispart12 chapter2 algorithm_analysispart1
2 chapter2 algorithm_analysispart1
SSE_AndyLi
 
Design & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptxDesign & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptx
JeevaMCSEKIOT
 
Analysis of algo
Analysis of algoAnalysis of algo
Analysis of algo
Sandeep Bhargava
 
lecture 23
lecture 23lecture 23
lecture 23
sajinsc
 
Chapter One.pdf
Chapter One.pdfChapter One.pdf
Chapter One.pdf
abay golla
 
Alg_Wks1_2.pdflklokjbhvkv jv .v.vk.hk kv h/k
Alg_Wks1_2.pdflklokjbhvkv jv .v.vk.hk kv h/kAlg_Wks1_2.pdflklokjbhvkv jv .v.vk.hk kv h/k
Alg_Wks1_2.pdflklokjbhvkv jv .v.vk.hk kv h/k
227567
 
complexity analysis.pdf
complexity analysis.pdfcomplexity analysis.pdf
complexity analysis.pdf
pasinduneshan
 
DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptx
NishaS88
 
lecture3.pptlecture3 data structures pptt
lecture3.pptlecture3  data structures ppttlecture3.pptlecture3  data structures pptt
lecture3.pptlecture3 data structures pptt
SyedAliShahid3
 
Lecture 3 insertion sort and complexity analysis
Lecture 3   insertion sort and complexity analysisLecture 3   insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysis
jayavignesh86
 
Matt Purkeypile's Doctoral Dissertation Defense Slides
Matt Purkeypile's Doctoral Dissertation Defense SlidesMatt Purkeypile's Doctoral Dissertation Defense Slides
Matt Purkeypile's Doctoral Dissertation Defense Slides
mpurkeypile
 
01 - Analysis of Efficiency.pptx
01 - Analysis of Efficiency.pptx01 - Analysis of Efficiency.pptx
01 - Analysis of Efficiency.pptx
Ishtiaq Rasool Khan
 
Algorithms
AlgorithmsAlgorithms
Algorithms
DevMix
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
Tariq Khan
 
algorithmanalysis and effciency.pptx
algorithmanalysis and effciency.pptxalgorithmanalysis and effciency.pptx
algorithmanalysis and effciency.pptx
ChSreenivasuluReddy
 
2 chapter2 algorithm_analysispart1
2 chapter2 algorithm_analysispart12 chapter2 algorithm_analysispart1
2 chapter2 algorithm_analysispart1
SSE_AndyLi
 
Design & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptxDesign & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptx
JeevaMCSEKIOT
 
Ad

More from Rajendran (20)

Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower bounds
Rajendran
 
Scheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsScheduling with Startup and Holding Costs
Scheduling with Startup and Holding Costs
Rajendran
 
Divide and conquer surfing lower bounds
Divide and conquer  surfing lower boundsDivide and conquer  surfing lower bounds
Divide and conquer surfing lower bounds
Rajendran
 
Red black tree
Red black treeRed black tree
Red black tree
Rajendran
 
Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statistics
Rajendran
 
Proof master theorem
Proof master theoremProof master theorem
Proof master theorem
Rajendran
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
Rajendran
 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theorem
Rajendran
 
Master method
Master method Master method
Master method
Rajendran
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
Rajendran
 
Hash tables
Hash tablesHash tables
Hash tables
Rajendran
 
Lower bound
Lower boundLower bound
Lower bound
Rajendran
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
Rajendran
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
Rajendran
 
Longest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisLongest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm Analysis
Rajendran
 
Np completeness
Np completenessNp completeness
Np completeness
Rajendran
 
computer languages
computer languagescomputer languages
computer languages
Rajendran
 
proving non-computability
proving non-computabilityproving non-computability
proving non-computability
Rajendran
 
the halting_problem
the halting_problemthe halting_problem
the halting_problem
Rajendran
 
universality
universalityuniversality
universality
Rajendran
 
Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower bounds
Rajendran
 
Scheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsScheduling with Startup and Holding Costs
Scheduling with Startup and Holding Costs
Rajendran
 
Divide and conquer surfing lower bounds
Divide and conquer  surfing lower boundsDivide and conquer  surfing lower bounds
Divide and conquer surfing lower bounds
Rajendran
 
Red black tree
Red black treeRed black tree
Red black tree
Rajendran
 
Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statistics
Rajendran
 
Proof master theorem
Proof master theoremProof master theorem
Proof master theorem
Rajendran
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
Rajendran
 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theorem
Rajendran
 
Master method
Master method Master method
Master method
Rajendran
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
Rajendran
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
Rajendran
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
Rajendran
 
Longest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisLongest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm Analysis
Rajendran
 
Np completeness
Np completenessNp completeness
Np completeness
Rajendran
 
computer languages
computer languagescomputer languages
computer languages
Rajendran
 
proving non-computability
proving non-computabilityproving non-computability
proving non-computability
Rajendran
 
the halting_problem
the halting_problemthe halting_problem
the halting_problem
Rajendran
 

Recently uploaded (20)

Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
Quiz Club of PSG College of Arts & Science
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
Respiratory System , Urinary System
Respiratory  System , Urinary SystemRespiratory  System , Urinary System
Respiratory System , Urinary System
RushiMandali
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptxCapitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
National Information Standards Organization (NISO)
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle SchoolExploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptxRai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
National Information Standards Organization (NISO)
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
Respiratory System , Urinary System
Respiratory  System , Urinary SystemRespiratory  System , Urinary System
Respiratory System , Urinary System
RushiMandali
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptxCapitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle SchoolExploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 

Dynamic programming in Algorithm Analysis

  • 1. David Luebke 1 CS 332: Algorithms Dynamic Programming
  • 2. David Luebke 2 Review: Amortized Analysis ● To illustrate amortized analysis we examined dynamic tables 1. Init table size m = 1 2. Insert elements until number n > m 3. Generate new table of size 2m 4. Reinsert old elements into new table 5. (back to step 2) ● What is the worst-case cost of an insert? ● What is the amortized cost of an insert?
  • 3. David Luebke 3 Review: Analysis Of Dynamic Tables ● Let ci = cost of ith insert ● ci = i if i-1 is exact power of 2, 1 otherwise ● Example: ■ Operation Table Size Cost Insert(1) 1 1 1 Insert(2) 2 1 + 1 2 Insert(3) 4 1 + 2 Insert(4) 4 1 Insert(5) 8 1 + 4 Insert(6) 8 1 Insert(7) 8 1 Insert(8) 8 1 Insert(9) 16 1 + 8 1 2 3 4 5 6 7 8 9
  • 4. David Luebke 4 Review: Aggregate Analysis ● n Insert() operations cost ● Average cost of operation = (total cost)/(# operations) < 3 ● Asymptotically, then, a dynamic table costs the same as a fixed-size table ■ Both O(1) per Insert operation nnnnc n j j n i i 3)12(2 lg 01 <−+=+≤ ∑∑ ==
  • 5. David Luebke 5 Review: Accounting Analysis ● Charge each operation $3 amortized cost ■ Use $1 to perform immediate Insert() ■ Store $2 ● When table doubles ■ $1 reinserts old item, $1 reinserts another old item ■ We’ve paid these costs up front with the last n/2 Insert()s ● Upshot: O(1) amortized cost per operation
  • 6. David Luebke 6 Review: Accounting Analysis ● Suppose must support insert & delete, table should contract as well as expand ■ Table overflows ⇒ double it (as before) ■ Table < 1/4 full ⇒ halve it ■ Charge $3 for Insert (as before) ■ Charge $2 for Delete ○ Store extra $1 in emptied slot ○ Use later to pay to copy remaining items to new table when shrinking table ● What if we halve size when table < 1/8 full?
  • 7. David Luebke 7 Dynamic Programming ● Another strategy for designing algorithms is dynamic programming ■ A metatechnique, not an algorithm (like divide & conquer) ■ The word “programming” is historical and predates computer programming ● Use when problem breaks down into recurring small subproblems
  • 8. David Luebke 8 Dynamic Programming Example: Longest Common Subsequence ● Longest common subsequence (LCS) problem: ■ Given two sequences x[1..m] and y[1..n], find the longest subsequence which occurs in both ■ Ex: x = {A B C B D A B }, y = {B D C A B A} ■ {B C} and {A A} are both subsequences of both ○ What is the LCS? ■ Brute-force algorithm: For every subsequence of x, check if it’s a subsequence of y ○ How many subsequences of x are there? ○ What will be the running time of the brute-force alg?
  • 9. David Luebke 9 LCS Algorithm ● Brute-force algorithm: 2m subsequences of x to check against n elements of y: O(n 2m ) ● We can do better: for now, let’s only worry about the problem of finding the length of LCS ■ When finished we will see how to backtrack from this solution back to the actual LCS ● Notice LCS problem has optimal substructure ■ Subproblems: LCS of pairs of prefixes of x and y
  • 10. David Luebke 10 Finding LCS Length ● Define c[i,j] to be the length of the LCS of x[1..i] and y[1..j] ■ What is the length of LCS of x and y? ● Theorem: ● What is this really saying?    −− =+−− = otherwise]),1[],1,[max( ],[][if1]1,1[ ],[ jicjic jyixjic jic