date: 2024-04-07
title: Graph-algorithm
status: UNFINISHED
author:
- AllenYGY
tags:
- Graph
- Algorithm
- NOTE
created: 2024-04-07T22:33
updated: 2024-04-15T13:24
publish: TrueGraph-algorithm
A graph is a pair of
V is the collection of vertices
E is the collection of edges
(u, v) and (v, u) are distinct for some edges (u, v)
(u, v) and (v, u) are identical for all edges (u, v)
Adjacency list Representation
Adjacency matrix Representation
Four array s are used to keep information gathered during traversal.
Algorithm DFS(G)
Input: Graph G
Output: Vertex traversal of graph G
for all vertex u∈V(G) do
color[u]←white//Initialize
pred[u]←NULL
end for
time←0
for all vertex u∈V(G) do//Start a new tree
if color[u]==white then
DFSVisit(u)
end if
end for
Algorithm DFSVisit
color[u]←gray//u is discovered
d[u]←++time//u's discovery time
for all v∈adj[u] do//Visit undiscovered vertex
if color[v]==white then
pred[v]←u
DFSVisit(v)
end if
end for
color[u]←black//u has finished
f[u]←++time//u finish time
Use
It is a graph with no cycles, and a collection of trees.
If G=(V, E) is an undirected graph

The idea is to consider every case.
Assume
An edge in an undirected graph is either a tree edge or a back edge.
Assume
Hence v is in the DFS subtree rooted at u.
Let G=(V, E) be a connected undirected graph.
An articulation point (cut vertex) of G is a vertex whose removal disconnects G

The running time is O (n ∗(n + e)) .
Using the discovery time in the DFS tree to define low and high.
If there is a subtree rooted at a children of v which does not have a back edge connecting to a vertex with discovery time smaller than d[v] , then v is an articulation point.