Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt

Slides:



Advertisements
Similar presentations
Multiplying Matrices Two matrices, A with (p x q) matrix and B with (q x r) matrix, can be multiplied to get C with dimensions p x r, using scalar multiplications.
Advertisements

Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Dr. Sumanta Guha Slide Sources: CLRS “Intro.
Comp 122, Fall 2004 Dynamic Programming. dynprog - 2 Lin / Devi Comp 122, Spring 2004 Longest Common Subsequence  Problem: Given 2 sequences, X =  x.
Dynamic Programming Lets begin by looking at the Fibonacci sequence.
CPSC 311, Fall 2009: Dynamic Programming 1 CPSC 311 Analysis of Algorithms Dynamic Programming Prof. Jennifer Welch Fall 2009.
Dynamic Programming Code
CPSC 411 Design and Analysis of Algorithms Set 5: Dynamic Programming Prof. Jennifer Welch Spring 2011 CPSC 411, Spring 2011: Set 5 1.
1 Dynamic Programming Andreas Klappenecker [based on slides by Prof. Welch]
Optimal binary search trees
11-1 Matrix-chain Multiplication Suppose we have a sequence or chain A 1, A 2, …, A n of n matrices to be multiplied –That is, we want to compute the product.
CS 5243: Algorithms Dynamic Programming Dynamic Programming is applicable when sub-problems are dependent! In the case of Divide and Conquer they are.
Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Prof. Sumanta Guha Slide Sources: CLRS “Intro.
Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Prof. Sumanta Guha Slide Sources: CLRS “Intro.
Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Prof. Sumanta Guha Slide Sources: CLRS “Intro.
Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Prof. Sumanta Guha Slide Sources: CLRS “Intro.
Chapter 15 Dynamic Programming Lee, Hsiu-Hui Ack: This presentation is based on the lecture slides from Hsu, Lih-Hsing, as well as various materials from.
Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Prof. Sumanta Guha Slide Sources: CLRS “Intro.
Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Prof. Sumanta Guha Slide Sources: CLRS “Intro.
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Dynamic Programming Typically applied to optimization problems
Dynamic Programming (DP)
Merge Sort 5/28/2018 9:55 AM Dynamic Programming Dynamic Programming.
Lecture 5 Dynamic Programming
Dynamic Programming (DP)
Advanced Algorithms Analysis and Design
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Advanced Algorithms Analysis and Design
Chapter 8 Dynamic Programming
Matrix Chain Multiplication
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Dynamic programming techniques
Dynamic programming techniques
Lecture 5 Dynamic Programming
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Dynamic Programming Several problems Principle of dynamic programming
Chapter 8 Dynamic Programming.
Dynamic Programming Comp 122, Fall 2004.
CSCE 411 Design and Analysis of Algorithms
Matrix Chain Multiplication
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Chapter 15: Dynamic Programming III
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
ICS 353: Design and Analysis of Algorithms
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
A brief introduction to Dynamic Programming
Advanced Algorithms Analysis and Design
Dynamic Programming.
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Data Structure and Algorithms
Dynamic Programming Comp 122, Fall 2004.
Lecture 8. Paradigm #6 Dynamic Programming
Ch. 15: Dynamic Programming Ming-Te Chi
Dynamic Programming-- Longest Common Subsequence
DYNAMIC PROGRAMMING.
COMP108 Algorithmic Foundations Dynamic Programming
Dynamic Programming II DP over Intervals
Matrix Chain Product 張智星 (Roger Jang)
Advanced Analysis of Algorithms
Matrix Chain Multiplication
CSCI 235, Spring 2019, Lecture 25 Dynamic Programming
Algorithms CSCI 235, Spring 2019 Lecture 27 Dynamic Programming II
Asst. Prof. Dr. İlker Kocabaş
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Analysis of Algorithms CS 477/677
Data Structures and Algorithms Dynamic Programming
Optimal Binary Search Tree. 1.Preface  OBST is one special kind of advanced tree.  It focus on how to reduce the cost of the search of the BST.  It.
Presentation transcript:

Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Prof. Sumanta Guha Slide Sources: CLRS “Intro. To Algorithms” book website (copyright McGraw Hill) adapted and supplemented

