home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / leda / man / graph_al.tex < prev    next >
Encoding:
Text File  |  1991-11-15  |  11.1 KB  |  332 lines

  1. \bigskip
  2. \bigskip
  3. {\magonebf 5.12 Graph Algorithms} 
  4. \bigskip
  5.  
  6. This sections gives a summary of the graph algorithms contained in LEDA.
  7. All algorithms are generic, i.e., they accept instances of any user defined
  8. parameterized graph type GRAPH($vtype,etype$) as arguments.
  9.  
  10. \bigskip
  11. {\bf 5.12.1 Basic Algorithms}
  12.  
  13. \bigskip
  14. $\bullet$ {\bf Topological Sorting}
  15.  
  16. $bool$ TOPSORT($graph\&\ G,\ node\_array(int)\&\ ord$)
  17.  
  18. TOPSORT takes as argument a directed graph $G(V,E)$. It sorts $G$ topologically 
  19. (if $G$ is acyclic) by computing for every node $v \in V$ an integer $ord[v]$ 
  20. such that $1\le ord[v]\le |V|$ and $ord[v] < ord[w]$ for all edges 
  21. $(v,w) \in E$. TOPSORT returns true if $G$ is acyclic and false otherwise.
  22.  
  23. Running Time: $O(|V|+|E|)$
  24.  
  25.  
  26.  
  27. \bigskip
  28. \bigskip
  29. $\bullet$ {\bf Depth First Search}
  30.  
  31. $list(node)$  DFS($graph\&\ G,\ node\ s,\ node\_array(bool)\&\ reached$) 
  32.  
  33. DFS takes as argument a directed graph $G(V,E)$, a node $s$ of $G$ and a 
  34. node\_array $reached$ of boolean values. It performs a depth first search 
  35. starting at $s$ visiting all reachable nodes $v$ with $reached[v]$ = false. 
  36. For every visited node $v$ $reached[v]$ is changed to true. DFS returns the 
  37. list of all reached nodes.
  38.  
  39. Running Time: $O(|V|+|E|)$
  40.  
  41.  
  42. \bigskip
  43. \cleartabs
  44. \+$list(edge)$  DFS\_NUM($graph\&\ G$, &$node\_array(int)\&\ dfsnum$,\cr
  45. \+                                     &$node\_array(int)\&\ compnum$)\cr
  46.  
  47. DFS\_NUM takes as argument a directed graph $G(V,E)$. It performs a 
  48. depth first search of $G$ numbering the nodes of $G$ in two different ways. 
  49. $dfsnum$ is a numbering with respect to the calling time and $compnum$ a 
  50. numbering with respect to the completion time of the recursive calls. DFS\_NUM 
  51. returns a depth first search forest of $G$ (list of tree edges).
  52.  
  53. Running Time: $O(|V|+|E|)$
  54.  
  55.  
  56. \bigskip
  57. \bigskip
  58. $\bullet$ {\bf Breadth First Search}
  59.  
  60. $list(node)$   BFS($graph\&\ G,\ node\ s,\ node\_array(int)\&\ dist$)
  61.  
  62. BFS takes as argument a directed graph $G(V,E)$ and a node $s$ of $G$. It 
  63. performs a breadth first search starting at $s$ computing for every visited 
  64. node $v$ the distance (length of a shortest path) $dist[v]$ from $s$ to $v$. 
  65. BFS returns the list of all reached nodes.
  66.  
  67. Running Time: $O(|V|+|E|)$
  68.  
  69. \bigskip
  70. \bigskip
  71. $\bullet$ {\bf Connected Components}
  72.  
  73. $int$   COMPONENTS($ugraph\&\ G,\ node\_array(int)\&\ compnum$)
  74.  
  75. COMPONENTS takes an undirected graph $G(V,E)$ as argument and computes 
  76. for every node $v\in V$ an integer $compnum[v]$ from $[0\dots c-1]$ where
  77. $c$ is the number of connected components of $G$ and 
  78. $v$ belongs to the $i$-th connected component iff $compnum[v] = i$.
  79. COMPONENTS returns $c$.
  80.  
  81. Running Time: $O(|V|+|E|)$
  82.  
  83.  
  84. \bigskip
  85. $\bullet$ {\bf Strong Connected Components}
  86.  
  87. $int$   STRONG\_COMPONENTS($graph\&\ G,\ node\_array(int)\&\ compnum$)
  88.  
  89. STRONG\_COMPONENTS takes a directed graph $G(V,E)$ as argument and computes for 
  90. every node $v\in V$ an integer $compnum[v]$ from $[0\dots c-1]$ where
  91. $c$ is the number of strongly connected components of $G$ and
  92. $v$ belongs to the $i$-th strongly connected component iff $compnum[v] = i$.
  93. STRONG\_COMPONENTS returns $c$.
  94.  
  95. Running Time: $O(|V|+|E|)$
  96.  
  97. \bigskip
  98. $\bullet$ {\bf Transitive Closure}
  99.  
  100. $graph$ TRANSITIVE\_CLOSURE($graph\&\ G$)
  101.  
  102. TRANSITIVE\_CLOSURE takes a directed graph $G(V,E)$ as argument and computes the 
  103. transitive closure of $G(V,E)$. It returns a directed graph $G\'(V\',E\')$ with
  104. $V\' = V$ and $(v,w) \in E\'  \Leftrightarrow$ there is a path form
  105. $v$ to $w$ in $G$.
  106.  
  107. Running Time: $O(|V|\cdot |E|)$
  108.  
  109.  
  110.  
  111.  
  112.  
  113. \bigskip
  114. {\bf 5.12.2 Network Algorithms}
  115.  
  116. Most of the following network algorithms are overloaded. They work
  117. for both integer and real valued edge costs.
  118.  
  119. \bigskip
  120. $\bullet$ {\bf Single Source Shortest Paths }
  121.  
  122. \medskip
  123. \cleartabs
  124. \+$void$ DIJKSTRA($graph\&\ G,\ node\ s$,\ edge\_array(int)\ $cost$,
  125.                                           &$node\_array(int)$\ \ \ &$dist$,\cr
  126. \+                                        &$node\_array(edge)$     &$pred$)\cr
  127. \medskip
  128. \cleartabs
  129. \+$void$ DIJKSTRA($graph\&\ G,\ node\ s$,\ edge\_array(real)\ $cost$,
  130.                                           &$node\_array(real)$\ \ \ &$dist$,\cr
  131. \+                                        &$node\_array(edge)$     &$pred$)\cr
  132.  
  133. DIJKSTRA takes as arguments a directed graph G(V,E), a source node $s$ and an 
  134. edge\_array $cost$ giving for each edge in $G$ a non-negative cost. It 
  135. computes for each node $v$ in $G$ the distance $dist[v]$ from $s$ (cost of the 
  136. least cost path from $s$ to $v$) and the predecessor edge $pred[v]$ in the 
  137. shortest path tree.
  138.  
  139. Running Time: $O(|E|+|V|\log |V|)$
  140.  
  141. \bigskip
  142. \cleartabs
  143. \+$bool$ BELLMAN\_FORD($graph\&\ G,\ node\ s$, 
  144.                        &$edge\_array(int)$\ \ &$cost$,\cr
  145. \+                     &$node\_array(int)$    &$dist$,\cr
  146. \+                     &$node\_array(int)$    &$pred$)\cr
  147. \medskip
  148. \cleartabs
  149. \+$bool$ BELLMAN\_FORD($graph\&\ G,\ node\ s$, 
  150.                        &$edge\_array(real)$\ \ &$cost$,\cr
  151. \+                     &$node\_array(real)$    &$dist$,\cr
  152. \+                     &$node\_array(edge)$    &$pred$)\cr
  153.  
  154. BELLMAN\_FORD takes as arguments a graph G(V,E), a source node $s$ and an 
  155. edge\_array $cost$ giving for each edge in $G$ a real (integer) cost. It 
  156. computes for each node $v$ in $G$ the distance $dist[v]$ from $s$ (cost of 
  157. the least cost path from $s$ to $v$) and the predecessor edge $pred[v]$ in 
  158. the shortest path tree. BELLMAN\_FORD returns false if there is a negative
  159. cycle in $G$ and true otherwise
  160.  
  161. Running Time: $O(|V|\cdot|E|)$
  162.  
  163. \bigskip
  164. \bigskip
  165. $\bullet$ {\bf All Pairs Shortest Paths }
  166.  
  167. \cleartabs
  168. \+$void$ ALL\_PAIRS\_SHORTEST\_PATHS($graph\&\ G$,
  169.                                      &$edge\_array(int)$\&\ \ \ &$cost$,\cr
  170. \+                                   &$node\_matrix(int)$\&  &$dist$)\cr
  171. \medskip
  172. \cleartabs
  173. \+$void$ ALL\_PAIRS\_SHORTEST\_PATHS($graph\&\ G$,
  174.                                      &$edge\_array(real)$\&\ \ \ &$cost$,\cr
  175. \+                                   &$node\_matrix(real)$\&  &$dist$)\cr
  176.  
  177. ALL\_PAIRS\_SHORTES\_PATHS takes as arguments a graph $G(V,E)$ and an 
  178. edge\_array $cost$ giving for each edge in $G$ a real (integer) valued cost. 
  179. It computes for each node pair $(v,w)$ of $G$ the distance $dist(v,w)$ from 
  180. $v$ to $w$ (cost of the least cost path from $v$ to $w$).
  181.  
  182. Running Time: $O(|V|\cdot|E| + |V|^2 \log|V|)$
  183.  
  184. \bigskip
  185. \bigskip
  186. $\bullet$ {\bf Maximum Flow }
  187.  
  188. \medskip
  189. \cleartabs
  190. \+$int$ MAX\_FLOW($graph\&\ G,\ node\ s,\ node\ t$, 
  191.                                                &$edge\_array(int)\&\ cap$,\cr
  192. \+                                             &$edge\_array(int)\&\ flow$)\cr
  193. \medskip
  194. \+$int$ MAX\_FLOW($graph\&\ G,\ node\ s,\ node\ t$, 
  195.                                                &$edge\_array(real)\&\ cap$,\cr
  196. \+                                             &$edge\_array(real)\&\ flow$)\cr
  197.  
  198. MAX\_FLOW takes as arguments a directed graph $G(V,E)$, a source node $s$, a 
  199. sink node $t$ and an edge\_array $cap$ giving for each edge in $G$ a capacity. 
  200. It computes for every edge $e$ in $G$ a flow $flow[e]$ such that the total 
  201. flow from $s$ to $t$ is maximal and $flow[e] \le cap[e]$ for all edges $e$. 
  202. MAXFLOW returns the total flow from $s$ to $t$.
  203.  
  204. Running Time: $O(|V|^3)$
  205.  
  206.  
  207. \bigskip
  208. \bigskip
  209. $\bullet$ {\bf Maximum Cardinality Bipartite Matching}
  210.  
  211. \medskip
  212. \cleartabs
  213. \+$list(edge)$ MAX\_CARD\_BIPARTITE\_MATCHING($graph\&\ G$, 
  214.                                               &$list(node)\&\ A$,\cr
  215. \+                                            &$list(node)\&\ B$)\cr
  216.  
  217. MAX\_CARD\_BIPARTITE\_MATCHING takes as arguments a directed graph $G(V,E)$ and
  218. two lists $A$ and $B$ of nodes. All edges in $G$ must be directed from nodes
  219. in $A$ to nodes in $B$. It computes a maximum cardinality bipartite matching
  220. of $G$, i.e., a maximal set of edges $M$ such that no two edges in $M$ share 
  221. an end point (target or source). MAX\_CARD\_BIPARTITE\_MATCHING returns $M$ as 
  222. a list of edges.
  223.  
  224. Running Time: $O(|E|\sqrt{|V|})$
  225.  
  226.  
  227. \bigskip
  228. $\bullet$ {\bf Maximum Weight Bipartite Matching}
  229.  
  230. \cleartabs
  231. \+$list(edge)$ MAX\_WEIGHT\_BIPARTITE\_MATCHING(&$graph\&\ G$,\cr 
  232. \+                                              &$list(node)\&\ A$,\cr
  233. \+                                              &$list(node)\&\ B$,\cr
  234. \+                                              &$edge\_array(int)\&\ weight$)\cr
  235.  
  236. \vfill\eject
  237.  
  238. \cleartabs
  239. \+$list(edge)$ MAX\_WEIGHT\_BIPARTITE\_MATCHING(&$graph\&\ G$,\cr 
  240. \+                                              &$list(node)\&\ A$,\cr
  241. \+                                              &$list(node)\&\ B$,\cr
  242. \+                                              &$edge\_array(real)\&\ weight$)\cr
  243.  
  244. MAX\_WEIGHT\_BIPARTITE\_MATCHING takes as arguments a directed graph $G$, 
  245. two lists $A$ and $B$ of nodes and an edge\_array giving for each edge an 
  246. integer (real) weight. All edges in $G$ must be directed from nodes in $A$ 
  247. to nodes in $B$. 
  248. It computes a maximum weight bipartite matching of $G$, i.e., a set of edges $M$
  249. such that the sum of weights of all edges in $M$ is maximal and no two edges 
  250. in $M$ share an end point. MAX\_WEIGHT\_BIPARTITE\_MATCHING returns $M$ as a 
  251. list of edges.
  252.  
  253. Running Time: $O(|V|\cdot |E|)$
  254.  
  255. \bigskip
  256. \bigskip
  257. $\bullet$ {\bf Spanning Tree}
  258.  
  259. \medskip
  260. $list(edge)$ SPANNING\_TREE($ugraph\&\ G$)
  261.  
  262. SPANNING\_TREE takes as argument an undirected graph $G(V,E)$. It computes
  263. a spanning tree $T$ of $G$, SPANNING\_TREE returns the list of edges of $T$.
  264.  
  265. Running Time: $O(|V|+|E|)$
  266.  
  267. \bigskip
  268. \bigskip
  269. $\bullet$ {\bf Minimum Spanning Tree}
  270.  
  271. $list(edge)$ MIN\_SPANNING\_TREE($ugraph\& G,\ edge\_array(int)\&\ cost$)
  272. \medskip
  273. $list(edge)$ MIN\_SPANNING\_TREE($ugraph\& G,\ edge\_array(real)\&\ cost$)
  274.  
  275. MIN\_SPANNING\_TREE takes as argument an undirected graph $G(V,E)$ and an edge\_array
  276. $cost$ giving for each edge an integer cost. It computes a minimum spanning 
  277. tree $T$ of $G$, i.e., a spanning tree such that the sum of all edge costs
  278. is minimal. MIN\_SPANNING\_TREE returns the list of edges of $T$.
  279.  
  280. Running Time: $O(|E|\log|V|)$
  281.  
  282.  
  283. \vfill\eject
  284.  
  285. \bigskip
  286. \bigskip
  287. {\bf 5.12.3 Algorithms for Planar Graphs}
  288.  
  289. \bigskip
  290. $\bullet$ {\bf Planarity Test}
  291.  
  292. $bool$ PLANAR($graph\& G$)
  293.  
  294. PLANAR takes as input a directed graph $G(V,E)$ and performs a planarity test
  295. for $G$. If $G$ is a planar graph it is transformed into a planar map
  296. (a combinatorial embedding such that the edges in all adjacency lists 
  297. are in clockwise ordering). PLANAR returns true if $G$ is planar and false
  298. otherwise.
  299.  
  300. Running Time: $O(|V|+|E|)$
  301.  
  302. \bigskip
  303. \bigskip
  304. $\bullet$ {\bf Triangulation}
  305.  
  306. $list(edge)$ TRIANGULATE\_PLANAR\_MAP($graph\&\ G$)
  307.  
  308. TRIANGULATE\_PLANAR\_MAP takes a directed graph $G$ representing a planar map.
  309. It triangulates the faces of $G$ by inserting additional edges. The list of
  310. inserted edges is returned.
  311.  
  312. Running Time: $O(|V|+|E|)$
  313.  
  314. \bigskip
  315. \bigskip
  316. $\bullet$ {\bf Straight Line Embedding}
  317.  
  318. \cleartabs
  319. \+$int$ STRAIGHT\_LINE\_EMBEDDING($graph\&\ G$, &$node\_array(int)\&\ xcoord$,\cr
  320. \+                                        &$node\_array(int)\&\ ycoord$)\cr
  321.  
  322. STRAIGHT\_LINE\_EMBEDDING takes as argument a directed graph $G$ representing
  323. a planar map. It computes a straight line embedding of $G$ by assigning 
  324. non-negative integer coordinates ($xcoord$ and $ycoord$) in the range 
  325. $0..2(n-1)$ to the nodes. STRAIGHT\_LINE\_EMBEDDING returns the maximal 
  326. coordinate.
  327.  
  328. Running Time: $O(|V|^2)$
  329.  
  330. \vfill\eject
  331.  
  332.