ALG 3-1: Graph


Undirected Graphs (无向图)

  • G = (V, E)
  • V = nodes.
  • E = edges between pairs of nodes.
  • Captures pairwise relationship between objects. (捕获对象之间的成对关系)
  • Graph size parameters: n = |V|, m = |E|. (图的大小参数:n = |V|, m = |E|)

Some Graph Applications

Graph Representation: Adjacency Matrix (邻接矩阵)

Adjacency matrix. n-by-n matrix with A_uv= 1 if (u, v) is an edge. (当(u, v)是边时,n×n矩阵A_uv= 1)

  • Two representations of each edge. (每条边有两种表示)
  • Space proportional to n^2. (空间与n^2成比例)
  • Checking if (u, v) is an edge takes Θ(1) time. (检查(u, v)是否为边需要Θ(1)时间)
  • Identifying all edges takes Θ(n^2) time. (识别所有边需要Θ(n^2)时间)

Graph Representation: Adjacency List (邻接表)

Adjacency list. Node indexed array of lists. (链表的节点索引数组)

  • Two representations of each edge. (每条边有两种表示)
  • Space proportional to m + n. (空间与m + n成比例)
  • Checking if (u, v) is an edge takes O(deg(u)) time. (degree = number of neighbors of u)   // 检查(u, v)是否为边需要O(deg(u))时间。(deg = u的邻居数量) 
  • Identifying all edges takes Θ(m + n) time. (识别所有边需要Θ(m + n)时间)

 

Paths and Connectivity

Def. A path in an undirected graph G = (V, E) is a sequence P of nodes v_1, v_2, …, v_k-1, v_k with the property that each consecutive pair v_i, v_i+1 is joined by an edge in E.

(定义:无向图G = (V, E)中的一条路径是节点v_1, v_2,…,v_k-1, v_k的序列P,其性质是每一对连续的v_i, v_i+1在E中由一条边连接)

Def. A path is simple if all nodes are distinct.

(定义:如果所有节点都是独特的,则称路径为 简单的)

Def. An undirected graph is connected if for every pair of nodes u and v, there is a path between u and v.

(定义:如果对于每一对结点u和v,在u和v之间存在一条路径,则无向图是连通的) 

Cycles

Def. A cycle is a path v_1, v_2, …, v_k-1, v_k in which v_1= v_k, k > 2, and the first k-1 nodes are all distinct.

(定义:一个循环是一个路径v_1, v_2,…,v_k-1, v_k,其中v_1= v_k, k > 2,并且第一个k-1节点都是不同的)

 

Trees

Def. An undirected graph is a tree if it is connected and does not contain a cycle.

(定义: 无向图是树,当它是连通的并且不包含循环)

Theorem. Let G be an undirected graph on n nodes. Any two of the following statements imply the third.

(定理: 设G是n个节点上的无向图。则下列任何两个陈述都可推出第三个)

  • G is connected.
  • G does not contain a cycle.
  • G has n-1 edges.

Rooted Trees

Rooted tree. Given a tree T, choose a root node r and orient each edge away from r.

(根树: 给定一个树T,选择一个根节点r,并使每条边远离r)

Importance. Models hierarchical structure.

(重要性: 根树是一种分层次的结构)

原文地址:https://www.cnblogs.com/JasperZhao/p/13975307.html