IS 2610: Data Structures Graph April 12, 2004. Graph Weighted graph – call it networks Shortest path between nodes s and t in a network  Directed simple.

Slides:



Advertisements
Similar presentations
1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 19 Prof. Erik Demaine.
Advertisements

Weighted graphs Example Consider the following graph, where nodes represent cities, and edges show if there is a direct flight between each pair of cities.
* Bellman-Ford: single-source shortest distance * O(VE) for graphs with negative edges * Detects negative weight cycles * Floyd-Warshall: All pairs shortest.
1 The TSP : Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell ( )
Advanced Algorithm Design and Analysis (Lecture 7) SW5 fall 2004 Simonas Šaltenis E1-215b
1 Chapter 26 All-Pairs Shortest Paths Problem definition Shortest paths and matrix multiplication The Floyd-Warshall algorithm.
Shortest Paths Algorithm Design and Analysis Week 7 Bibliography: [CLRS] – chap 24 [CLRS] – chap 25.
Design and Analysis of Algorithms Single-source shortest paths, all-pairs shortest paths Haidong Xue Summer 2012, at GSU.
The Theory of NP-Completeness
Lecture 17 Path Algebra Matrix multiplication of adjacency matrices of directed graphs give important information about the graphs. Manipulating these.
Chapter 25: All-Pairs Shortest-Paths
 2004 SDU Lecture11- All-pairs shortest paths. Dynamic programming Comparing to divide-and-conquer 1.Both partition the problem into sub-problems 2.Divide-and-conquer.
Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.
All Pairs Shortest Paths and Floyd-Warshall Algorithm CLRS 25.2
CS420 lecture twelve Shortest Paths wim bohm cs csu.
The Theory of NP-Completeness
Design and Analysis of Algorithms - Chapter 81 Dynamic Programming Dynamic Programming is a general algorithm design technique Dynamic Programming is a.
Lecture 22: Matrix Operations and All-pair Shortest Paths II Shang-Hua Teng.
Shortest Path Algorithm By Weston Vu CS 146. What is Shortest Paths? Shortest Paths is a part of the graph algorithm. It is used to calculate the shortest.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 16 All shortest paths algorithms Properties of all shortest paths Simple algorithm:
CSE 421 Algorithms Richard Anderson Lecture 27 NP Completeness.
Algorithms All pairs shortest path
Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
All-Pairs Shortest Paths Given an n-vertex directed weighted graph, find a shortest path from vertex i to vertex j for each of the n 2 vertex pairs (i,j).
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
IS 2610: Data Structures Graph April 5, 2004.
Directed graphs Definition. A directed graph (or digraph) is a pair (V, E), where V is a finite non-empty set of vertices, and E is a set of ordered pairs.
1 The Theory of NP-Completeness 2012/11/6 P: the class of problems which can be solved by a deterministic polynomial algorithm. NP : the class of decision.
Chapter 2 Graph Algorithms.
CSCE350 Algorithms and Data Structure Lecture 17 Jianjun Hu Department of Computer Science and Engineering University of South Carolina
Minimum Spanning Trees CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Week 10Complexity of Algorithms1 Hard Computational Problems Some computational problems are hard Despite a numerous attempts we do not know any efficient.
All-Pairs Shortest Paths & Essential Subgraph 01/25/2005 Jinil Han.
1 The Floyd-Warshall Algorithm Andreas Klappenecker.
All-pairs Shortest Paths. p2. The structure of a shortest path: All subpaths of a shortest path are shortest paths. p : a shortest path from vertex i.
Parallel Programming: All-Pairs Shortest Path CS599 David Monismith Based upon notes from multiple sources.
Shortest Path Algorithms. Definitions Variants  Single-source shortest-paths problem: Given a graph, finding a shortest path from a given source.
Shortest Paths CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
The all-pairs shortest path problem (APSP) input: a directed graph G = (V, E) with edge weights goal: find a minimum weight (shortest) path between every.
CSE 421 Algorithms Richard Anderson Lecture 27 NP-Completeness and course wrap up.
Lecture 6 NP Class. P = ? NP = ? PSPACE They are central problems in computational complexity.
Data Structures & Algorithms Shortest Paths Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Design and Analysis of Algorithms - Chapter 101 Our old list of problems b Sorting b Searching b Shortest paths in a graph b Minimum spanning tree b Primality.
NP-Completeness (Nondeterministic Polynomial Completeness) Sushanth Sivaram Vallath & Z. Joseph.
1 Prim’s algorithm. 2 Minimum Spanning Tree Given a weighted undirected graph G, find a tree T that spans all the vertices of G and minimizes the sum.
“One ring to rule them all” Analogy (sort of) Lord of The Rings Computational Complexity “One problem to solve them all” “my preciousss…”
All-Pairs Shortest Paths
Graphs Upon completion you will be able to:
Lecture 25 NP Class. P = ? NP = ? PSPACE They are central problems in computational complexity.
NPC.
CSE 421 Algorithms Richard Anderson Lecture 27 NP-Completeness Proofs.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
COSC 3101A - Design and Analysis of Algorithms 14 NP-Completeness.
P, NP, and NP-Complete Problems Section 10.3 The class P consists of all problems that can be solved in polynomial time, O(N k ), by deterministic computers.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
Minimum Spanning Trees CSE 2320 – Algorithms and Data Structures Vassilis Athitsos and Alexandra Stefan University of Texas at Arlington These slides are.
The Theory of NP-Completeness
Limitation of Computation Power – P, NP, and NP-complete
Minimum Spanning Trees
Richard Anderson Lectures NP-Completeness
Lecture 2-2 NP Class.
Richard Anderson Lecture 29 NP-Completeness and course wrap-up
Richard Anderson Lecture 26 NP-Completeness
Graph Programs for Graph Algorithms
Minimum Spanning Trees
Richard Anderson Lecture 30 NP-Completeness
All pairs shortest path problem
Weighted Graphs & Shortest Paths
Text Book: Introduction to algorithms By C L R S
ADVANCED COMPUTATIONAL MODELS AND ALGORITHMS
Presentation transcript:

IS 2610: Data Structures Graph April 12, 2004

Graph Weighted graph – call it networks Shortest path between nodes s and t in a network  Directed simple path from s to t with the property that no other such path has a lower weight  Negative edges? Applications ?

Shortest Path The shortest path problem has several different forms:  Source-sink SP: Given two nodes A and B, find the shortest path in the weighted graph from A to B.  Single source SP: Given a node A, find the shortest path from A to every other node in the graph.  All Pair SP: Find the shortest path between every pair of nodes in the graph

Basic concept in SP Relaxation  At each step increment the SP information  Path relaxation Test if traveling through a given vertex introduces a new shortest path between a pair of vertices  Edge relaxation : special case of path relaxation Test if traveling through a given edge gives a new shortest path to its destination vertex If (wt[w] > wt[v] + e.wt) { wt[w] = wt[v] + e.wt; st[w] = v;}

Relaxation Edge relaxation w v s w v s ws ws v v Path relaxation

Shortest Path Property 21.1  If a vertex x is on a shortest path from s to t, then that path consists of a shortest path from s to x followed by a shortest path from x to t Dijkstra’s algorithm (similar to Prim’s MST)  Start at source  Include next edge that gives the shortest path from the source to a vertex not in the SP

Shortest path To select the next node to visit, we must choose the node in the fringe that has the shortest path to A. The shortest path from the next closest node must immediately go to a visited node. Visited nodes form a shortest path tree Fringe node set

Dijkstra’s algorithm Complexity? Fringe v 0 v 1, v 0 v 2, v 0 v 4 v 0 v 1, v 0 v 4, v 2 v 3 v 0 v 1, v 0 v 4, v 3 v 1 ( v 3 v 4 ?) v 0 v 4 v0v0 v1v1 v4v4 v2v2 v3v3 v5v

Dijkstra’s algorithm #define GRAPHpfs GRAPHspt #define P (wt[v] + t->wt) void GRAPHpfs(Graph G, int s, int st[], double wt[]) { int v, w; link t; PQinit(); priority = wt; for (v = 0; v V; v++) { st[v] = -1; wt[v] = maxWT; PQinsert(v); } wt[s] = 0.0; PQdec(s); while (!PQempty()) if (wt[v = PQdelmin()] != maxWT) for (t = G->adj[v]; t != NULL; t = t->next) if (P v]) { wt[w] = P; PQdec(w); st[w] = v; } }

All-pairs shortest path Use Dijkstra’s algorithm from each vertex  Complexity: VElgV Floyd’s algorithm  Use extension of Warshall’s algorithm for transitive closure  Complexity: V 3

Floyd-Warshall Algorithm D ij (k) = length of shortest path from i to j with intermediate vertices from {1, 2,..., k}: Dynamic Programming: recurrence  D ij (0) = D ij  D ij (k) = min {D ij (k-1), D ik (k-1) + D kj (k-1) } intermediate nodes in {1, 2,..., k} j i D ik (k-1) D kj (k-1) k D ij (k-1)

The Floyd-Warshall algorithm = { Floyd-Warshall(W)  (n 3 ) 1n  rows[W] 2 D (0) = W 3for k  1 to n 4 do for i  1 to n 5do for j  1 to n 6 7return D (n) calculate D (0),D (1),D (2), D (3),D (4) and D (5) if k = 0 if k  1 4 2

Floyd-Warshall Algorithm void GRAPHspALL(Graph G) { int i, s, t; double **d = MATRIXdouble(G->V, G->V, maxWT); int **p = MATRIXint(G->V, G->V, G->V); for (s = 0; s V; s++) for (t = 0; t V; t++) if ((d[s][t] = G->adj[s][t]) < maxWT) p[s][t] = t; for (i = 0; i V; i++) for (s = 0; s V; s++) if (d[s][i] < maxWT) for (t = 0; t V; t++) if (d[s][t] > d[s][i]+d[i][t]) { p[s][t] = p[s][i]; d[s][t] = d[s][i]+d[i][t]; } G->dist = d; G->path = p; }

Complexity classes An algorithm A is of polynomial complexity if there exists a polynomial p(n) such that the computing time of A is O(p(n)) Set P  set of decision problems solvable in polynomial time using deterministic algorithm Deterministic: result of each step is uniquely defined Set NP  set of decision problem solvable in polynomial time using nondeterministic algorithm Non-deterministic: result of each step is a set of possibilities P  NP  Problem is P = NP or P  NP?

Complexity classes Satisfiability is in P iff P = NP NP-hard problems  Reduction L1 reduces to L2 Iff there is a way to solve L1 in deterministic polynomial time algorithm using deterministic algorithm that solves L2 in polynomial time  A problem L is NP-hard iff satisfiability reduces to L NP-complete  L is in NP  L is NP-hard

Showing a problem NP-complete Show that it is in NP Show that it is NP-hard  Pick problem L already known to be NP-hard  Show that the problem can be reduced to L Example  Show that traveling salesman problem is NP- complete  Known: directed Hamiltonian cycle problem is NP- complete