CLRS “Intro. To Algorithms” Ch. 15: Dynamic Programming

What is the brute-force, i. e What is the brute-force, i.e., exhaustive method, to solve the problem? What is its running time?

fi[j] = fastest possible time from start through station Si,j Fastest time to completion = f* = min{ f1[n] + x1, f2[n] + x2 } f1[j] = e1 + a1,1 if j = 1 min( f1[j-1] + a1,j , f2[j-1] + t2,j-1 + a1,j ) if j > 1 Similar equation for f2[j]. What’s the problem with a recursive algorithm based on these formulae? Think of the Fibonacci numbers!

Idea is to fill out the tables of f1, f2, l1 and l2. Linear time! Ques: How does PRINT-STATIONS work?

Straight-forward matrix multiplication: if A is p  q and B is q  r then C is p  r and requires pqr scalar multiplications to compute. Consider 3 matrices A1 (size 10  100), A2 (size 100  5) and A3 (size 5  50). There are two ways to compute the product A1A2A3: (A1A2)A3 = A1(A2A3) Ques: Is the complexity in terms of the number scalar of multiplications the same? Matrix-chain multiplication problem: Given a chain A1, A2, …, An of n matrices, where matrix Ai has size pi-1  pi, fully parenthesize the product A1A2…An in a way that minimizes the number of scalar multiplications. Note: There are exponentially many ways to fully parenthesize the product so an exhaustive solution is infeasible.

Let Ai..j for the product matrix AiAi+1…Aj, where i ≤ j. Let m[i,j] be the minimum number of scalar multiplications to compute Ai..j. The problem is to find m[1,n]. Now, m[i,j] = 0 if i = j mini≤k<j { m[i,k] + m[k+1,j] + pi-1pkpj } if i < j Ques: What would be the performance of a recursive algorithm based on this formula?

Ex. 15.2-1

Optimal Binary Search Trees 0.1x1 0.15x2 0.1x2 0.05x3 0.2x3 0.05x3 0.1x3 0.05x4 0.05x4 0.05x4 0.1x4 Cost of node in red: total cost 2.80 ki are keys (k1 < k2 < … < k5), di are dummy values representing “space between” keys k-i and ki+1. Check the expected search cost of the two trees! ←probability of ki ←probability of di

Finding a Recursive Solution through Dynamic Programming Critical Observation: If an optimal BST T has a subtree T’ containing keys ki, …, kj, then this must be the optimal BST for the subproblem with keys ki, …, kj and dummy keys di-1, di, …, dj. e[i, j] is the expected cost of searching an optimal BST containing the keys ki, …, kj. Ultimately, we wish to compute e[1, n]. For subtree with keys ki, …, kj denote w(i, j) = ∑l=i..j pl + ∑l=i-1..j ql If kr is the root of the optimal subtree containing ki, …, kj, we have e[i, j] = pr + (e(i, r-1] + w(i, r-1)) + (e[r+1, j] + w(r+1, j)) which is equivalent to e[i, j] = e[i, r-1] + e[r+1, j] + w(i, j) because w(i, j) = w(i, r-1) + pr + w(r+1, j) Final, recursive formula: e[i, j] = qi-1 if j = i -1 mini≤r≤j {e[i, r-1] + e[r+1, j] } + w(i, j) if i ≤ j Must add because the depth of each node in the left and right subtrees increases by one in the big tree.

Problems Read Sec. 15.3 Read Sec. 15.4: Longest common subsequences Ex. 15.4-1 Ex. 15.5-2 Prob. 15-6 Prob. 15-7