update time = Find_min time =
Shortest Path (contd.)
Graph with negative edge costs
- concept of known vertices does not work
- algorithm should be capable of changing its mind about vertices
- enqueue and dequeue vertices, exploring their adjacent edges until
queue is empty
Acyclic graph
- select vertices in topological order
- perform selection and updates as topological sort is performed
- no need for priority queues
Network Flow Problem
- directed graph
- source S
- sink T
- capacity of edge (v,w) = Cv,w
Goal: Find maximum flow from source to sink
Constraint: At intermediate nodes:
in-flow = out-flow
Network Flow: Greedy Approach
Given graph G, create:
- Gf: flow graph
- Gr: residual graph
- 1.
- add positive flow path between source and sink to Gf
- 2.
- subtract corresponding capacity from Gr
- 3.
- stop when sink unreachable from source (no path of positive edges)
May generate suboptimal solutions.
Network Flow: Improvements
- the algorithm should be allowed to change its mind (backtrack)
- for every edge (v,w) with flow fv,w added to Gf, add an
edge (w,v) to Gr with capacity fv,w
- same stopping condition
Leads to optimal solutions
Minimum Spanning Tree
- undirected graph
- connected
- non-negative weights associated with edges
Construction Requirements:
- 1.
- Tree: acyclic subgraph
- 2.
- Spanning: connecting all vertices in the graph
- 3.
- Minimum: minimum sum of edge weights
Number of edges in the tree =
Prim's Algorithm: Minimum Spanning Tree
Two sets of vertices:
-
vertices already in tree
- other vertices
- 1.
- choose non-tree vertex v with minimum weight edge to any tree vertex
- 2.
- add v and corresponding minimum weight edge to tree
- 3.
- continue until all vertices accounted for
:
without heaps
dense graphs
:
heaps
sparse
graphs
Kruskal's Algorithm: Minimum Spanning Tree
- 1.
- start with a forest of
trees
- 2.
- maintain edge weights in a heap
- 3.
- keep adding minimum weight edges that do not form cycle(s)
Time =
=
Tree Search Approaches
Breadth-first search
-
start from root
- search level by level
- appropriate data structure: queue
Depth-first search
-
start from root
- travel to a leaf along a path
- backtrack one level
- travel down another branch
- if all branches of a node explored: backtrack another level
- continue until all subtrees of root explored
- appropriate data structure: stack
Edge Classifications: Tree Traversal
Undirected Graph
- Tree edge: connecting a node to its child
- Back edge: connecting a node to its ancestor
Directed Graph - two additional types
- Forward edge: non-tree edge connecting a node to its descendant
- Cross edge: connecting nodes that are not directly related
Biconnectivity
Biconnected graph: graph with no vertex such that its removal
disconnects the rest of the graph.
Articulation point: vertex whose removal disconnects the graph.
Detection of Articulation Points
- depth first search of vertices while numbering them in ascending order:
Num(v)
- determine lowest-numbered vertex reachable from v: Low(v) is
minimum of:
- 1.
- Num(v)
- 2.
- lowest Num(w) among back edges (v,w)
- 3.
- lowest Low(w) among tree edges (v,w)
- if root has more than one child
root is an
articulation point
- for non-root vertex v and its child w, if
vertex v is an articulation point
Euler Circuits
Goal: to find a path in a graph that visits every edge
exactly once.
Necessary and sufficient conditions:
Euler circuit: connected graph and every vertex should have
an even degree.
Euler tour: exactly two vertices have odd degree. Visits every
edge, but does not return to starting vertex.
Euler circuit construction
- construct a circuit
- repeat:
- if untraversed edges out of a vertex in circuit:
- construct a circuit starting at this vertex
- splice this circuit into previous circuit
- until all edges traversed
Next: About this document ...
Up: CS 3345: Algorithm Analysis
Previous: Chapter 7: Sorting
Ravi Prakash
1999-11-17