Graph Programs for Graph Algorithms

Slides:



Advertisements
Similar presentations
Graph Algorithms - 3 Algorithm Design and Analysis Victor AdamchikCS Spring 2014 Lecture 13Feb 12, 2014Carnegie Mellon University.
Advertisements

Algorithms (and Datastructures) Lecture 3 MAS 714 part 2 Hartmut Klauck.
Min Cost Flow: Polynomial Algorithms. Overview Recap: Min Cost Flow, Residual Network Potential and Reduced Cost Polynomial Algorithms Approach Capacity.
Single Source Shortest Paths
CS 206 Introduction to Computer Science II 04 / 01 / 2009 Instructor: Michael Eckmann.
2005conjunctive-ii1 Query languages II: equivalence & containment (Motivation: rewriting queries using views)  conjunctive queries – CQ’s  Extensions.
* Bellman-Ford: single-source shortest distance * O(VE) for graphs with negative edges * Detects negative weight cycles * Floyd-Warshall: All pairs shortest.
CS 206 Introduction to Computer Science II 11 / 10 / 2008 Instructor: Michael Eckmann.
1 Dijkstra's Shortest Path Algorithm Find shortest path from s to t. s 3 t
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
The Shortest Path Problem
IS 2610: Data Structures Graph April 5, 2004.
Minimum Spanning Trees CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Graph Algorithms. Definitions and Representation An undirected graph G is a pair (V,E), where V is a finite set of points called vertices and E is a finite.
All-Pairs Shortest Paths & Essential Subgraph 01/25/2005 Jinil Han.
Shortest Paths CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Verifying Programs with BDDs Topics Representing Boolean functions with Binary Decision Diagrams Application to program verification class-bdd.ppt
Reasoning about the Behavior of Semantic Web Services with Concurrent Transaction Logic Presented By Dumitru Roman, Michael Kifer University of Innsbruk,
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
IS 2610: Data Structures Graph April 12, Graph Weighted graph – call it networks Shortest path between nodes s and t in a network  Directed simple.
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Minimum Spanning Trees CSE 2320 – Algorithms and Data Structures Vassilis Athitsos and Alexandra Stefan University of Texas at Arlington These slides are.
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
1 IAS, Princeton ASCR, Prague. The Problem How to solve it by hand ? Use the polynomial-ring axioms ! associativity, commutativity, distributivity, 0/1-elements.
Introduction toData structures and Algorithms
Algorithm Analysis 1.
Shortest Paths.
The Theory of NP-Completeness
P & NP.
IOI/ACM ICPC Training 4 June 2005.
Minimum Spanning Trees
Inductive Proof (the process of deriving generalities from particulars) Mathematical Induction (reasoning over the natural numbers)
Software Testing.
Lectures linked lists Chapter 6 of textbook
Hans Bodlaender, Marek Cygan and Stefan Kratsch
Dijkstra’s Algorithm SSSP, non-neg Edge weights = w(x,y)
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
UNIT-3 LINKED LIST.
Graph-Based Operational Semantics
Recursive Thinking Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences.
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
Chapter 5. Optimal Matchings
Recursive Thinking Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences.
Symbolic Implementation of the Best Transformer
CS330 Discussion 6.
Various Graph Algorithms
COMP 175: Computer Graphics February 9, 2016
Software Testing (Lecture 11-a)
Greedy Algorithms / Dijkstra’s Algorithm Yin Tat Lee
Instructor: Shengyu Zhang
Analysis of Algorithms
Alternating tree Automata and Parity games
Shortest paths & Weighted graphs
Dijkstra’s Algorithm for the Shortest Path Problem
Analysis and design of algorithm
Advanced Algorithms Analysis and Design
Minimum Spanning Tree Algorithms
CSE332: Data Abstractions Lecture 18: Minimum Spanning Trees
Graphs and Algorithms (2MMD30)
All pairs shortest path problem
Algorithms: Design and Analysis
Algorithms: Design and Analysis
The Theory of NP-Completeness
CSE 373 Data Structures and Algorithms
UNINFORMED SEARCH -BFS -DFS -DFIS - Bidirectional
Verifying Programs with BDDs Sept. 22, 2006
Data Structures and Algorithm Analysis Lecture 8
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

Graph Programs for Graph Algorithms Sandra Steinert and Detlef Plump The University of York 22/03/05

