Introduction to Algorithms 6.046J/18.401J/SMA5503

Slides:



Advertisements
Similar presentations
You have been given a mission and a code. Use the code to complete the mission and you will save the world from obliteration…
Advertisements

Unit-iv.
Analysis of Algorithms
and 6.855J Cycle Canceling Algorithm. 2 A minimum cost flow problem , $4 20, $1 20, $2 25, $2 25, $5 20, $6 30, $
October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.
February 21, 2002 Simplex Method Continued
1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 19 Prof. Erik Demaine.
Introduction to Algorithms
© 2001 by Charles E. Leiserson Introduction to AlgorithmsDay 18 L10.1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 10 Prof. Erik Demaine.
© 2001 by Charles E. Leiserson Introduction to AlgorithmsDay 17 L9.1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 9 Prof. Charles E. Leiserson.
©2001 by Charles E. Leiserson Introduction to AlgorithmsDay 9 L6.1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 6 Prof. Erik Demaine.
Introduction to Algorithms 6.046J/18.401J/SMA5503
Tuesday, March 5 Duality – The art of obtaining bounds – weak and strong duality Handouts: Lecture Notes.
February 14, 2002 Putting Linear Programs into standard form
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
1 LP, extended maxflow, TRW OR: How to understand Vladimirs most recent work Ramin Zabih Cornell University.
ZMQS ZMQS
Graph Algorithms - 3 Algorithm Design and Analysis Victor AdamchikCS Spring 2014 Lecture 13Feb 12, 2014Carnegie Mellon University.
1 Outline relationship among topics secrets LP with upper bounds by Simplex method basic feasible solution (BFS) by Simplex method for bounded variables.
Fibonacci Numbers F n = F n-1 + F n-2 F 0 =0, F 1 =1 – 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 … Straightforward recursive procedure is slow! Why? How slow? Lets.
1 Column Generation. 2 Outline trim loss problem different formulations column generation the trim loss problem master problem and subproblem in column.
Randomized Algorithms Randomized Algorithms CS648 1.
ABC Technology Project
COMP 482: Design and Analysis of Algorithms
Comp 122, Spring 2004 Graph Algorithms – 2. graphs Lin / Devi Comp 122, Fall 2004 Identification of Edges Edge type for edge (u, v) can be identified.
Advanced Algorithm Design and Analysis Jiaheng Lu Renmin University of China
演 算 法 實 驗 室演 算 法 實 驗 室 On the Minimum Node and Edge Searching Spanning Tree Problems Sheng-Lung Peng Department of Computer Science and Information Engineering.
Name Convolutional codes Tomashevich Victor. Name- 2 - Introduction Convolutional codes map information to code bits sequentially by convolving a sequence.
1 Breadth First Search s s Undiscovered Discovered Finished Queue: s Top of queue 2 1 Shortest path from s.
8.6 Linear Programming. Linear Program: a mathematical model representing restrictions on resources using linear inequalities combined with a function.
Squares and Square Root WALK. Solve each problem REVIEW:
The simplex algorithm The simplex algorithm is the classical method for solving linear programs. Its running time is not polynomial in the worst case.
Chapter 5 Test Review Sections 5-1 through 5-4.
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
Addition 1’s to 20.
25 seconds left…...
Complexity ©D.Moshkovits 1 Where Can We Draw The Line? On the Hardness of Satisfiability Problems.
Week 1.
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Dantzig-Wolfe Decomposition
Bart Jansen 1.  Problem definition  Instance: Connected graph G, positive integer k  Question: Is there a spanning tree for G with at least k leaves?
Epp, section 10.? CS 202 Aaron Bloomfield
 Theorem 5.9: Let G be a simple graph with n vertices, where n>2. G has a Hamilton circuit if for any two vertices u and v of G that are not adjacent,
all-pairs shortest paths in undirected graphs
Linear Programming (LP) (Chap.29)
C&O 355 Mathematical Programming Fall 2010 Lecture 22 N. Harvey TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A A A.
Single-Source Shortest- paths. p2. Shortest-paths problems : G=(V,E) : weighted, directed graph w : E  R : weight function P=
Introduction to Algorithms 6.046J/18.401J/SMA5503
How should we define corner points? Under any reasonable definition, point x should be considered a corner point x What is a corner point?
Basic Feasible Solutions: Recap MS&E 211. WILL FOLLOW A CELEBRATED INTELLECTUAL TEACHING TRADITION.
Tirgul 12 Algorithm for Single-Source-Shortest-Paths (s-s-s-p) Problem Application of s-s-s-p for Solving a System of Difference Constraints.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 15 Shortest paths algorithms Properties of shortest paths Bellman-Ford algorithm.
C&O 355 Mathematical Programming Fall 2010 Lecture 17 N. Harvey TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AA A.
Theory of Computing Lecture 13 MAS 714 Hartmut Klauck.
C&O 355 Lecture 19 N. Harvey TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A A A A A A A A A A.
TU/e Algorithms (2IL15) – Lecture 12 1 Linear Programming.
TU/e Algorithms (2IL15) – Lecture 12 1 Linear Programming.
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Problem Solving 4.
Analysis of Algorithms
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Analysis of Algorithms
Presentation transcript:

Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 18 Prof. Erik Demaine

