Optimization II: Dynamic programming

Size: px
Start display at page:

Download "Optimization II: Dynamic programming"

Transcription

1 Optimization II: Dynamic programming Ricardo Fukasawa Department of Combinatorics and Optimization Faculty of Mathematics University of Waterloo Nov 2, 2016 R. Fukasawa (C&O) Optimization II 1 / 21

2 Picking items Question Suppose you have a list of n items with integer weights (a 1,...,a n ) and with values (c 1,...,c n ) and you can carry at most an integer b amount of weight. Which items would you choose to carry to maximize the total value you carry? Example: n = 5, (a 1,a 2,a 3,a 4,a 5 ) = (5,3,6,4,7) (c 1,c 2,c 3,c 4,c 5 ) = (6,4,5,7,6) b = 11 Examples of feasible solutions: R. Fukasawa (C&O) Optimization II 2 / 21

3 Picking items Question Suppose you have a list of n items with integer weights (a 1,...,a n ) and with values (c 1,...,c n ) and you can carry at most an integer b amount of weight. Which items would you choose to carry to maximize the total value you carry? Example: n = 5, (a 1,a 2,a 3,a 4,a 5 ) = (5,3,6,4,7) (c 1,c 2,c 3,c 4,c 5 ) = (6,4,5,7,6) b = 11 Examples of feasible solutions: Carry 1 and 3, with value 11 R. Fukasawa (C&O) Optimization II 2 / 21

4 Picking items Question Suppose you have a list of n items with integer weights (a 1,...,a n ) and with values (c 1,...,c n ) and you can carry at most an integer b amount of weight. Which items would you choose to carry to maximize the total value you carry? Example: n = 5, (a 1,a 2,a 3,a 4,a 5 ) = (5,3,6,4,7) (c 1,c 2,c 3,c 4,c 5 ) = (6,4,5,7,6) b = 11 Examples of feasible solutions: Carry 1 and 3, with value 11 Carry 4 and 5, with value 13 R. Fukasawa (C&O) Optimization II 2 / 21

5 Picking items Question Suppose you have a list of n items with integer weights (a 1,...,a n ) and with values (c 1,...,c n ) and you can carry at most an integer b amount of weight. Which items would you choose to carry to maximize the total value you carry? Example: n = 5, (a 1,a 2,a 3,a 4,a 5 ) = (5,3,6,4,7) (c 1,c 2,c 3,c 4,c 5 ) = (6,4,5,7,6) b = 11 Examples of feasible solutions: Carry 1 and 3, with value 11 Carry 4 and 5, with value 13 Carry 4 and 6, with value 12 R. Fukasawa (C&O) Optimization II 2 / 21

6 Picking items Question Suppose you have a list of n items with integer weights (a 1,...,a n ) and with values (c 1,...,c n ) and you can carry at most an integer b amount of weight. Which items would you choose to carry to maximize the total value you carry? Proposed greedy algorithms: R. Fukasawa (C&O) Optimization II 3 / 21

7 Picking items Question Suppose you have a list of n items with integer weights (a 1,...,a n ) and with values (c 1,...,c n ) and you can carry at most an integer b amount of weight. Which items would you choose to carry to maximize the total value you carry? Proposed greedy algorithms: Pick smallest weight item, until weight limit is exceeded. R. Fukasawa (C&O) Optimization II 3 / 21

8 Picking items Question Suppose you have a list of n items with integer weights (a 1,...,a n ) and with values (c 1,...,c n ) and you can carry at most an integer b amount of weight. Which items would you choose to carry to maximize the total value you carry? Proposed greedy algorithms: Pick smallest weight item, until weight limit is exceeded. Pick largest value item that does not exceed weight limit. R. Fukasawa (C&O) Optimization II 3 / 21

9 Picking items Question Suppose you have a list of n items with integer weights (a 1,...,a n ) and with values (c 1,...,c n ) and you can carry at most an integer b amount of weight. Which items would you choose to carry to maximize the total value you carry? Proposed greedy algorithms: Pick smallest weight item, until weight limit is exceeded. Pick largest value item that does not exceed weight limit. Order items from highest to lowest value / weight ratio ( c j a j ). Pick the items in that order if possible. R. Fukasawa (C&O) Optimization II 3 / 21

10 Picking items Question Suppose you have a list of n items with integer weights (a 1,...,a n ) and with values (c 1,...,c n ) and you can carry at most an integer b amount of weight. Which items would you choose to carry to maximize the total value you carry? Proposed greedy algorithms: Pick smallest weight item, until weight limit is exceeded. Pick largest value item that does not exceed weight limit. Order items from highest to lowest value / weight ratio ( c j a j ). Pick the items in that order if possible. Suggestions? R. Fukasawa (C&O) Optimization II 3 / 21

11 Alternative approach: Suppose I am considering just the last item (item n). Then either: I pick item n, get a value of c n and reduce my capacity by a n or I don t pick item n and still have capacity b Example: n = 3, (a 1,a 2,a 3 ) = (2,3,1) (c 1,c 2,c 3 ) = (5,7,6) b = 4 If I pick item 3, then I have already a value of 6, with capacity of 3 left for items 1,2. If I don t pick item 3, then I have already a value of 0, with capacity of 4 left for items 1,2. R. Fukasawa (C&O) Optimization II 4 / 21

12 Example: n = 3, (a 1,a 2,a 3 ) = (2,3,1) (c 1,c 2,c 3 ) = (5,7,6) b = 4 Conclusion: In my example, I should pick the best of: R. Fukasawa (C&O) Optimization II 5 / 21

