DSAA之图论基础定义部分(一)

前言

  终于开始学习图论啦

1. Definitions

  • A graph G = ( V , E ) consists of a set of vertices, V , and a set of edges, E . Each edge is a pair ( v , w ) , where v , w V .
  • If the pair is ordered, then the graph is directed. Directed graphs are sometimes referred to as digraphs.
  • Vertex w is adjacent to v if and only if ( v , w ) E .
    • In an undirected graph with edge ( v , w ) , and hence ( w , v ) , w is adjacent to v and v is adjacent to w .
  • Sometimes an edge has a third component, known as either a weight or a cost.

  和别的书不同的是,DSAA使用数学的方式描述图的性质,特别强调第3点: ( v , w ) E 时,在有向图中只能说 w v 的相邻(单向性);在无向图中,可以说 w v 的相邻或者 v w 相邻。路径的定义:

  • A path in a graph is a sequence of verices w 1 , w 2 , w 3 , . . . , w n such that ( w i , w i + 1 ) E for 1 i < n . The length of such a path is the number of edges on the path, which is equal to n 1 .
    • We allow a path from a vertex to itself;
  • if this path contains no edges, then the path lenght is 0. This is a convenient way to define an otherwise special case. If the graph contains an edge ( v , v ) from a vertex to itself, then the path v , v is sometimes referred to as a loop.
  • The graphs we will consider will generally be loopless. A simple path is a path such that all vertices are distinct, except that the first and last could be the same.

  强调第2点:loop区分于cycleloop是特殊情况下的cycle。DSAA图论部分不考虑loop。接下来是cycle的定义:

  • A cycle in a directed graph is a path of length at least 1 such that w 1 = w n ; this cycle is simple if the path is simple.
  • For undirected graphs, we require that the edges be distinct. The logic of these requirements is that the path u , v , u in an undirected graph should not be considered a cycle, because ( u , v ) and ( v , u ) are the same edge. In a directed graph, these are different edges, so it makes sense to call this a cycle. A directed graph is acyclic if it has no cycles. A directed acyclic graph is sometimes referred to by its abbreviation, DAG.

  第一点是圆的定义(无论是有向还是无向),因为长度至少为1,且不考虑loop,所以可以认为一个圆最少应该含有三个点,两条边。第二点提出在无向图中,应保证所有边都是互异的(其实对于有向图也适用),所以 u , v , u 在无向图中并不是有效路径。之后,连通性的定义:

  • An undirected graph is connected if there is a path from every vertex to every other vertex. A directed graph with this property is called strongly connected.
  • If a directed graph is not strongly connected, but the underlying graph (without direction to the arcs) is connected, then the graph is said to be weakly connected. A complete graph is a graph in which there is an edge between every pair of vertices.

  无向图中,任意两个顶点都具有路径,则该图为连通图,数学形式为: 如果 v , w V ,则 ( v , w ) E 。在有向图中,如果不满足上面的定义,但去掉方向之后的无向图满足上式定义,则该图为弱连通。(如果满足,当然也是强连通)

2. 实际例子

  • Each airport is a vertex, and two vertices are connected by an edge if there is a nonstop flight from the airports that are represented by the vertices.
  • The edge could have a weight, representing the time, distance, or cost of the flight. It is reasonable to assume that such a graph is directed, since it might take longer or cost more (depending on local taxes, for example) to fly in different directions.
  • We would probably like to make sure that the airport system is strongly connected, so that it is always possible to fly from any airport to any other airport. We might also like to quickly determine the best flight between any two airports. “Best” could mean the path with the fewest number of edges or could be taken with respect to one, or all, of the weight measures.

  这里写图片描述
  图片侵权自删,每个顶点代表一个机场,任意两个机场都是相邻的(该图为有向图)。每个边具有权重,权重为距离或者花费。第三点提到了最佳路径问题,这个最佳定义的方式有多种,具体问题具体分析。

3. 总结

  图由边和点构成,如果边有方向,则该图为有向图。两点的相邻性,在有向和无向图中稍有区别。路径中的边要满足互异性,cycle为出发点和终止点相同的情况,loop为特殊的cycle,边可能具有权重。如果在图中任意两点都是相邻的(或者存在一条路径),则该图为连通的。特别的,在有向图中如果不满足上面的定义,但是其去方向之后的无向图是连通的,那么该图称为弱连通。
  最后针对实际问题转化的图可能是无向,也可能是有向的。根据具体问题,决定最佳路径,就是图论的一个实际应用场合。

猜你喜欢

转载自blog.csdn.net/lovestackover/article/details/80526776