Negative-weight cycles Recall: If a graph G = (V, E) contains a negative- weight cycle, then some shortest paths may not exist. Bellman-Ford algorithm: Finds all shortest-path lengths from a source s  V to all v  V or determines that a negative-weight cycle exists. © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

Bellman-Ford algorithm d[s] ← 0 for each v  V – {s} do d[v] ←  for i ← 1 to |V| – 1 do for each edge (u, v)  E do if d[v] > d[u] + w(u, v) then d[v] ← d[u] + w(u, v) for each edge (u, v)  E then report that a negative-weight cycle exists At the end, d[v] = (s, v). Time = O(VE) initialization relaxation step © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

Example of Bellman-Ford © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

Example of Bellman-Ford © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

Example of Bellman-Ford © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

Example of Bellman-Ford © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

Example of Bellman-Ford © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

Example of Bellman-Ford © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

Example of Bellman-Ford © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

Example of Bellman-Ford © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

Example of Bellman-Ford Note: Values decrease monotonically. © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

Correctness Theorem. If G = (V, E) contains no negative- weight cycles, then after the Bellman-Ford algorithm executes, d[v] = (s, v) for all v  V. Proof. Let v  V be any vertex, and consider a shortest path p from s to v with the minimum number of edges. Since p is a shortest path, we have (s, vi) = (s, vi-1) + w(vi-1 , vi) . © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

Correctness (continued) Initially, d[v0] = 0 =  (s, v0), and d[s] is unchanged by subsequent relaxations (because of the lemma from Lecture 17 that d[v] ≥  (s, v)). After 1 pass through E, we have d[v1] = (s, v1). After 2 passes through E, we have d[v2] = (s, v2). After k passes through E, we have d[vk] = (s, vk). Since G contains no negative-weight cycles, p is simple. Longest simple path has ≤|V| – 1 edges. © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

Detection of negative-weight cycles Corollary. If a value d[v] fails to converge after |V| – 1 passes, there exists a negative-weight cycle in G reachable from s. © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

DAG shortest paths If the graph is a directed acyclic graph (DAG), we first topologically sort the vertices. Determine f : V → {1, 2, …, |V|} such that (u, v)  E  f (u) < f (v). O(V + E) time using depth-first search. Walk through the vertices u  V in this order, relaxing the edges in Adj[u], thereby obtaining the shortest paths from s in a total of O(V + E) time. © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

Linear programming Let A be an m× n matrix, b be an m-vector, and c be an n-vector. Find an n-vector x that maximizes cTx subject to Ax ≤ b, or determine that no such solution exists. © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

Linear-programming algorithms Algorithms for the general problem Simplex methods — practical, but worst-case exponential time. Ellipsoid algorithm — polynomial time, but slow in practice. Interior-point methods — polynomial time and competes with simplex. Feasibility problem: No optimization criterion. Just find x such that Ax ≤ b. In general, just as hard as ordinary LP. © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

Solving a system of difference constraints Linear programming where each row of A contains exactly one 1, one –1, and the rest 0’s. Example: Solution: x1 – x2 ≤ 3 x2 – x3 ≤ –2 x1 – x3 ≤ 2 x1 = 3 x2 = 0 x3 = 2 xj – xi ≤ wij Constraint graph: (The “A” matrix has dimensions |E| × |V|.) xj – xi ≤ wij © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

Unsatisfiable constraints Theorem. If the constraint graph contains a negative-weight cycle, then the system of differences is unsatisfiable. Proof. Suppose that the negative-weight cycle is v1 → v2 →  → vk → v1. Then, we have x2 – x1 ≤ w12 x3 – x2 ≤ w23 xk – xk-1 ≤ wk–1, k x1 – xk ≤ wk1 Therefore, no values for the xi can satisfy the constraints. 0 ≤ weight of cycle < 0 © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

Satisfying the constraints Theorem. Suppose no negative-weight cycle exists in the constraint graph. Then, the constraints are satisfiable. Proof. Add a new vertex s to V with a 0-weight edge to each vertex vi  V. Note: No negative-weight cycles introduced  shortest paths exist. © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

Proof (continued) Claim: The assignment xi = (s, vi) solves the constraints. Consider any constraint xj – xi ≤ wij, and consider the shortest paths from s to vj and vi: The triangle inequality gives us (s,vj) ≤ (s, vi) + wij. Since xi = (s, vi) and xj = (s, vj), the constraint xj – xi ≤ wij is satisfied. © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

Bellman-Ford and linear programming Corollary. The Bellman-Ford algorithm can solve a system of m difference constraints on n variables in O(mn) time. Single-source shortest paths is a simple LP problem. In fact, Bellman-Ford maximizes x1 + x2 + + xn subject to the constraints xj – xi ≤ wij and xi ≤ 0 (exercise). Bellman-Ford also minimizes maxi{xi} – mini{xi} … © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

Application to VLSI layout compaction Integrated -circuit features: minimum separation λ Problem: Compact (in one dimension) the space between the features of a VLSI layout without bringing any features too close together. © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.

VLSI layout compaction Constraint: x2 – x1 ≥ d1 + λ Bellman-Ford minimizes maxi{xi} – mini{xi}, which compacts the layout in the x-dimension. © 2001 by Charles E. Leiserson Introduction to Algorithms Day 31 L18.