13 Example: n = 3, (a 1,a 2,a 3 ) = (2,3,1) (c 1,c 2,c 3 ) = (5,7,6) b = 4 Conclusion: In my example, I should pick the best of: Picking item 3: 6+ optimal value of problem with just items 1,2 and capacity 3 R. Fukasawa (C&O) Optimization II 5 / 21

14 Example: n = 3, (a 1,a 2,a 3 ) = (2,3,1) (c 1,c 2,c 3 ) = (5,7,6) b = 4 Conclusion: In my example, I should pick the best of: Picking item 3: 6+ optimal value of problem with just items 1,2 and capacity 3 Not picking item 3: 0+ optimal value of problem with just items 1,2 and capacity 4 R. Fukasawa (C&O) Optimization II 5 / 21

15 Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem R. Fukasawa (C&O) Optimization II 6 / 21

16 Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation R. Fukasawa (C&O) Optimization II 6 / 21

17 Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation v(i,d) - Optimal value for problem with items 1,...,i and capacity d R. Fukasawa (C&O) Optimization II 6 / 21

18 Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation v(i,d) - Optimal value for problem with items 1,...,i and capacity d What we want: v(n,b) R. Fukasawa (C&O) Optimization II 6 / 21

19 Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation v(i,d) - Optimal value for problem with items 1,...,i and capacity d What we want: v(n,b) Back to example: R. Fukasawa (C&O) Optimization II 6 / 21

20 Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation v(i,d) - Optimal value for problem with items 1,...,i and capacity d What we want: Back to example: Picking item 3: v(n,b) R. Fukasawa (C&O) Optimization II 6 / 21

21 Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation v(i,d) - Optimal value for problem with items 1,...,i and capacity d What we want: v(n,b) Back to example: Picking item 3: 6+ optimal value of problem with just items 1,2 and capacity 3 R. Fukasawa (C&O) Optimization II 6 / 21

22 Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation v(i,d) - Optimal value for problem with items 1,...,i and capacity d What we want: Back to example: Picking item 3: v(n,b) v(3,4) = 6+v(2,3) R. Fukasawa (C&O) Optimization II 6 / 21

23 Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation v(i,d) - Optimal value for problem with items 1,...,i and capacity d What we want: Back to example: Picking item 3: v(n,b) v(3,4) = 6+v(2,3) Not picking item 3: R. Fukasawa (C&O) Optimization II 6 / 21

24 Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation v(i,d) - Optimal value for problem with items 1,...,i and capacity d What we want: v(n,b) Back to example: Picking item 3: Not picking item 3: v(3,4) = 6+v(2,3) 0+ optimal value of problem with just items 1,2 and capacity 4 R. Fukasawa (C&O) Optimization II 6 / 21

25 Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation v(i,d) - Optimal value for problem with items 1,...,i and capacity d What we want: v(n,b) Back to example: Picking item 3: Not picking item 3: v(3,4) = 6+v(2,3) v(3,4) = 0+v(2,4) R. Fukasawa (C&O) Optimization II 6 / 21

26 Idea: (DYNAMIC PROGRAMMING) Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem Notation v(i,d) - Optimal value for problem with items 1,...,i and capacity d What we want: v(n,b) Back to example: v(3,4) = max{6+v(2,3),0+v(2,4)} R. Fukasawa (C&O) Optimization II 6 / 21

27 In general, given: integer weights (a 1,...,a n ) values (c 1,...,c n ) integer capacity b v(i,d) = R. Fukasawa (C&O) Optimization II 7 / 21

28 In general, given: integer weights (a 1,...,a n ) values (c 1,...,c n ) integer capacity b v(i,d) = max{c i +v(i 1,d a i ),0+v(i 1,d)} R. Fukasawa (C&O) Optimization II 7 / 21

29 In general, given: integer weights (a 1,...,a n ) values (c 1,...,c n ) integer capacity b v(i,d) = max{c i +v(i 1,d a i ),0+v(i 1,d)} (only if i > 1 and d a i ) R. Fukasawa (C&O) Optimization II 7 / 21

30 In general, given: integer weights (a 1,...,a n ) values (c 1,...,c n ) integer capacity b v(i,d) = max{c i +v(i 1,d a i ),0+v(i 1,d)} (only if i > 1 and d a i ) Otherwise: Easy cases: i = 1 d < a i R. Fukasawa (C&O) Optimization II 7 / 21

31 Example n = 3, (a 1,a 2,a 3 ) = (2,3,1) (c 1,c 2,c 3 ) = (5,7,6) b = 4 R. Fukasawa (C&O) Optimization II 8 / 21

32 Dynamic programming Key ingredient: Optimal substructure: Optimal solution to a problem can be constructed from optimal solution of simpler versions of the same problem R. Fukasawa (C&O) Optimization II 9 / 21

33 Google maps (shortest path) Suppose circles represent intersections, lines are streets, numbers are distances. Goal: Find shortest path from A E R. Fukasawa (C&O) Optimization II 10 / 21

34 Google maps (shortest path) Suppose circles represent intersections, lines are streets, numbers are distances. Goal: Find shortest path from A E Nomenclature: Vertices (circles): {A,B,C,D,E,F,G} Edges (lines): {A,B}, {B,F}, {A,F}, {B,C},... Vertices are adjacent if there is an edge connecting them Path is a sequence of adjacent non-repeated vertices Example: (A,B,F,G,E) is an A E path Cost of path is sum of cost of edges Example: Path (A,B,F,G,E) has cost 18 R. Fukasawa (C&O) Optimization II 10 / 21

35 Shortest path Given G = (V,E) with costs c e > 0 for all e E, and two vertices s and t, find shortest s t path. Key observation Shortest path from A to E is shortest of: 5 + Shortest path from A to D 4 + Shortest path from A to G R. Fukasawa (C&O) Optimization II 11 / 21

