1 More On Dynamic programming Algorithms Shortest path with edge constraint: Let G=(V, E) be a directed graph with weighted edges. Let s and v be two vertices.

Slides:



Advertisements
Similar presentations
Algorithm Design Methods Spring 2007 CSE, POSTECH.
Advertisements

ECE 667 Synthesis and Verification of Digital Circuits
Greedy Algorithms.
Greedy Algorithms Greed is good. (Some of the time)
Lecture 24 Coping with NPC and Unsolvable problems. When a problem is unsolvable, that's generally very bad news: it means there is no general algorithm.
Chapter 4 The Greedy Approach. Minimum Spanning Tree A tree is an acyclic, connected, undirected graph. A spanning tree for a given graph G=, where E.
3.3 Spanning Trees Tucker, Applied Combinatorics, Section 3.3, by Patti Bodkin and Tamsen Hunter.
1 Pseudo-polynomial time algorithm (The concept and the terminology are important) Partition Problem: Input: Finite set A=(a 1, a 2, …, a n } and a size.
Dynamic Programming Reading Material: Chapter 7..
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Greedy Algorithms Reading Material: –Alsuwaiyel’s Book: Section 8.1 –CLR Book (2 nd Edition): Section 16.1.
1 Vertex Cover Problem Given a graph G=(V, E), find V' ⊆ V such that for each edge (u, v) ∈ E at least one of u and v belongs to V’ and |V’| is minimized.
1. 2 Weighted interval scheduling for a lazy man Input: the same as weighted interval scheduling. Goal: find a set of compatible jobs such that for any.
1 Assignment 4. This one is cancelled since there is a solution on website. I new assignment will be given on Nov. 28. (Due on Friday of Week 14. Drop.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Shortest Path Problems Directed weighted graph. Path length is sum of weights of edges on path. The vertex at which the path begins is the source vertex.
1 Pseudo-polynomial time algorithm (The concept and the terminology are important) Partition Problem: Input: Finite set A=(a 1, a 2, …, a n } and a size.
Dynamic Programming1. 2 Outline and Reading Matrix Chain-Product (§5.3.1) The General Technique (§5.3.2) 0-1 Knapsack Problem (§5.3.3)
Pseudo-polynomial time algorithm (The concept and the terminology are important) Partition Problem: Input: Finite set A=(a1, a2, …, an} and a size s(a)
Tirgul 13. Unweighted Graphs Wishful Thinking – you decide to go to work on your sun-tan in ‘ Hatzuk ’ beach in Tel-Aviv. Therefore, you take your swimming.
chapter chapter chapter253.
Approximation Algorithms Motivation and Definitions TSP Vertex Cover Scheduling.
1 Dynamic Programming Jose Rolim University of Geneva.
1 Dynamic programming algorithms for all-pairs shortest path and longest common subsequences We will study a new technique—dynamic programming algorithms.
10/31/02CSE Greedy Algorithms CSE Algorithms Greedy Algorithms.
The Shortest Path Problem
Assignment 4. (Due on Dec 2. 2:30 p.m.) This time, Prof. Yao and I can explain the questions, but we will NOT tell you how to solve the problems. Question.
10/31/02CSE Greedy Algorithms CSE Algorithms Greedy Algorithms.
Dynamic Programming – Part 2 Introduction to Algorithms Dynamic Programming – Part 2 CSE 680 Prof. Roger Crawfis.
The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each decision is locally optimal. These.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Chapter 5 Dynamic Programming 2001 년 5 월 24 일 충북대학교 알고리즘연구실.
Approximating Minimum Bounded Degree Spanning Tree (MBDST) Mohit Singh and Lap Chi Lau “Approximating Minimum Bounded DegreeApproximating Minimum Bounded.
7 -1 Chapter 7 Dynamic Programming Fibonacci sequence Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, … F i = i if i  1 F i = F i-1 + F i-2 if.
May 1, 2002Applied Discrete Mathematics Week 13: Graphs and Trees 1News CSEMS Scholarships for CS and Math students (US citizens only) $3,125 per year.
Minimum weight spanning trees
Lectures on Greedy Algorithms and Dynamic Programming
Data Structures & Algorithms Graphs
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 14.
Approximation Algorithms Department of Mathematics and Computer Science Drexel University.
Comp. Genomics Recitation 10 Clustering and analysis of microarrays.
CS 3343: Analysis of Algorithms Lecture 18: More Examples on Dynamic Programming.
Dynamic Programming.  Decomposes a problem into a series of sub- problems  Builds up correct solutions to larger and larger sub- problems  Examples.
Algorithm Design Methods 황승원 Fall 2011 CSE, POSTECH.
Chapter 7 Dynamic Programming 7.1 Introduction 7.2 The Longest Common Subsequence Problem 7.3 Matrix Chain Multiplication 7.4 The dynamic Programming Paradigm.
COSC 3101NJ. Elder Announcements Midterm Exam: Fri Feb 27 CSE C –Two Blocks: 16:00-17:30 17:30-19:00 –The exam will be 1.5 hours in length. –You can attend.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
1 Assignment #3 is posted: Due Thursday Nov. 15 at the beginning of class. Make sure you are also working on your projects. Come see me if you are unsure.
TU/e Algorithms (2IL15) – Lecture 12 1 Linear Programming.
Introduction to NP Instructor: Neelima Gupta 1.
Chapter 14 Section 3 - Slide 1 Copyright © 2009 Pearson Education, Inc. AND.
More NP-Complete and NP-hard Problems
All-pairs Shortest paths Transitive Closure
Greedy Technique.
CS 3343: Analysis of Algorithms
Design and Analysis of Algorithm
1.3 Modeling with exponentially many constr.
Autumn 2016 Lecture 11 Minimum Spanning Trees (Part II)
ICS 353: Design and Analysis of Algorithms
Merge Sort 11/28/2018 2:21 AM The Greedy Method The Greedy Method.
Algorithm Design Methods
Pseudo-polynomial time algorithm (The concept and the terminology are important) Partition Problem: Input: Finite set A=(a1, a2, …, an} and a size s(a)
Algorithm Design Techniques Greedy Approach vs Dynamic Programming
Lecture 19 Linear Program
CSE 421, University of Washington, Autumn 2006
Analysis of Algorithms CS 477/677
Winter 2019 Lecture 11 Minimum Spanning Trees (Part II)
Weighted interval scheduling for a lazy man
Autumn 2019 Lecture 11 Minimum Spanning Trees (Part II)
Presentation transcript:

1 More On Dynamic programming Algorithms Shortest path with edge constraint: Let G=(V, E) be a directed graph with weighted edges. Let s and v be two vertices in V. Find a shortest path from s to u with exactly k edges. Here k  n-1 is part of the input. Solution: Define d(i, v) be the length of the shortest path from s to v with exactly i edges. d(i, v)=min {c(w, v)+d(i-1, w)} w  V. Initial values: d(i, s)=0, for i=0, d(i,s)=  for i=1, 2, …, d(0, v)=  ; d(k, v) will give the length of the shortest path. A backtracking process can give the path.

z uv xy i z, u, x, v, y 0 0      6z 7z   2   14u 4x 2u 3 4y 2v  9y 23x.

3 Shortest path with delay constraint: Let G=(V, E) be a directed path. Each edge (u, v) has a positive weight edges c(u, v) and a (positive integer) delay delay(u, v). Let s and v be two vertices in V. Find a shortest path from s to u with delay at most k. Solution: Define l(d, v) be the length of the shortest path from s to v with delay = d. l(d, v)= min {c(w, v)+l(d-delay(w, v), w),  }. w  V & delay(w,v)  d Initial values: l(0, s)=0, l(i, s)=  and d(0, v)=  ; l(k, u) will give the length of the shortest path. A backtracking process can give the path. The previous example is for delay(u, v)=1.

z uv xy d z, u, x, v, y 0 0     1  6z 7z   2   14u 4x 2u 3 4y   9y 23x. delay(v,u)=2. For any other edge, it is 1.

5

6 Weighted interval scheduling for a lazy man Input: the same as weighted interval scheduling. Goal: find a set of compatible jobs such that for any two consecutive jobs in the subset either there is some idle time or the total length of the two consecutive jobs is at most k. If k=4, we can choose black, blue, yellow as a subset. But we cannot choose black, blue and green as the subset.

7 Solution: Still the same equation, but use different p(). OPT(j) be the weight of the optimal solution containing at most the first j jobs. OPT(j)=min {OPT(j-1), v j + OPT(p(j))} Initial Value: OPT(0)=0. P(j) is redefined as: the largest i<j such that job i is compatible with j and either there is some idle time between i and j or f j -s i  k.

8 K=4 p(b)=0; p( c )=0; p(a)=0; p(e)=0; p(d)=0; p(f)=b; p(g)=c; p(h)= e;

9 k=6 p(b)=0; p( c )=0; p(a)=0; p(e)=b; p(d)=0; p(f)=c; p(g)=c; p(h)= e;

10 Weighted maximum independent set on a path. Given a graph G(V, E), where V={v 1, v 2, …, v n } and E={(v i, v i+1 )|for i=1, 2, …, n-1}. Each vertex v i has a weight w i. Find an independent set with maximum weight. An independent set in a graph is a subset of vertices in V such that no two vertices in the independent set share an edge. Solution: Define d(i) be the weight of the optimal solution for the first i vertices. d(i)=max {d(i-1), w i +d(i-2)}. d(0)=0; Remarks: The problem is almost identical to the weighted interval scheduling problem if we treat p(i)=i-2.

11 Weighted maximum set on a path. Given a graph G(V, E), where V={v 1, v 2, …, v n } and E={(v i, v i+1 )|for i=1, 2, …, n-1}. Each vertex v i has a weight w i. d(v i, v i+1 ) is the length of the edge. d(v i, v i+2 )=d(v i, v i+1 )+d(v i+1, v i+2 ). Find a subset of vertices with maximum weight such that the distance between any pair of vertices in the subset is at least k. Solution: Define d(i) be the weight of the optimal solution for the first i vertices. d(i)= max {d(i-1), w i +d(p(i))}. d(0)=0; Remarks: p(i) is the biggest j<i such that d(v i,v j )≥k.

12 Another setting of the previous problem. Text book page 307. Consider a highway from west to east. The possible sites for billboards are given by numbers x1, x2, …, xn, each in the interval [0, M]. If you place a billboard at location xi, you receive revenue of ri>0. Regulations imposed by the county’s Highway Department require that no two of the billboards be within less than or equal to 5 miles of each other. How to place billboards at a subset of sites so as to maximize your total revenue, subject to this restriction.. Solution: Define d(i) be the revenue of the optimal solution for the first i sites. d(i)=max { d(i-1), r i +d(p(i))}. d(0)=0; Remarks: p(i) is the biggest j 5. x 1 x 2 x 3 x n

13 Another setting of the previous problem. X1=0, x2=3, x3=6, x4=8, x5=15, x6=25. W1=2, w2=5, w3=8, w4=6, w5=9, w6=12. i p(i): d(i): 0 2, d(i)=max { d(i-1), w i +d(p(i))}. d(0)=0; Remarks: p(i) is the biggest j 5. x 1 x 2 x 3 x n

14 Change-making problem: Given an amount n and unlimited quantities of coins of each of the denominations d 1, d 2, …, d m, find the smallest number of coins that add up to n or indicate that the problem does not have a solution. Solution: Let d(i) be the minimum number of coins used for amount i. Initial values: d(0)=0, d(i)= . equation: d(i) = min d(i-d k )+1. k=1, 2, …, m.

15 Change-making problem: Initial values: d(0)=0, d(i)= . equation: d(i) = min d(i-d k )+1 k=1, 2, …, m & i-d k ≥0 d 1 =2 and d 2 =5. i=7. i= 0, 1, 2, 3, 4, 5, 6, 7 d(i): 0, , 1, , 2, 1, 3, 2. Backtracking: $5, $2. (how do you get d(7)=2? d(7)=d(2)+5. Print $5 and goto d(2). How do you get d(2)? D(2)=2+d(0). Print out $2 and goto d(0). Whenever reach d(0), we stop. ) for i=3, since d(3)= , there is no solution.

16 LCS for three sequences. Give three sequences X, Y, X. Find the longest common subsequence for three sequences. First try. 1. construct W, the LCS for X and Y 2. Construct U, the LCS for W and Z. 3. U will be the LCS for the tree sequences X, Y and Z. It does not work! Counter Example: X=bbaaa, Y=aaaabb and Z=cbcbc. LCS for X and Y is aaa. LCS for aaa and cbcbc is empty. However, the LCS for X, Y and Z is bb.

17 LCS for three sequences. Give three sequences X, Y, X. Find the longest common subsequence for three sequences. Solution: Define c[i, j, k] be the length of LCS for the first I letters in X, the first j letters in Y and the first k letters in Z. c[i,j,k] is the maximum of the following: c[i-1, j-1, k-1]+1, if Xi=Yj=Zk. c[i-1, j-1, k]; c[i-1, j, k-1] c[i, j-1, k-1] c[i, j, k-1] c[i,j-1, k] c[i-1, j,k]. Initial values: c[i,jk]=0 if i=0 or j=0 or k=0.

18 Exercise 1: Let T be a rooted binary tree, where each internal node in the tree has two children and every node (except the root) in T has a parent. Each leaf in the tree is assigned a letter in  ={A, C, G, T}. Figure 1 gives an example. Consider an edge e in T. Assume that every end of e is assigned a letter. The cost of e is 0 if the two letters are identical and the cost is 1 if the two letters are not identical. The problem here is to assign a letter in  to each internal node of T such that the cost of the tree is minimized, where the cost of the tree is the total cost of all edges in the tree. Design a polynomial-time dynamic programming algorithm to solve the problem.

19 A A C Figure 1 A

20 Exercise 2. Give a polynomial time algorithm to find the longest monotonically increasing subsequence of a sequence of n numbers. Can you give a linear space algorithm? (Assume that each integer appears once in the input sequence of n numbers) Example: Consider sequence 1,8, 2,9, 3,10, 4, 5. Both subsequences 1, 2, 3, 4, 5 and 1, 8, 9, 10 are monotonically increasing subsequences. However, 1,2,3, 4, 5 is the longest.

21 Assignment 4. (Due on Friday of Week 14. Drop it in Mail Box 76 ) This time, I can explain the questions, but we will NOT tell you how to solve the problems. Question 1. (20 points) Change-making problem (version 1): Given an amount n and coins of each of the denominations d 1, d 2, …, d m, where there are k copies of d 1 coin and unlimited quantities of other coins, design a dynamic programming algorithm to find the smallest number of coins that add up to n or indicate that the problem does not have a solution. Question 2. (20 points) Change-making problem (version 2): Given an amount n and coins of the denominations d 1, d 2, …, d m, where there are 2 copies of each d i coin, design a dynamic programming algorithm to find the smallest number of coins that add up to n or indicate that the problem does not have a solution. Question 3. (60 points) will be give in week 12.