際際滷

際際滷Share a Scribd company logo
HOPEFULLY
SORT OF
INTERESTING
ALGO TALK
Lunch and Learn
12.01.2016
Big-O
Big-O
Operations
for 10
things
Operations
for 100
things
(1) 1 1
(log ) 3 7
() 10 100
( log ) 30 700
(2) 100 10000
(2 ) 1024 2^100
(!) 3628800 100!
Dynamic Programming
 Break a problem down into sub-problems
 Store the results to avoid computing again
Two main components
 Optimal substructure
 Overlapping sub-problems
Fibonacci Sequence (2 )
function fib(n)
if n <= 1 return n
return fib(n  1) + fib(n  2)
How many statements do we need to
compute ()?
Prove that () can be solved in   time,
where  > 1.
Solve for  using quadratic formula
 =
+ 

fib(1) = 1
fib(n) = fib(n-1) + fib(n-2)
an  a(n-1) + a(n-2)
a2  a + 1
+ 

 1.62, which satisfies a2 = 1 + 1
Top-down and Bottom-up ()
var m := map(0  0, 1  1)
function fib(n)
if key n is not in map m
m[n] := fib(n  1) + fib(n  2)
return m[n]
Top-down (Memoization) Bottom-up
function fib(n)
if n = 0
return 0
else
var previousFib := 0, currentFib := 1
repeat n  1 times // loop is skipped if n = 1
var nextFib := previousFib + currentFib
previousFib := currentFib
currentFib := nextFib
return currentFib
Hyphenation and Justification ( )
If a paragraph contains  possible breakpoints, the number of
situations that must be evaluated naively is 2  since any two
consecutive words may get split up by a break.
Knuth-Plass Algorithm
Considers a paragraph to be a sequence 1, 2,  .   of  items, where each item ヰ
is either a box, a glue, or a penalty specification.
Knuth-Plass Algorithm (cont.)
Box: Width of the box: i, some  representing the space occupied by the box.
Glue: Three  of importance:
ゐ is the ideal or normal width
 is the stretchability
ю is the shrinkability
Penalty: Potential places to end of
line and begin another.
 Certain aesthetic cost
 High  indicates poor place to break, negative  indicates a good place to break
 Uses ゐ to represent width added to the line just before the break occurs
Knuth-Plass Algorithm (cont.)
Demerits: measures the badness of fit
Badness is the amount of stretching or
shrinking.
Knuth-Plass Algorithm (cont.)
Calculating demerits
adjustment = available width - text width
If adjustment <= 0
adj ratio = adj 歎 avl shk
If adjustment > 0
adj ratio = adj 歎 avl str
badness = |adj ratio|3  100 + 0揃5
Knuth-Plass Algorithm (cont.)
Goals:
Minimize $ of each line
Dynamic programming comes into play
1) Scan line for breaking opportunities
2) At each opportunity, look at prior
opportunities
3) Consider a candidate line between these
two opportunities
4) Compute the demerits of this line candidate
5) Select the line candidate with the minimum
demerits
Knuth-Plass Algorithm (cont.)
https://github.com/bramstein/typeset/blob/mast
er/src/linebreak.js
Greedy Algorithm
The Knuth-Plass algorithm will almost always be more pleasing to look at, because
the Greedy Algorithm may leave too much whitespace at the end of a line.
Still, the lighter runtime cost of running Greedy () vs Knuth-Plasss (2) is why
most modern browsers will use the Greedy algorithm.
SpaceLeft := LineWidth
for each Word in Text
if (Width(Word) + SpaceWidth) > SpaceLeft
insert line break before Word in Text
SpaceLeft := LineWidth - Width(Word)
else
SpaceLeft := SpaceLeft - (Width(Word) + SpaceWidth)
P vs NP
The general class of questions for which some algorithm can provide an answer in
polynomial time is called "class P" or just "P
The class of questions for which an answer can be verified in polynomial time is called
NP, which stands for "nondeterministic polynomial time.
An answer to the P = NP question would determine whether problems that can be
verified in polynomial time can also be solved in polynomial time.
Turing Machines
A Turing Machine can do everything that a real computer can do.
The Turing Machine model contains these things:
 an infinite tape as its unlimited memory
 a tape head that can read and write symbols and move around the tape
