graph(2)

1. calloc(size_t nelems个数, size_t nbytes所需空间): 分配出nelems*nbytes的内存,这块内存里的所有字节初始化为0

2. DFS

所有vertex最多走一次(O(v)),所有标记了visited vertices的都走过(O(E)),时间复杂度为O(V+E)

3. stack倒序放入,时间复杂度也为O(V+E)

 

DFS也可以检测是否存在cycle,以及component的个数(数一共给出了几组图)

4. BFS(优势是可以找到最短路径),时间复杂度也为O(V+E)

 

5. Hamiltonian Path

在graph G中找到一条path连接vertices v, w,使得每个vertex只经过了一次

 若v=w,则为Hamiltonian circuit

 

6. 在graph G中找到一条路径连接两个vertices v, w,每个边只走一次,但是可以多次来同一个点

若v=w, 则为Euler circuit

定理:A graph has an Euler circuit if and only if it is connected and all vertices have even degree

A graph has a non-circuitous Euler path if and only if it is connected and exactly two vertices have odd degree

猜你喜欢

转载自www.cnblogs.com/eleni/p/11706979.html