Graph Programs for Graph Algorithms - PowerPoint PPT Presentation

About This Presentation
Title:

Graph Programs for Graph Algorithms

Description:

Graph Programs for Graph Algorithms Sandra Steinert and Detlef Plump The University of York 22/03/05 Example: Graph Algorithm in C (Sedgewick) Graph Program Simple ... – PowerPoint PPT presentation

Number of Views:181
Avg rating:3.0/5.0
Slides: 12
Provided by: San7265
Category:

less

Transcript and Presenter's Notes

Title: Graph Programs for Graph Algorithms


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

2
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-gtv v
x-gtwt wt x-gtnext next return x
Graph GRAPHinit(int V) int i Graph
G malloc(sizeof G) G-gtadj
malloc(Vsizeof(link)) G-gtV V G-gtE
0 for (i 0 i lt V i) G-gtadji
NULL return G Void GRAPHinsertE(Graph
G, Edge e) link t int v e.v, w
e.w if (v w) return G-gtadjv
NEW(w, e.wt, G-gtadjv) G-gtE
Priority Queue Implementation include
PQindex.h Typedef int Item static int N,
pqmaxPQ1, qpmaxPQ1 void exch(int i, int
j) int t t qpi qpi qpj
qpj t pqqpi i pqqpj j
void PQinit() N 0 int PQempty() return
!N void PQinser(int k) qpk N pqN
k fixUp(pq, N) int PQdelmax() exch
(pq1, pqN) fixDown(pq, 1, - - N)
return pqN1 void PQchange(int k)
fixUp(pq, qpk) fixDown(pq, qpk, N)
Graph Algorithm define GRAPHpfs GRAPHspt define
P (wtv t-gtwt) void GRAPHpfs (Graph G, int s,
double wt ) int v, w link t PQinit()
priority wt for (v 0 v lt G-gtV v)
stv -1 wtv maxWT
PQinsert(v) wts 0.0 PQdec(s)
while (!PQempty()) if (wtv PQdelmin()
! maxWT) for (t G-gtadjv t !
NULL t t-gtnext)
if (P lt wtw t-gtv) wtw
P PQdec(w)
What problem does it solve?
Dijkstras single-source shortest path algorithm!
3
Graph Program Simple_Dijkstra
4
(Conditional) Rule Schemata
Conditional Rule Schema
Instance (DPO rule with relabelling)
Transformation Step
5
Graph Programs
6
Graph Program Simple_Dijkstra
7
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

8
Complexity
  • worst case exponential in the number of rule
    applications

start node
- best derivation n-1 applications of S_Reduce
9
Graph Programs
10
Graph Program Dijkstra
11
Conclusion
  • GP is a simple, semantics-based language
  • Dijkstras 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-Warshalls 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)
Write a Comment
User Comments (0)
About PowerShow.com