M1 = On input string w:
1. Sweep left to right across the tape, crossing off every other 0.
2. If in stage 1 the tape contained a single 0, accept.
3. If in stage 1 the tape contained more than a single 0 and the number of 0s was odd, reject
4. Return the head to the left-hand end of the tape.
5. Go to stage 1.
Turing Machines (cont.)
M1 = On input string w:
1. Sweep left to right across the tape, crossing off every other 0.
2. If in stage 1 the tape contained a single 0, accept.
3. If in stage 1 the tape contained more than a single 0 and the number of 0s was
odd, reject
4. Return the head to the left-hand end of the tape.
5. Go to stage 1.
M1 decides  = {02

|   0}, the language consisting of all strings of 0s whose
length is a power of 2.
Turing Machines and Big-O
M2 = On input string w:
1. Scan across the tape and reject if a 0 is found to the right of a 1.
2. Repeat if both 0s and 1s remain on the tape:
3. Scan across the tape, crossing off a single 0 and a single 1.
4. If 0s still remain after all the 1st have been crossed off, or if 1s still remain after all
the 0s have been crossed off, reject. Else, if neither 0s nor 1s remain on the tape,
accept.
M2 decides  = {0

1

|   0}, the language consisting of all strings of  0s followed
by  1s.
Thank you

More Related Content

What's hot (20)

Solving 0-1 knapsack problems based on amoeboid organism algorithm
Solving 0-1 knapsack problems based on amoeboid organism algorithmSolving 0-1 knapsack problems based on amoeboid organism algorithm
Solving 0-1 knapsack problems based on amoeboid organism algorithm
juanjo_23
Ms nikita greedy agorithm
Ms nikita greedy agorithmMs nikita greedy agorithm
Ms nikita greedy agorithm
Nikitagupta123
25 String Matching
25 String Matching25 String Matching
25 String Matching
Andres Mendez-Vazquez
4 greedy methodnew
4 greedy methodnew4 greedy methodnew
4 greedy methodnew
abhinav108
A greedy algorithms
A greedy algorithmsA greedy algorithms
A greedy algorithms
Amit Kumar Rathi
G6 m2-d-lesson 19-t
G6 m2-d-lesson 19-tG6 m2-d-lesson 19-t
G6 m2-d-lesson 19-t
mlabuski
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
Rajendran
Daa unit 3
Daa unit 3Daa unit 3
Daa unit 3
Abhimanyu Mishra
Greedy method1
Greedy method1Greedy method1
Greedy method1
Rajendran
Greedy method by Dr. B. J. Mohite
Greedy method by Dr. B. J. MohiteGreedy method by Dr. B. J. Mohite
Greedy method by Dr. B. J. Mohite
Zeal Education Society, Pune
Greedy method
Greedy method Greedy method
Greedy method
Dr Shashikant Athawale
Problem set3 | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
Problem set3 | Theory of Computation | Akash Anand | MTH 401A | IIT KanpurProblem set3 | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
Problem set3 | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
Vivekananda Samiti
Business Logistics Assignment Help
Business Logistics Assignment HelpBusiness Logistics Assignment Help
Business Logistics Assignment Help
Statistics Homework Helper
Assignment 2 daa
Assignment 2 daaAssignment 2 daa
Assignment 2 daa
gaurav201196
L06
L06L06
L06
Saurav Rahman
Support Vector Machine
Support Vector MachineSupport Vector Machine
Support Vector Machine
Shao-Chuan Wang
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
Madhu Bala
Back tracking
Back trackingBack tracking
Back tracking
Keshav Memorial Institute of Technology
Svm V SVC
Svm V SVCSvm V SVC
Svm V SVC
AMR koura
Greedy algorithm activity selection fractional
Greedy algorithm activity selection fractionalGreedy algorithm activity selection fractional
Greedy algorithm activity selection fractional
Amit Kumar Rathi
Solving 0-1 knapsack problems based on amoeboid organism algorithm
Solving 0-1 knapsack problems based on amoeboid organism algorithmSolving 0-1 knapsack problems based on amoeboid organism algorithm
Solving 0-1 knapsack problems based on amoeboid organism algorithm
juanjo_23
Ms nikita greedy agorithm
Ms nikita greedy agorithmMs nikita greedy agorithm
Ms nikita greedy agorithm
Nikitagupta123
4 greedy methodnew
4 greedy methodnew4 greedy methodnew
4 greedy methodnew
abhinav108
G6 m2-d-lesson 19-t
G6 m2-d-lesson 19-tG6 m2-d-lesson 19-t
G6 m2-d-lesson 19-t
mlabuski
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
Rajendran
Greedy method1
Greedy method1Greedy method1
Greedy method1
Rajendran
Problem set3 | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
Problem set3 | Theory of Computation | Akash Anand | MTH 401A | IIT KanpurProblem set3 | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
Problem set3 | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
Vivekananda Samiti
Assignment 2 daa
Assignment 2 daaAssignment 2 daa
Assignment 2 daa
gaurav201196
Support Vector Machine
Support Vector MachineSupport Vector Machine
Support Vector Machine
Shao-Chuan Wang
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
Madhu Bala
Svm V SVC
Svm V SVCSvm V SVC
Svm V SVC
AMR koura
Greedy algorithm activity selection fractional
Greedy algorithm activity selection fractionalGreedy algorithm activity selection fractional
Greedy algorithm activity selection fractional
Amit Kumar Rathi