36 Example Dijkstra s algorithm starting with A R. Fukasawa (C&O) Optimization II 12 / 21

37 Shortest path Given G = (V,E) with costs c e > 0 for all e E, and initial vertex s, find shortest s v path for all v V. Dijkstra s algorithm: Maintain a set S for which we know the shortest s v path. 1 Circle the beginning vertex. 2 List the uncircled vertices that are adjacent to circled ones, the paths, and the total time. 3 Identify the uncircled vertex with shortest total time and circle the corresponding adjacent vertex. 4 Repeat from step 2 until no uncircled vertices exist. R. Fukasawa (C&O) Optimization II 13 / 21

Computational Methods in IS Research Fall Graph Algorithms Network Flow Problems

Computational Methods in IS Research Fall Graph Algorithms Network Flow Problems Computational Methods in IS Research Fall 2017 Graph Algorithms Network Flow Problems Nirmalya Roy Department of Information Systems University of Maryland Baltimore County www.umbc.edu Network Flow Problems

More information

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity. 1. T F: Consider a directed graph G = (V, E) and a vertex s V. Suppose that for all v V, there exists a directed path in G from s to v. Suppose that a DFS is run on G, starting from s. Then, true or false:

More information

CSE 21: Mathematics for Algorithms and Systems Analysis

CSE 21: Mathematics for Algorithms and Systems Analysis CSE 21: Mathematics for Algorithms and Systems Analysis Week 10 Discussion David Lisuk June 4, 2014 David Lisuk CSE 21: Mathematics for Algorithms and Systems Analysis June 4, 2014 1 / 26 Agenda 1 Announcements

More information

Lesson 1: Complementary and Supplementary Angles

Lesson 1: Complementary and Supplementary Angles lasswork Opening As we begin our study of unknown angles, let us review key definitions. Term Definition Two angles and, with a common side, are angles if is in the interior of. When two lines intersect,

More information

Partha Sarathi Mandal

Partha Sarathi Mandal MA 515: Introduction to Algorithms & MA353 : Design and Analysis of Algorithms [3-0-0-6] Lecture 39 http://www.iitg.ernet.in/psm/indexing_ma353/y09/index.html Partha Sarathi Mandal psm@iitg.ernet.in Dept.

More information

Math 414 Lecture 30. The greedy algorithm provides the initial transportation matrix.

Math 414 Lecture 30. The greedy algorithm provides the initial transportation matrix. Math Lecture The greedy algorithm provides the initial transportation matrix. matrix P P Demand W ª «2 ª2 «W ª «W ª «ª «ª «Supply The circled x ij s are the initial basic variables. Erase all other values

More information

Problem 1. Which of the following is true of functions =100 +log and = + log? Problem 2. Which of the following is true of functions = 2 and =3?

Problem 1. Which of the following is true of functions =100 +log and = + log? Problem 2. Which of the following is true of functions = 2 and =3? Multiple-choice Problems: Problem 1. Which of the following is true of functions =100+log and =+log? a) = b) =Ω c) =Θ d) All of the above e) None of the above Problem 2. Which of the following is true

More information

Grade 7/8 Math Circles Graph Theory - Solutions October 13/14, 2015

Grade 7/8 Math Circles Graph Theory - Solutions October 13/14, 2015 Faculty of Mathematics Waterloo, Ontario N2L 3G1 Centre for Education in Mathematics and Computing Grade 7/8 Math Circles Graph Theory - Solutions October 13/14, 2015 The Seven Bridges of Königsberg In

More information

CS1 Lecture 31 Apr. 3, 2019

CS1 Lecture 31 Apr. 3, 2019 CS Lecture 3 Apr. 3, 209 HW6 due Fri. Q3: think carefully about overlaps draw pictures Think dimension by dimension three D problems if they don t overlap in x, they don t overlap» Express this in terms

More information

Introduction to Algorithms and Complexity Theory

Introduction to Algorithms and Complexity Theory Introduction to Algorithms and Complexity Theory Iris Cong UCLA Math Circle - HS II Example 1. Algorithm to find the maximum of a list of N positive integers (call this list L 0, L N-1 ): initialize accumulator

More information

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS Department of Computer Science University of Babylon LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS By Faculty of Science for Women( SCIW), University of Babylon, Iraq Samaher@uobabylon.edu.iq

More information

The k-center problem Approximation Algorithms 2009 Petros Potikas

The k-center problem Approximation Algorithms 2009 Petros Potikas Approximation Algorithms 2009 Petros Potikas 1 Definition: Let G=(V,E) be a complete undirected graph with edge costs satisfying the triangle inequality and k be an integer, 0 < k V. For any S V and vertex

More information

Ideally your algorithms for both parts should run in linear time. You will receive partial credit for a polynomial-time algorithm.

Ideally your algorithms for both parts should run in linear time. You will receive partial credit for a polynomial-time algorithm. HW 7: Extra problems Instructor: Sariel Har-Peled CS/ECE 374: Algorithms & Models of Computation, Fall 2017 Version: 1.0 1 Consider a directed graph G, where each edge is colored either red, white, or

More information

Info 2950, Lecture 16

Info 2950, Lecture 16 Info 2950, Lecture 16 28 Mar 2017 Prob Set 5: due Fri night 31 Mar Breadth first search (BFS) and Depth First Search (DFS) Must have an ordering on the vertices of the graph. In most examples here, the

More information

PATH FINDING AND GRAPH TRAVERSAL