Example: Graph Algorithm in C (Sedgewick) Graph ADT #include “Graph.h” typedef struct node *link; struct node { int v; double wt; link next; }; Struct graph { int V; int E; link *adj; }; link NEW(int v, double wt, link next) { link x = malloc(sizeof *x); x->v = v; x->wt = wt; x->next = next; return x; } Graph GRAPHinit(int V) { int i; Graph G = malloc(sizeof *G); G->adj = malloc(V*sizeof(link)); G->V = V; G->E = 0; for (i = 0; i < V; i++) G->adj[i] = NULL; return G; } Void GRAPHinsertE(Graph G, Edge e) { link t; int v = e.v, w = e.w; if (v == w) return; G->adj[v] = NEW(w, e.wt, G->adj[v]); G->E++ } Priority Queue Implementation #include “PQindex.h” Typedef int Item; static int N, pq[maxPQ+1], qp[maxPQ+1]; void exch(int i, int j) { int t; t = qp[i]; qp[i] = qp[j]; qp[j] = t; pq[qp[i]] = i; pq[qp[j]] = j; } void PQinit() { N = 0; } int PQempty() { return !N; } void PQinser(int k) { qp[k] = ++N; pq[N] = k; fixUp(pq, N); } int PQdelmax() { exch (pq[1], pq[N]); fixDown(pq, 1, - - N); return pq[N+1]; void PQchange(int k) { fixUp(pq, qp[k]); fixDown(pq, qp[k], N); Graph Algorithm #define GRAPHpfs GRAPHspt #define P (wt[v] + t->wt) void GRAPHpfs (Graph G, int s, double wt[ ]) { int v, w; link t; PQinit(); priority = wt; for (v = 0; v < G->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 < wt[w = t->v]) { wt[w] = P; PQdec(w) } } What problem does it solve? Dijkstra‘s single-source shortest path algorithm!

Graph Program Simple_Dijkstra IMPORTANT (point to): Two new concepts, labels in rules are terms over a fixed algebra, rules with conditions. Here explained only intuitively, later in detail (POINT TO): x is a variable, x+y is a term, where... Is a condition START NODE: we assume that our start loop has an attached loop with label *. Mention: terms as labels and conditions. New concepts are introduced later. Here only intuition

(Conditional) Rule Schemata x+y y x z 1 2 where (x+y) < z Conditional Rule Schema instantiation Instance (DPO rule with relabelling) 1 2 5 3 (PO) 1 2 3 42 5 Transformation Step

Graph Programs Semantics: non-deterministic one-step application of a set R of conditional rule schemata apply R “as long as possible” sequential composition Semantics:

Graph Program Simple_Dijkstra IMPORTANT (point to): Two new concepts, labels in rules are terms over a fixed algebra, rules with conditions. Here explained only intuitively, later in detail (POINT TO): x is a variable, x+y is a term, where... Is a condition START NODE: we assume that our start loop has an attached loop with label *. Mention: terms as labels and conditions. New concepts are introduced later. Here only intuition

Results for Simple_Dijkstra Proposition: Simple_Dijkstra always terminates (follows easily from rules) (2) Correctness: started from a graph containing an unique node s with tag _0, Simple_Dijkstra produces the graph which is obtained by labelling each node v with the shortest distance from s to v

Complexity worst case: exponential in the number of rule applications start node - S_Reduce can be applied times - best derivation: n-1 applications of S_Reduce We measure time complexity in the number of rule applications and ignore the cost of matching It turns out that Simple_Dijkstra is exponential. The reason is that Simple_Dijkstra is highly non-deterministic. Example a bit slower Don’t tell the sum: we this term here… Best derivation: linear The Problem here is the non-determinism. Thus, we reduced the non-determinism and show an improved program The non-determinism is responsible for the problem of exponential complexity

Graph Programs Semantics: Language Extension While: non-deterministic one-step application of a set R of conditional rule schemata apply R “as long as possible” sequential composition Semantics: Language Extension While: , where B is a graph {(B  B  B)} with B  B identity morphism on B

Graph Program Dijkstra Complexity: n + (n-1)² + e + (n-1) + 1 rule applications = O(n² + e) (O(n²) if parallel edges are forbidden) New concepts: edge predicate in a condition; prepare is executed iff such an edge does not exist New concepts: while loop; Program is executed as long as graph B occurs as a subgraph N-1 applications of while because in each step, a box loop is deleted by next At most n-1 applications of min (comparing one node with every other node) Reduce can only be applied once to each edge Next applied n-1 times because there are n-1 box labelled nodes and one of them is deleted in each iteration IMPORTANT: explain the program first, Prepare…, rules are given here…, Prepare adds a box-loop to every node! IMPORTANT: n^2 because then e is bound by n^2 (n square)

Conclusion Outlook GP is a simple, semantics-based language Dijkstra’s single-source shortest-path algorithm as case study: succinct programs, easy to understand; simple semantics supports formal reasoning Outlook example-driven development of GP: procedures, graph types, … more case studies in graph algorithms (e.g. Floyd-Warshall’s shortest path algorithm, vertex colouring) and other domains development of general proof patterns for termination, correctness and complexity implementation of GP (Greg Manning, The University of York) SAY: Our approach is similar to the one proposed by Schied in 1992 but we allow… Schied also has a condition concept: he allows arbitrary term equations SAY: types: for example type concepts of previous talk… Schied: propositional formulas over term equations