Similar to Dynamic Programming - Laughlin Lunch and Learn (20)

Introduction
IntroductionIntroduction
Introduction
Gopi Saiteja
Limits of Computation
Limits of ComputationLimits of Computation
Limits of Computation
Joshua Reuben
The Limits of Computation
The Limits of ComputationThe Limits of Computation
The Limits of Computation
Joshua Reuben
Unit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdf
Unit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdfUnit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdf
Unit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdf
yashodamb
Linear Programming- Leacture-16-lp1.pptx
Linear Programming- Leacture-16-lp1.pptxLinear Programming- Leacture-16-lp1.pptx
Linear Programming- Leacture-16-lp1.pptx
SarahKoech1
design and analysis of algorithm
design and analysis of algorithmdesign and analysis of algorithm
design and analysis of algorithm
Muhammad Arish
Acm aleppo cpc training fifth session
Acm aleppo cpc training fifth sessionAcm aleppo cpc training fifth session
Acm aleppo cpc training fifth session
Ahmad Bashar Eter
Mit6 006 f11_quiz1
Mit6 006 f11_quiz1Mit6 006 f11_quiz1
Mit6 006 f11_quiz1
Sandeep Jindal
9. chapter 8 np hard and np complete problems
9. chapter 8   np hard and np complete problems9. chapter 8   np hard and np complete problems
9. chapter 8 np hard and np complete problems
Jyotsna Suryadevara
Beyond Floating Point Next Generation Computer Arithmetic
Beyond Floating Point  Next Generation Computer ArithmeticBeyond Floating Point  Next Generation Computer Arithmetic
Beyond Floating Point Next Generation Computer Arithmetic
inside-BigData.com
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWERUndecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
muthukrishnavinayaga
Analysis and design of algorithms part 4
Analysis and design of algorithms part 4Analysis and design of algorithms part 4
Analysis and design of algorithms part 4
Deepak John
Programming Exam Help
Programming Exam Help Programming Exam Help
Programming Exam Help
Programming Exam Help
Undecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation AlgorithmsUndecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation Algorithms
Muthu Vinayagam
Computer Science Exam Help
Computer Science Exam Help Computer Science Exam Help
Computer Science Exam Help
Programming Exam Help
36 greedy
36 greedy36 greedy
36 greedy
Ikram Khan
1
11
1
EasyStudy3
NP completeness
NP completenessNP completeness
NP completeness
Amrinder Arora
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
Programming Homework Help
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
Fahim Ferdous
Limits of Computation
Limits of ComputationLimits of Computation
Limits of Computation
Joshua Reuben
The Limits of Computation
The Limits of ComputationThe Limits of Computation
The Limits of Computation
Joshua Reuben
Unit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdf
Unit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdfUnit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdf
Unit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdf
yashodamb
Linear Programming- Leacture-16-lp1.pptx
Linear Programming- Leacture-16-lp1.pptxLinear Programming- Leacture-16-lp1.pptx
Linear Programming- Leacture-16-lp1.pptx
SarahKoech1
design and analysis of algorithm
design and analysis of algorithmdesign and analysis of algorithm
design and analysis of algorithm
Muhammad Arish
Acm aleppo cpc training fifth session
Acm aleppo cpc training fifth sessionAcm aleppo cpc training fifth session
Acm aleppo cpc training fifth session
Ahmad Bashar Eter
9. chapter 8 np hard and np complete problems
9. chapter 8   np hard and np complete problems9. chapter 8   np hard and np complete problems
9. chapter 8 np hard and np complete problems
Jyotsna Suryadevara
Beyond Floating Point Next Generation Computer Arithmetic
Beyond Floating Point  Next Generation Computer ArithmeticBeyond Floating Point  Next Generation Computer Arithmetic
Beyond Floating Point Next Generation Computer Arithmetic
inside-BigData.com
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWERUndecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
muthukrishnavinayaga
Analysis and design of algorithms part 4
Analysis and design of algorithms part 4Analysis and design of algorithms part 4
Analysis and design of algorithms part 4
Deepak John
Undecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation AlgorithmsUndecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation Algorithms
Muthu Vinayagam
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
Fahim Ferdous