PATH FINDING AND GRAPH TRAVERSAL GRAPH TRAVERSAL PATH FINDING AND GRAPH TRAVERSAL Path finding refers to determining the shortest path between two vertices in a graph. We discussed the Floyd Warshall algorithm previously, but you may

More information

The Shortest Path Problem

The Shortest Path Problem The Shortest Path Problem 1 Shortest-Path Algorithms Find the shortest path from point A to point B Shortest in time, distance, cost, Numerous applications Map navigation Flight itineraries Circuit wiring

More information

Spanning Trees. Lecture 20 CS2110 Spring 2015

Spanning Trees. Lecture 20 CS2110 Spring 2015 1 Spanning Trees Lecture 0 CS110 Spring 01 1 Undirected trees An undirected graph is a tree if there is exactly one simple path between any pair of vertices Root of tree? It doesn t matter choose any vertex

More information

CS261: Problem Set #2

CS261: Problem Set #2 CS261: Problem Set #2 Due by 11:59 PM on Tuesday, February 9, 2016 Instructions: (1) Form a group of 1-3 students. You should turn in only one write-up for your entire group. (2) Submission instructions:

More information

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014 Problem 1 (4 parts, 21 points) Encoders and Pass Gates Part A (8 points) Suppose the circuit below has the following input priority: I 1 > I 3 > I 0 > I 2. Complete the truth table by filling in the input

More information

Chapter 3 Linear Programming: A Geometric Approach

Chapter 3 Linear Programming: A Geometric Approach Chapter 3 Linear Programming: A Geometric Approach Section 3.1 Graphing Systems of Linear Inequalities in Two Variables y 4x + 3y = 12 4 3 4 x 3 y 12 x y 0 x y = 0 2 1 P(, ) 12 12 7 7 1 1 2 3 x We ve seen

More information

NP Completeness. Andreas Klappenecker [partially based on slides by Jennifer Welch]

NP Completeness. Andreas Klappenecker [partially based on slides by Jennifer Welch] NP Completeness Andreas Klappenecker [partially based on slides by Jennifer Welch] Dealing with NP-Complete Problems Dealing with NP-Completeness Suppose the problem you need to solve is NP-complete. What

More information

Math 381 Discrete Mathematical Modeling

