Undirected Graphs -- Data structure

  1. Undirected Graphs

average degree:


Undirected Graphs -- Data structure_第1张图片
Paste_Image.png
  1. DFS, depth first search

example trace:


Undirected Graphs -- Data structure_第2张图片
Paste_Image.png

The output is 0-2-1-3-5-4.

DFS implementation:

Undirected Graphs -- Data structure_第3张图片
Paste_Image.png

Proposition A. DFS marks all the vertices connected to a given source in time proportional to the sum of their degrees.

Undirected Graphs -- Data structure_第4张图片
Paste_Image.png

Why the preprocessing time is E + V?
For example:

Undirected Graphs -- Data structure_第5张图片
Paste_Image.png

The source is s. s has adjacent vertices A, C, D.
The trace will be:
Stack: s a b c d
output: s a b c d e v

  1. BFS, breadth-first search:
    Depth-first search. Put unvisited vertices on a stack.
    Breadth-first search. Put unvisited vertices on a queue.
    Shortest path. Find path from s to t that uses fewest number of edges.
Undirected Graphs -- Data structure_第6张图片
Paste_Image.png

你可能感兴趣的:(Undirected Graphs -- Data structure)