Recently uploaded (20)

It's a great presentation for everything
It's a great presentation for everythingIt's a great presentation for everything
It's a great presentation for everything
NonalynMagdagasang1
Isaiah Scudder Dealing with Stress.pptx
Isaiah Scudder  Dealing with Stress.pptxIsaiah Scudder  Dealing with Stress.pptx
Isaiah Scudder Dealing with Stress.pptx
FamilyWorshipCenterD
Defining what is or is not academic writing.pptx
Defining what is or is not academic writing.pptxDefining what is or is not academic writing.pptx
Defining what is or is not academic writing.pptx
bluerosedreamland
Heraldry Gold's Whiteburn Gold Project (PDAC, March 2025)
Heraldry Gold's Whiteburn Gold Project (PDAC, March 2025)Heraldry Gold's Whiteburn Gold Project (PDAC, March 2025)
Heraldry Gold's Whiteburn Gold Project (PDAC, March 2025)
RonHawkes1
Arts of Tajikistan_20250302_183038_0000.pdf
Arts of Tajikistan_20250302_183038_0000.pdfArts of Tajikistan_20250302_183038_0000.pdf
Arts of Tajikistan_20250302_183038_0000.pdf
raffypro11
JARINZO TANABATAS SIX CAPITAL FORCES: A FRAMEWORK FOR STRATEGIC ADVANTAGE
JARINZO TANABATAS SIX CAPITAL FORCES: A FRAMEWORK FOR STRATEGIC ADVANTAGEJARINZO TANABATAS SIX CAPITAL FORCES: A FRAMEWORK FOR STRATEGIC ADVANTAGE
JARINZO TANABATAS SIX CAPITAL FORCES: A FRAMEWORK FOR STRATEGIC ADVANTAGE
Jarinzo Tanabata
Your paragraph text_20250307_191630_0000.pdf
Your paragraph text_20250307_191630_0000.pdfYour paragraph text_20250307_191630_0000.pdf
Your paragraph text_20250307_191630_0000.pdf
jatv64344
Profisee - HIMSS workshop - Mar 2025 - final.pptx
Profisee - HIMSS workshop - Mar 2025 - final.pptxProfisee - HIMSS workshop - Mar 2025 - final.pptx
Profisee - HIMSS workshop - Mar 2025 - final.pptx
Profisee
TRADE PROMOTION UNIT action plan version 3.pptx
TRADE PROMOTION UNIT action plan version 3.pptxTRADE PROMOTION UNIT action plan version 3.pptx
TRADE PROMOTION UNIT action plan version 3.pptx
SupunLiyanage5
Steven Nickel Seeing God 3.09.2025.pptx
Steven  Nickel Seeing God 3.09.2025.pptxSteven  Nickel Seeing God 3.09.2025.pptx
Steven Nickel Seeing God 3.09.2025.pptx
FamilyWorshipCenterD
AI in Parliaments: Strategic Opportunities and Challenges
AI in Parliaments: Strategic Opportunities and ChallengesAI in Parliaments: Strategic Opportunities and Challenges
AI in Parliaments: Strategic Opportunities and Challenges
Dr. Fotios Fitsilis
day 4- w3-q4 ppt FACTORS THAT AFFECT WEATHER CLIMATE
day 4- w3-q4 ppt FACTORS THAT AFFECT WEATHER CLIMATEday 4- w3-q4 ppt FACTORS THAT AFFECT WEATHER CLIMATE
day 4- w3-q4 ppt FACTORS THAT AFFECT WEATHER CLIMATE
MefetchMoevaGumahad
2025-03-02 FATC 01 Annas, Caiaphas & The Sanhedrin (shared slides).pptx
2025-03-02 FATC 01 Annas, Caiaphas & The Sanhedrin (shared slides).pptx2025-03-02 FATC 01 Annas, Caiaphas & The Sanhedrin (shared slides).pptx
2025-03-02 FATC 01 Annas, Caiaphas & The Sanhedrin (shared slides).pptx
Dale Wells
Grey's Anatomy Trivia - The Coffee Parlor
Grey's Anatomy Trivia - The Coffee ParlorGrey's Anatomy Trivia - The Coffee Parlor
Grey's Anatomy Trivia - The Coffee Parlor
sdwebb2000
Science Communication beyond Journal Publications Workshop
Science Communication beyond Journal Publications WorkshopScience Communication beyond Journal Publications Workshop
Science Communication beyond Journal Publications Workshop
WAIHIGA K.MUTURI
Mavi Gradyan Profesyonel Kurumsal Sunum (1).pdf
Mavi Gradyan Profesyonel Kurumsal Sunum (1).pdfMavi Gradyan Profesyonel Kurumsal Sunum (1).pdf
Mavi Gradyan Profesyonel Kurumsal Sunum (1).pdf
efeaudal4599
KCS Whitepaper - A Blockchain-Based Value Self-Circulation Ecosystem
KCS Whitepaper - A Blockchain-Based Value Self-Circulation EcosystemKCS Whitepaper - A Blockchain-Based Value Self-Circulation Ecosystem
KCS Whitepaper - A Blockchain-Based Value Self-Circulation Ecosystem
KuCoin - Exchange
SEO Myths You Should Stop Believing in 2025.pdf
SEO Myths You Should Stop Believing in 2025.pdfSEO Myths You Should Stop Believing in 2025.pdf
SEO Myths You Should Stop Believing in 2025.pdf
Md Emran Hossain
Johari window introduction to identifying the personality attributes
Johari window introduction to identifying the personality attributesJohari window introduction to identifying the personality attributes
Johari window introduction to identifying the personality attributes
yogitabharatmandhany
Cerino Four Seasons 300th Anniversary x China
Cerino Four Seasons 300th Anniversary x ChinaCerino Four Seasons 300th Anniversary x China
Cerino Four Seasons 300th Anniversary x China
Marco Acerbi
It's a great presentation for everything
It's a great presentation for everythingIt's a great presentation for everything
It's a great presentation for everything
NonalynMagdagasang1
Isaiah Scudder Dealing with Stress.pptx
Isaiah Scudder  Dealing with Stress.pptxIsaiah Scudder  Dealing with Stress.pptx
Isaiah Scudder Dealing with Stress.pptx
FamilyWorshipCenterD
Defining what is or is not academic writing.pptx
Defining what is or is not academic writing.pptxDefining what is or is not academic writing.pptx
Defining what is or is not academic writing.pptx
bluerosedreamland
Heraldry Gold's Whiteburn Gold Project (PDAC, March 2025)
Heraldry Gold's Whiteburn Gold Project (PDAC, March 2025)Heraldry Gold's Whiteburn Gold Project (PDAC, March 2025)
Heraldry Gold's Whiteburn Gold Project (PDAC, March 2025)
RonHawkes1
Arts of Tajikistan_20250302_183038_0000.pdf
Arts of Tajikistan_20250302_183038_0000.pdfArts of Tajikistan_20250302_183038_0000.pdf
Arts of Tajikistan_20250302_183038_0000.pdf
raffypro11
JARINZO TANABATAS SIX CAPITAL FORCES: A FRAMEWORK FOR STRATEGIC ADVANTAGE
JARINZO TANABATAS SIX CAPITAL FORCES: A FRAMEWORK FOR STRATEGIC ADVANTAGEJARINZO TANABATAS SIX CAPITAL FORCES: A FRAMEWORK FOR STRATEGIC ADVANTAGE
JARINZO TANABATAS SIX CAPITAL FORCES: A FRAMEWORK FOR STRATEGIC ADVANTAGE
Jarinzo Tanabata
Your paragraph text_20250307_191630_0000.pdf
Your paragraph text_20250307_191630_0000.pdfYour paragraph text_20250307_191630_0000.pdf
Your paragraph text_20250307_191630_0000.pdf
jatv64344
Profisee - HIMSS workshop - Mar 2025 - final.pptx
Profisee - HIMSS workshop - Mar 2025 - final.pptxProfisee - HIMSS workshop - Mar 2025 - final.pptx
Profisee - HIMSS workshop - Mar 2025 - final.pptx
Profisee
TRADE PROMOTION UNIT action plan version 3.pptx
TRADE PROMOTION UNIT action plan version 3.pptxTRADE PROMOTION UNIT action plan version 3.pptx
TRADE PROMOTION UNIT action plan version 3.pptx
SupunLiyanage5
Steven Nickel Seeing God 3.09.2025.pptx
Steven  Nickel Seeing God 3.09.2025.pptxSteven  Nickel Seeing God 3.09.2025.pptx
Steven Nickel Seeing God 3.09.2025.pptx
FamilyWorshipCenterD
AI in Parliaments: Strategic Opportunities and Challenges
AI in Parliaments: Strategic Opportunities and ChallengesAI in Parliaments: Strategic Opportunities and Challenges
AI in Parliaments: Strategic Opportunities and Challenges
Dr. Fotios Fitsilis
day 4- w3-q4 ppt FACTORS THAT AFFECT WEATHER CLIMATE
day 4- w3-q4 ppt FACTORS THAT AFFECT WEATHER CLIMATEday 4- w3-q4 ppt FACTORS THAT AFFECT WEATHER CLIMATE
day 4- w3-q4 ppt FACTORS THAT AFFECT WEATHER CLIMATE
MefetchMoevaGumahad
2025-03-02 FATC 01 Annas, Caiaphas & The Sanhedrin (shared slides).pptx
2025-03-02 FATC 01 Annas, Caiaphas & The Sanhedrin (shared slides).pptx2025-03-02 FATC 01 Annas, Caiaphas & The Sanhedrin (shared slides).pptx
2025-03-02 FATC 01 Annas, Caiaphas & The Sanhedrin (shared slides).pptx
Dale Wells
Grey's Anatomy Trivia - The Coffee Parlor
Grey's Anatomy Trivia - The Coffee ParlorGrey's Anatomy Trivia - The Coffee Parlor
Grey's Anatomy Trivia - The Coffee Parlor
sdwebb2000
Science Communication beyond Journal Publications Workshop
Science Communication beyond Journal Publications WorkshopScience Communication beyond Journal Publications Workshop
Science Communication beyond Journal Publications Workshop
WAIHIGA K.MUTURI
Mavi Gradyan Profesyonel Kurumsal Sunum (1).pdf
Mavi Gradyan Profesyonel Kurumsal Sunum (1).pdfMavi Gradyan Profesyonel Kurumsal Sunum (1).pdf
Mavi Gradyan Profesyonel Kurumsal Sunum (1).pdf
efeaudal4599
KCS Whitepaper - A Blockchain-Based Value Self-Circulation Ecosystem
KCS Whitepaper - A Blockchain-Based Value Self-Circulation EcosystemKCS Whitepaper - A Blockchain-Based Value Self-Circulation Ecosystem
KCS Whitepaper - A Blockchain-Based Value Self-Circulation Ecosystem
KuCoin - Exchange
SEO Myths You Should Stop Believing in 2025.pdf
SEO Myths You Should Stop Believing in 2025.pdfSEO Myths You Should Stop Believing in 2025.pdf
SEO Myths You Should Stop Believing in 2025.pdf
Md Emran Hossain
Johari window introduction to identifying the personality attributes
Johari window introduction to identifying the personality attributesJohari window introduction to identifying the personality attributes
Johari window introduction to identifying the personality attributes
yogitabharatmandhany
Cerino Four Seasons 300th Anniversary x China
Cerino Four Seasons 300th Anniversary x ChinaCerino Four Seasons 300th Anniversary x China
Cerino Four Seasons 300th Anniversary x China
Marco Acerbi