Math 381 Discrete Mathematical Modeling Math 381 Discrete Mathematical Modeling Sean Griffin Today: -Equipment Replacement Problem -Min Spanning Tree Problem -Clustering Friday s Plan Intro to LPSolve software Download before class (link on

More information

MCL. (and other clustering algorithms) 858L

MCL. (and other clustering algorithms) 858L MCL (and other clustering algorithms) 858L Comparing Clustering Algorithms Brohee and van Helden (2006) compared 4 graph clustering algorithms for the task of finding protein complexes: MCODE RNSC Restricted

More information

Your favorite blog : (popularly known as VIJAY JOTANI S BLOG..now in facebook.join ON FB VIJAY

Your favorite blog :  (popularly known as VIJAY JOTANI S BLOG..now in facebook.join ON FB VIJAY Course Code : BCS-042 Course Title : Introduction to Algorithm Design Assignment Number : BCA(IV)-042/Assign/14-15 Maximum Marks : 80 Weightage : 25% Last Date of Submission : 15th October, 2014 (For July

More information

1. The following graph is not Eulerian. Make it into an Eulerian graph by adding as few edges as possible.

1. The following graph is not Eulerian. Make it into an Eulerian graph by adding as few edges as possible. 1. The following graph is not Eulerian. Make it into an Eulerian graph by adding as few edges as possible. A graph is Eulerian if it has an Eulerian circuit, which occurs if the graph is connected and

More information

Problem set 2. Problem 1. Problem 2. Problem 3. CS261, Winter Instructor: Ashish Goel.

Problem set 2. Problem 1. Problem 2. Problem 3. CS261, Winter Instructor: Ashish Goel. CS261, Winter 2017. Instructor: Ashish Goel. Problem set 2 Electronic submission to Gradescope due 11:59pm Thursday 2/16. Form a group of 2-3 students that is, submit one homework with all of your names.

More information

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures Final Examination (17 pages) Instructor: Douglas Harder April 14, 2004 9:00-12:00 Name (last,

More information

Section The Law of Sines and the Law of Cosines

Section The Law of Sines and the Law of Cosines Section 7.3 - The Law of Sines and the Law of Cosines Sometimes you will need to solve a triangle that is not a right triangle. This type of triangle is called an oblique triangle. To solve an oblique

More information

9 abcd = dcba b + 90c = c + 10b b = 10c.

9 abcd = dcba b + 90c = c + 10b b = 10c. In this session, we ll learn how to solve problems related to place value. This is one of the fundamental concepts in arithmetic, something every elementary and middle school mathematics teacher should

More information

Lecture: Analysis of Algorithms (CS )

Lecture: Analysis of Algorithms (CS ) Lecture: Analysis of Algorithms (CS483-001) Amarda Shehu Spring 2017 1 The Fractional Knapsack Problem Huffman Coding 2 Sample Problems to Illustrate The Fractional Knapsack Problem Variable-length (Huffman)

More information

Algorithms for Euclidean TSP

Algorithms for Euclidean TSP This week, paper [2] by Arora. See the slides for figures. See also http://www.cs.princeton.edu/~arora/pubs/arorageo.ps Algorithms for Introduction This lecture is about the polynomial time approximation

More information

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved. Chapter 9 Greedy Technique Copyright 2007 Pearson Addison-Wesley. All rights reserved. Greedy Technique Constructs a solution to an optimization problem piece by piece through a sequence of choices that

More information

Student number: Datenstrukturen & Algorithmen page 1

Student number: Datenstrukturen & Algorithmen page 1 Student number: Datenstrukturen & Algorithmen page 1 Problem 1. / 15 P Please note: 1) In this problem, you have to provide solutions only. You can write them right on this sheet. 2) If you use algorithms

More information

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Shortest Paths Date: 10/13/15

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Shortest Paths Date: 10/13/15 600.363 Introduction to Algorithms / 600.463 Algorithms I Lecturer: Michael Dinitz Topic: Shortest Paths Date: 10/13/15 14.1 Introduction Today we re going to talk about algorithms for computing shortest

More information

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014 Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate

More information

LOOK AT THE EXTEMES! Răzvan Gelca Texas Tech University

LOOK AT THE EXTEMES! Răzvan Gelca Texas Tech University LOOK AT THE EXTEMES! Răzvan Gelca Texas Tech University Problem 1: In some country all roads between cities are oneway so that once you leave a city you cannot return to it anymore. Prove that there exists

More information

CMSC 451: Dynamic Programming

CMSC 451: Dynamic Programming CMSC 41: Dynamic Programming Slides By: Carl Kingsford Department of Computer Science University of Maryland, College Park Based on Sections 6.1&6.2 of Algorithm Design by Kleinberg & Tardos. Dynamic Programming

More information

How to find a minimum spanning tree

How to find a minimum spanning tree Print How to find a minimum spanning tree Definitions Kruskal s algorithm Spanning tree example Definitions Trees A tree is a connected graph without any cycles. It can also be defined as a connected graph

More information

SPANNING TREES. Lecture 21 CS2110 Spring 2016

SPANNING TREES. Lecture 21 CS2110 Spring 2016 1 SPANNING TREES Lecture 1 CS110 Spring 016 Spanning trees What we do today: Calculating the shortest path in Dijkstra s algorithm Look at time complexity of shortest path Definitions Minimum spanning

More information

Algorithm Design Techniques. Hwansoo Han

Algorithm Design Techniques. Hwansoo Han Algorithm Design Techniques Hwansoo Han Algorithm Design General techniques to yield effective algorithms Divide-and-Conquer Dynamic programming Greedy techniques Backtracking Local search 2 Divide-and-Conquer

More information

Artificial Intelligence

Artificial Intelligence Artificial Intelligence Shortest Path Problem G. Guérard Department of Nouvelles Energies Ecole Supérieur d Ingénieurs Léonard de Vinci Lecture 3 GG A.I. 1/42 Outline 1 The Shortest Path Problem Introduction

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 101, Winter 018 D/Q Greed SP s DP LP, Flow B&B, Backtrack Metaheuristics P, NP Design and Analysis of Algorithms Lecture 8: Greed Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ Optimization

More information

10/31/18. About A6, Prelim 2. Spanning Trees, greedy algorithms. Facts about trees. Undirected trees

10/31/18. About A6, Prelim 2. Spanning Trees, greedy algorithms. Facts about trees. Undirected trees //8 About A, Prelim Spanning Trees, greedy algorithms Lecture CS Fall 8 Prelim : Thursday, November. Visit exams page of course website and read carefully to find out when you take it (: or 7:) and what

More information

Spanning Trees, greedy algorithms. Lecture 20 CS2110 Fall 2018

Spanning Trees, greedy algorithms. Lecture 20 CS2110 Fall 2018 1 Spanning Trees, greedy algorithms Lecture 20 CS2110 Fall 2018 1 About A6, Prelim 2 Prelim 2: Thursday, 15 November. Visit exams page of course website and read carefully to find out when you take it

More information

L.J. Institute of Engineering & Technology Semester: VIII (2016)

L.J. Institute of Engineering & Technology Semester: VIII (2016) Subject Name: Design & Analysis of Algorithm Subject Code:1810 Faculties: Mitesh Thakkar Sr. UNIT-1 Basics of Algorithms and Mathematics No 1 What is an algorithm? What do you mean by correct algorithm?

More information

CS61BL. Lecture 5: Graphs Sorting

CS61BL. Lecture 5: Graphs Sorting CS61BL Lecture 5: Graphs Sorting Graphs Graphs Edge Vertex Graphs (Undirected) Graphs (Directed) Graphs (Multigraph) Graphs (Acyclic) Graphs (Cyclic) Graphs (Connected) Graphs (Disconnected) Graphs (Unweighted)

More information

Graph Algorithms (part 3 of CSC 282),

Graph Algorithms (part 3 of CSC 282), Graph Algorithms (part of CSC 8), http://www.cs.rochester.edu/~stefanko/teaching/10cs8 1 Schedule Homework is due Thursday, Oct 1. The QUIZ will be on Tuesday, Oct. 6. List of algorithms covered in the

More information

UNIT 3. Greedy Method. Design and Analysis of Algorithms GENERAL METHOD

UNIT 3. Greedy Method. Design and Analysis of Algorithms GENERAL METHOD UNIT 3 Greedy Method GENERAL METHOD Greedy is the most straight forward design technique. Most of the problems have n inputs and require us to obtain a subset that satisfies some constraints. Any subset

More information

Dijkstra's Algorithm

Dijkstra's Algorithm Carlos Moreno cmoreno @ uwaterloo.ca EIT-4103 Image courtesy of wikipedia.org https://ece.uwaterloo.ca/~cmoreno/ece250 Standard reminder to set phones to silent/vibrate mode, please! During today's class

More information

Algorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee

Algorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee Algorithm Analysis Graph algorithm Chung-Ang University, Jaesung Lee Basic definitions Graph = (, ) where is a set of vertices and is a set of edges Directed graph = where consists of ordered pairs

More information

Graph Algorithms. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

Graph Algorithms. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University Graph Algorithms CptS 223 Advanced Data Structures Larry Holder School of Electrical Engineering and Computer Science Washington State University 1 Network Flow How much freight can flow from Seattle to

More information

Module 2: NETWORKS AND DECISION MATHEMATICS

Module 2: NETWORKS AND DECISION MATHEMATICS Further Mathematics 2017 Module 2: NETWORKS AND DECISION MATHEMATICS Chapter 9 Undirected Graphs and Networks Key knowledge the conventions, terminology, properties and types of graphs; edge, face, loop,

More information

CS161 - Final Exam Computer Science Department, Stanford University August 16, 2008

CS161 - Final Exam Computer Science Department, Stanford University August 16, 2008 CS161 - Final Exam Computer Science Department, Stanford University August 16, 2008 Name: Honor Code 1. The Honor Code is an undertaking of the students, individually and collectively: a) that they will

More information

Math/Stat 2300 Modeling using Graph Theory (March 23/25) from text A First Course in Mathematical Modeling, Giordano, Fox, Horton, Weir, 2009.

Math/Stat 2300 Modeling using Graph Theory (March 23/25) from text A First Course in Mathematical Modeling, Giordano, Fox, Horton, Weir, 2009. Math/Stat 2300 Modeling using Graph Theory (March 23/25) from text A First Course in Mathematical Modeling, Giordano, Fox, Horton, Weir, 2009. Describing Graphs (8.2) A graph is a mathematical way of describing

More information

MST & Shortest Path -Prim s -Djikstra s

MST & Shortest Path -Prim s -Djikstra s MST & Shortest Path -Prim s -Djikstra s PRIM s - Minimum Spanning Tree - A spanning tree of a graph is a tree that has all the vertices of the graph connected by some edges. - A graph can have one or more

More information

Name: THE SIMPLEX METHOD: STANDARD MAXIMIZATION PROBLEMS

Name: THE SIMPLEX METHOD: STANDARD MAXIMIZATION PROBLEMS Name: THE SIMPLEX METHOD: STANDARD MAXIMIZATION PROBLEMS A linear programming problem consists of a linear objective function to be maximized or minimized subject to certain constraints in the form of

More information

CS2223: Algorithms D-Term, Assignment 5

CS2223: Algorithms D-Term, Assignment 5 CS2223: Algorithms D-Term, 2015 Assignment 5 Teams: To be done individually Due date: 05/01/2015 (1:50 PM) Note: no late submission of HW5 will be accepted; we will talk about the solution of HW5 during

More information

CS 311 Discrete Math for Computer Science Dr. William C. Bulko. Graphs

CS 311 Discrete Math for Computer Science Dr. William C. Bulko. Graphs CS 311 Discrete Math for Computer Science Dr. William C. Bulko Graphs 2014 Definitions Definition: A graph G = (V,E) consists of a nonempty set V of vertices (or nodes) and a set E of edges. Each edge

More information

CSE 421 Applications of DFS(?) Topological sort

CSE 421 Applications of DFS(?) Topological sort CSE 421 Applications of DFS(?) Topological sort Yin Tat Lee 1 Precedence Constraints In a directed graph, an edge (i, j) means task i must occur before task j. Applications Course prerequisite: course

More information

CSC 373 Lecture # 3 Instructor: Milad Eftekhar

CSC 373 Lecture # 3 Instructor: Milad Eftekhar Huffman encoding: Assume a context is available (a document, a signal, etc.). These contexts are formed by some symbols (words in a document, discrete samples from a signal, etc). Each symbols s i is occurred

More information

CSE 100 Minimum Spanning Trees Prim s and Kruskal

CSE 100 Minimum Spanning Trees Prim s and Kruskal CSE 100 Minimum Spanning Trees Prim s and Kruskal Your Turn The array of vertices, which include dist, prev, and done fields (initialize dist to INFINITY and done to false ): V0: dist= prev= done= adj:

More information

Further Mathematics 2016 Module 2: NETWORKS AND DECISION MATHEMATICS Chapter 9 Undirected Graphs and Networks

Further Mathematics 2016 Module 2: NETWORKS AND DECISION MATHEMATICS Chapter 9 Undirected Graphs and Networks Further Mathematics 2016 Module 2: NETWORKS AND DECISION MATHEMATICS Chapter 9 Undirected Graphs and Networks Key knowledge the conventions, terminology, properties and types of graphs; edge, face, loop,

More information

Greedy Algorithms and Huffman Coding

Greedy Algorithms and Huffman Coding Greedy Algorithms and Huffman Coding Henry Z. Lo June 10, 2014 1 Greedy Algorithms 1.1 Change making problem Problem 1. You have quarters, dimes, nickels, and pennies. amount, n, provide the least number

More information

Greedy algorithms is another useful way for solving optimization problems.

Greedy algorithms is another useful way for solving optimization problems. Greedy Algorithms Greedy algorithms is another useful way for solving optimization problems. Optimization Problems For the given input, we are seeking solutions that must satisfy certain conditions. These

More information

Lesson 2 7 Graph Partitioning

Lesson 2 7 Graph Partitioning Lesson 2 7 Graph Partitioning The Graph Partitioning Problem Look at the problem from a different angle: Let s multiply a sparse matrix A by a vector X. Recall the duality between matrices and graphs:

More information

Note: For all questions, answer (E) NOTA means none of the above answers is correct. Unless otherwise specified, all angles are measured in degrees.

Note: For all questions, answer (E) NOTA means none of the above answers is correct. Unless otherwise specified, all angles are measured in degrees. Note: For all questions, answer means none of the above answers is correct. Unless otherwise specified, all angles are measured in degrees. 1. The three angles of a triangle have measures given by 3 5,

More information

Greedy Algorithms. Algorithms

Greedy Algorithms. Algorithms Greedy Algorithms Algorithms Greedy Algorithms Many algorithms run from stage to stage At each stage, they make a decision based on the information available A Greedy algorithm makes decisions At each

More information

Graph Algorithms (part 3 of CSC 282),

Graph Algorithms (part 3 of CSC 282), Graph Algorithms (part of CSC 8), http://www.cs.rochester.edu/~stefanko/teaching/11cs8 Homework problem sessions are in CSB 601, 6:1-7:1pm on Oct. (Wednesday), Oct. 1 (Wednesday), and on Oct. 19 (Wednesday);

More information

Examples of P vs NP: More Problems

Examples of P vs NP: More Problems Examples of P vs NP: More Problems COMP1600 / COMP6260 Dirk Pattinson Australian National University Semester 2, 2017 Catch Up / Drop in Lab When Fridays, 15.00-17.00 Where N335, CSIT Building (bldg 108)

More information

Graph Algorithms Introduction to Data Structures. Ananda Gunawardena 7/31/2011 1

Graph Algorithms Introduction to Data Structures. Ananda Gunawardena 7/31/2011 1 Graph Algorithms 15-121 Introduction to Data Structures Ananda Gunawardena 7/31/2011 1 In this lecture.. Main idea is finding the Shortest Path between two points in a Graph We will look at Graphs with

More information

CS170 Discussion Section 4: 9/18

CS170 Discussion Section 4: 9/18 CS170 Discussion Section 4: 9/18 1. Alien alphabet. Suppose you have a dictionary of an alien language which lists words in some sorted lexicographical ordering. For example, given the following list of

More information

Name Course Days/Start Time

Name Course Days/Start Time Name Course Days/Start Time Mini-Project : The Library of Functions In your previous math class, you learned to graph equations containing two variables by finding and plotting points. In this class, we

More information

UNIT Name the different ways of representing a graph? a.adjacencymatrix b. Adjacency list

UNIT Name the different ways of representing a graph? a.adjacencymatrix b. Adjacency list UNIT-4 Graph: Terminology, Representation, Traversals Applications - spanning trees, shortest path and Transitive closure, Topological sort. Sets: Representation - Operations on sets Applications. 1. Name

More information

Chapter 9 Graph Algorithms

Chapter 9 Graph Algorithms Chapter 9 Graph Algorithms 2 Introduction graph theory useful in practice represent many real-life problems can be slow if not careful with data structures 3 Definitions an undirected graph G = (V, E)

More information

Lecture outline. Graph coloring Examples Applications Algorithms

Lecture outline. Graph coloring Examples Applications Algorithms Lecture outline Graph coloring Examples Applications Algorithms Graph coloring Adjacent nodes must have different colors. How many colors do we need? Graph coloring Neighbors must have different colors

More information

ICS 161 Algorithms Winter 1998 Final Exam. 1: out of 15. 2: out of 15. 3: out of 20. 4: out of 15. 5: out of 20. 6: out of 15.

ICS 161 Algorithms Winter 1998 Final Exam. 1: out of 15. 2: out of 15. 3: out of 20. 4: out of 15. 5: out of 20. 6: out of 15. ICS 161 Algorithms Winter 1998 Final Exam Name: ID: 1: out of 15 2: out of 15 3: out of 20 4: out of 15 5: out of 20 6: out of 15 total: out of 100 1. Solve the following recurrences. (Just give the solutions;

More information

Solving NP-hard Problems on Special Instances

Solving NP-hard Problems on Special Instances Solving NP-hard Problems on Special Instances Solve it in poly- time I can t You can assume the input is xxxxx No Problem, here is a poly-time algorithm 1 Solving NP-hard Problems on Special Instances

More information

Linear Programming Terminology

Linear Programming Terminology Linear Programming Terminology The carpenter problem is an example of a linear program. T and B (the number of tables and bookcases to produce weekly) are decision variables. The profit function is an

More information

6th Bay Area Mathematical Olympiad

6th Bay Area Mathematical Olympiad 6th Bay Area Mathematical Olympiad February 4, 004 Problems and Solutions 1 A tiling of the plane with polygons consists of placing the polygons in the plane so that interiors of polygons do not overlap,

More information

TA: Jade Cheng ICS 241 Recitation Lecture Note #9 October 23, 2009

TA: Jade Cheng ICS 241 Recitation Lecture Note #9 October 23, 2009 TA: Jade Cheng ICS 241 Recitation Lecture Note #9 October 23, 2009 Recitation #9 Question: For each of these problems about a subway system, describe a weighted graph model that can be used to solve the

More information

9 abcd = dcba b + 90c = c + 10b b = 10c.

9 abcd = dcba b + 90c = c + 10b b = 10c. In this session, we ll learn how to solve problems related to place value. This is one of the fundamental concepts in arithmetic, something every elementary and middle school mathematics teacher should

More information

2006 Fryer Contest. Solutions

2006 Fryer Contest. Solutions Canadian Mathematics Competition An activity of the Centre for Education in Mathematics and Computing, University of Waterloo, Waterloo, Ontario 006 Fryer Contest Thursday, April 0, 006 Solutions c 006

More information

Greedy Algorithms. This is such a simple approach that it is what one usually tries first.

Greedy Algorithms. This is such a simple approach that it is what one usually tries first. Greedy Algorithms A greedy algorithm tries to solve an optimisation problem by making a sequence of choices. At each decision point, the alternative that seems best at that moment is chosen. This is such

More information

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions Introduction Chapter 9 Graph Algorithms graph theory useful in practice represent many real-life problems can be slow if not careful with data structures 2 Definitions an undirected graph G = (V, E) is

More information

CS388C: Combinatorics and Graph Theory

CS388C: Combinatorics and Graph Theory CS388C: Combinatorics and Graph Theory David Zuckerman Review Sheet 2003 TA: Ned Dimitrov updated: September 19, 2007 These are some of the concepts we assume in the class. If you have never learned them

More information

Announcements. CSEP 521 Applied Algorithms. Announcements. Polynomial time efficiency. Definitions of efficiency 1/14/2013

Announcements. CSEP 521 Applied Algorithms. Announcements. Polynomial time efficiency. Definitions of efficiency 1/14/2013 Announcements CSEP 51 Applied Algorithms Richard Anderson Winter 013 Lecture Reading Chapter.1,. Chapter 3 Chapter Homework Guidelines Prove that your algorithm works A proof is a convincing argument Give

More information

NARROW CORRIDOR. Teacher s Guide Getting Started. Lay Chin Tan Singapore

NARROW CORRIDOR. Teacher s Guide Getting Started. Lay Chin Tan Singapore Teacher s Guide Getting Started Lay Chin Tan Singapore Purpose In this two-day lesson, students are asked to determine whether large, long, and bulky objects fit around the corner of a narrow corridor.

More information

Approximation Techniques for Utilitarian Mechanism Design

Approximation Techniques for Utilitarian Mechanism Design Approximation Techniques for Utilitarian Mechanism Design Department of Computer Science RWTH Aachen Germany joint work with Patrick Briest and Piotr Krysta 05/16/2006 1 Introduction to Utilitarian Mechanism

More information

END-TERM EXAMINATION

END-TERM EXAMINATION (Please Write your Exam Roll No. immediately) Exam. Roll No... END-TERM EXAMINATION Paper Code : MCA-205 DECEMBER 2006 Subject: Design and analysis of algorithm Time: 3 Hours Maximum Marks: 60 Note: Attempt

More information

Lecture 3: Totally Unimodularity and Network Flows

Lecture 3: Totally Unimodularity and Network Flows Lecture 3: Totally Unimodularity and Network Flows (3 units) Outline Properties of Easy Problems Totally Unimodular Matrix Minimum Cost Network Flows Dijkstra Algorithm for Shortest Path Problem Ford-Fulkerson

More information

Bounds on graphs with high girth and high chromatic number

Bounds on graphs with high girth and high chromatic number Bounds on graphs with high girth and high chromatic number joint work with Daniel Bath and Zequn Li INTEGERS 2013: The Erdős Centennial Conference October 26, 2013 Some Definitions Graph Theory Chromatic

More information

Outline. CS38 Introduction to Algorithms. Approximation Algorithms. Optimization Problems. Set Cover. Set cover 5/29/2014. coping with intractibility

Outline. CS38 Introduction to Algorithms. Approximation Algorithms. Optimization Problems. Set Cover. Set cover 5/29/2014. coping with intractibility Outline CS38 Introduction to Algorithms Lecture 18 May 29, 2014 coping with intractibility approximation algorithms set cover TSP center selection randomness in algorithms May 29, 2014 CS38 Lecture 18

More information

Dijkstra s algorithm for shortest paths when no edges have negative weight.

Dijkstra s algorithm for shortest paths when no edges have negative weight. Lecture 14 Graph Algorithms II 14.1 Overview In this lecture we begin with one more algorithm for the shortest path problem, Dijkstra s algorithm. We then will see how the basic approach of this algorithm

More information

Lecture 7. s.t. e = (u,v) E x u + x v 1 (2) v V x v 0 (3)

Lecture 7. s.t. e = (u,v) E x u + x v 1 (2) v V x v 0 (3) COMPSCI 632: Approximation Algorithms September 18, 2017 Lecturer: Debmalya Panigrahi Lecture 7 Scribe: Xiang Wang 1 Overview In this lecture, we will use Primal-Dual method to design approximation algorithms

More information

Pred 8 1. Dist. Pred

Pred 8 1. Dist. Pred CS Graph Algorithms, Page Shortest Path Problem Task: given a graph G, find the shortest path from a vertex u to a vertex v. ffl If all edges are of the same length, then BFS will do. ffl But some times

More information

FINAL EXAM SOLUTIONS

FINAL EXAM SOLUTIONS COMP/MATH 3804 Design and Analysis of Algorithms I Fall 2015 FINAL EXAM SOLUTIONS Question 1 (12%). Modify Euclid s algorithm as follows. function Newclid(a,b) if a

More information

Spanning Trees, greedy algorithms. Lecture 22 CS2110 Fall 2017

Spanning Trees, greedy algorithms. Lecture 22 CS2110 Fall 2017 1 Spanning Trees, greedy algorithms Lecture 22 CS2110 Fall 2017 1 We demo A8 Your space ship is on earth, and you hear a distress signal from a distance Planet X. Your job: 1. Rescue stage: Fly your ship

More information

Chapter-6 Backtracking

Chapter-6 Backtracking Chapter-6 Backtracking 6.1 Background Suppose, if you have to make a series of decisions, among various choices, where you don t have enough information to know what to choose. Each decision leads to a

More information

Lesson 5: Identical Triangles

Lesson 5: Identical Triangles NS COMMON CORE MATHEMATICS CURRICULUM Lesson 5 7 6 Classwork Opening When studying triangles, it is essential to be able to communicate about the parts of a triangle without any confusion. The following

More information

Linear Programming. Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015

Linear Programming. Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015 Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015 Linear Programming 2015 Goodrich and Tamassia 1 Formulating the Problem q The function

More information