CSE 780: Design and Analysis of Algorithms - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

CSE 780: Design and Analysis of Algorithms

Description:

Matrix multiplication is associative. So output will be the same ... Remember the breaking position chosen for each table entry. Total time complexity: ... – PowerPoint PPT presentation

Number of Views:63
Avg rating:3.0/5.0
Slides: 20
Provided by: tri5133
Category:

less

Transcript and Presenter's Notes

Title: CSE 780: Design and Analysis of Algorithms


1
CSE 780 Design and Analysis of Algorithms
  • Lecture 11
  • DP-algorithm
  • Matrix multiplication
  • Min-weight triangulation

2
Matrix Multiplication
  • Given matrix A (size p ? q) and B (size q ? r)
  • Compute C A B
  • A and B must be compatible
  • Time to compute C (number of scalar
    multiplications) pqr

3
Matrix-chain Multiplication
  • Different ways to compute C
  • Matrix multiplication is associative
  • So output will be the same
  • However, time cost can be very different
  • Example

4
Problem Definition
  • fully parenthesize the product in a way that
    minimizes the number of scalar multiplications
  • ( ( ) ( ) ) ( ( ) ( ( ) ( ( ) ( ) ) )
    )

5
Number of Parenthesizations
  • T(n) number of parenthesizations for n matrices
  • Recurrences

Number of parenthesizations exponential
6
Extract the Problem
  • First try
  • m(i)
  • smallest number of scalar multiplications from A1
    to Ai.

Doesnt work
7
Extract the Problem
  • Second try
  • Define the problem MM(i, j)
  • let m(i,j) smallest number of scalar
    multiplications
  • Goal MM(1, n) (with m(1,n) )

8
Structure of Optimal Parenthesization
  • Given MM(i, j)
  • ( ( ) ( ) ) ( ( ) ( ( ) ( ( ) ( ) ) )
    )
  • Imagine we take the leftmost left-parenthesis and
    its pairing right-parenthesis
  • Break MM(i,j) into two parts
  • Suppose break at kth position
  • Subproblems MM(i,k), MM(k1, j)
  • Optimal substructure property
  • Where to break

9
A Recursive Solution
  • Base case for mi,j
  • i j, m i , i 0
  • Otherwise, if its broken at i k lt j

10
Compute Optimal Cost
  • How to do bottom-up?

11
Example
  • A1 (30 ? 35)
  • A2 (35 ? 15)
  • A3 (15 ? 5)
  • A4 (5 ? 10)
  • A5 (10 ? 20)

1000
750
4375
2625
5775
15750
12
Construct Opt-solution
  • Remember the breaking position chosen for each
    table entry.
  • Total time complexity
  • Each table entry
  • Number of choices O(j-i)
  • Each choice O(1)
  • O(n3) running time

13
Remarks
  • More than constant choices
  • The order to build table

14
Simple Polygon Triangulation
diagonal, triangulation
15
Minimum-weight Triangulation
  • Weight of triangle perimeter of triangle
  • Weight of triangulation sum of perimeters
  • gt sum of length of diagonals
  • Hence now define weight sum of length of
    diagonals!
  • Goal find the triangulation with min-weight
  • for a convex polygon

16
Observation
17
Extract Problem
  • MT(i, j) minimum weight of sub-polygon from
    vertex i to j
  • wi,j weight of MT(i,j)
  • Goal MT(1,n)

18
Recursion

19
DP Table
  • 2D table
  • Size O(n2)
  • Total time complexity
  • O(n3)
Write a Comment
User Comments (0)
About PowerShow.com