Dynamic Programming - Laughlin Lunch and Learn

  • 2. Big-O Big-O Operations for 10 things Operations for 100 things (1) 1 1 (log ) 3 7 () 10 100 ( log ) 30 700 (2) 100 10000 (2 ) 1024 2^100 (!) 3628800 100!
  • 3. Dynamic Programming Break a problem down into sub-problems Store the results to avoid computing again Two main components Optimal substructure Overlapping sub-problems
  • 4. Fibonacci Sequence (2 ) function fib(n) if n <= 1 return n return fib(n 1) + fib(n 2) How many statements do we need to compute ()? Prove that () can be solved in time, where > 1. Solve for using quadratic formula = + fib(1) = 1 fib(n) = fib(n-1) + fib(n-2) an a(n-1) + a(n-2) a2 a + 1 + 1.62, which satisfies a2 = 1 + 1
  • 5. Top-down and Bottom-up () var m := map(0 0, 1 1) function fib(n) if key n is not in map m m[n] := fib(n 1) + fib(n 2) return m[n] Top-down (Memoization) Bottom-up function fib(n) if n = 0 return 0 else var previousFib := 0, currentFib := 1 repeat n 1 times // loop is skipped if n = 1 var nextFib := previousFib + currentFib previousFib := currentFib currentFib := nextFib return currentFib
  • 6. Hyphenation and Justification ( ) If a paragraph contains possible breakpoints, the number of situations that must be evaluated naively is 2 since any two consecutive words may get split up by a break.
  • 7. Knuth-Plass Algorithm Considers a paragraph to be a sequence 1, 2, . of items, where each item ヰ is either a box, a glue, or a penalty specification.
  • 8. Knuth-Plass Algorithm (cont.) Box: Width of the box: i, some representing the space occupied by the box. Glue: Three of importance: ゐ is the ideal or normal width is the stretchability ю is the shrinkability Penalty: Potential places to end of line and begin another. Certain aesthetic cost High indicates poor place to break, negative indicates a good place to break Uses ゐ to represent width added to the line just before the break occurs
  • 9. Knuth-Plass Algorithm (cont.) Demerits: measures the badness of fit Badness is the amount of stretching or shrinking.
  • 10. Knuth-Plass Algorithm (cont.) Calculating demerits adjustment = available width - text width If adjustment <= 0 adj ratio = adj 歎 avl shk If adjustment > 0 adj ratio = adj 歎 avl str badness = |adj ratio|3 100 + 0揃5
  • 11. Knuth-Plass Algorithm (cont.) Goals: Minimize $ of each line Dynamic programming comes into play 1) Scan line for breaking opportunities 2) At each opportunity, look at prior opportunities 3) Consider a candidate line between these two opportunities 4) Compute the demerits of this line candidate 5) Select the line candidate with the minimum demerits
  • 13. Greedy Algorithm The Knuth-Plass algorithm will almost always be more pleasing to look at, because the Greedy Algorithm may leave too much whitespace at the end of a line. Still, the lighter runtime cost of running Greedy () vs Knuth-Plasss (2) is why most modern browsers will use the Greedy algorithm. SpaceLeft := LineWidth for each Word in Text if (Width(Word) + SpaceWidth) > SpaceLeft insert line break before Word in Text SpaceLeft := LineWidth - Width(Word) else SpaceLeft := SpaceLeft - (Width(Word) + SpaceWidth)
  • 14. P vs NP The general class of questions for which some algorithm can provide an answer in polynomial time is called "class P" or just "P The class of questions for which an answer can be verified in polynomial time is called NP, which stands for "nondeterministic polynomial time. An answer to the P = NP question would determine whether problems that can be verified in polynomial time can also be solved in polynomial time.
  • 15. Turing Machines A Turing Machine can do everything that a real computer can do. The Turing Machine model contains these things: an infinite tape as its unlimited memory a tape head that can read and write symbols and move around the tape M1 = On input string w: 1. Sweep left to right across the tape, crossing off every other 0. 2. If in stage 1 the tape contained a single 0, accept. 3. If in stage 1 the tape contained more than a single 0 and the number of 0s was odd, reject 4. Return the head to the left-hand end of the tape. 5. Go to stage 1.
  • 16. Turing Machines (cont.) M1 = On input string w: 1. Sweep left to right across the tape, crossing off every other 0. 2. If in stage 1 the tape contained a single 0, accept. 3. If in stage 1 the tape contained more than a single 0 and the number of 0s was odd, reject 4. Return the head to the left-hand end of the tape. 5. Go to stage 1. M1 decides = {02 | 0}, the language consisting of all strings of 0s whose length is a power of 2.
  • 17. Turing Machines and Big-O M2 = On input string w: 1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Repeat if both 0s and 1s remain on the tape: 3. Scan across the tape, crossing off a single 0 and a single 1. 4. If 0s still remain after all the 1st have been crossed off, or if 1s still remain after all the 0s have been crossed off, reject. Else, if neither 0s nor 1s remain on the tape, accept. M2 decides = {0 1 | 0}, the language consisting of all strings of 0s followed by 1s.