Graph theory Knowledge Finishing (2) topological sequencing, shortest path, minimum spanning tree

Source: Internet
Author: User
Tags sorts

=====================================

found that the previous picture of the study is very bad, nothing, now began to organize the graph theory of knowledge

The author is a Konjac konjac, Orz, you gods.

=====================================

Definition: The topological ordering of a directed acyclic graph (Directed acyclic graph, or DAG), in which all vertices in the graph are arranged in a linear sequence, so that any pair of vertices in the graph are U and V, if <u,v>∈e (G), then u appears before v in a linear sequence.

It seems to make sense, but I don't understand what it is talking about.

For example, now there is a job, the job has 5 parts, respectively, V1,V2,V3,V4,V5

Well, then to do v2 first have to do V1, V3; To do v1 first have to do V4, v5

Then a sequence of topological sorts is V4, V5, V1, v3, v2

In fact, it means the relationship between restriction and restriction (I don't know the clarity of the description)

There is no ENG to the existence loop of the graph to make topological sort.

Topology Sorting algorithm:

A vertex output of 0 is selected each time (regardless of the order, so the answer is not unique).

If you finally find that the number of vertices in the output is less than n (or written | v|), the presence of a circuit is indicated.

Initialize: top=0 (stack top pointer);

The initial state of all the vertices in the degree of 0 is stacked;

I=0 (counter);

While top>0 (stack non-empty) do

Vertex v (stack top element) is out of stack and output;

Counter I increased by 1;

The for-v adjacency vertex u do//with adjacency table, each edge is accessed 1 times, so the total complexity is O (| e|); With the adjacency matrix, the complexity of O (n) is required each time;

Dec (Indgr[u]);

If indgr[u]=0 then vertex u into the stack;

If i<| v| Then exit (with loop information).

Shortest circuit problem:

In the weighted graph G = (v,e), if the vertex vi,vj is the two vertices of figure g, the path length from vertex Vi to VJ is defined as the sum of the weights of each edge of the path. There may be multiple paths from Vertex VI to VJ, where a path with the smallest path length is called the shortest path of Vertex VI to VJ. For non-weighted graphs, as long as the weighted value of each edge is 1, it can be treated as a weighted graph.

Single Source Shortest path SSSP (Single-source shortest path) from a vertex (source point) to the shortest path of another vertex (end point)

Common algorithms:

Dijkstra

Bellman-ford (upgrade to SPFA)

Multi-source Shortest path APSP (all Pairs shortest Paths) The shortest path between each pair of vertices in the graph.

Common algorithms:

Floyd

1. SPFA

Each time the team first node is removed u, and the current shortest path estimate of U point (u,v) is relaxed, if the shortest path estimate of the V point is adjusted and the V point is not in the current queue, the V point is added to the queue. This keeps the nodes out of the queue for relaxation operations until the queue is empty.

Determine if there is a negative ring: If a point enters the queue more than N/2 times, there is a negative ring. On average O (KE), K is the smaller constant.

However, it is possible to get the grid graph and the negative weight ring card to O (VE)

--wyh Poly

2. Dijkstra

Initialize: Dis[v]=w[s,v];

Wherein, w[s,v]=maxint means s to v without direct edge

dis[s]=0; S={s}; s represents a set of points that have been expanded

For I:=1 to N-1 does take a vertex u out of the v-s to expand,

Requirements: Dis[u]=min{dis[v]|v∈v-s}//Here is also the key to the algorithm, S to u shortest path d[u] is no longer small. You can use heap optimization here.

S=s+{u}

Each side of the for U connection <u,v> do

Relax (U,V)

No heap optimization O (v^2) recommended dense graph use

Heap optimization O (eloge) Recommended sparse graph use

3. Floyd: This is simply too simple to say, using the idea of dynamic planning, Complexity O (v^3), but you can find the shortest path between all pairs of points.

But generally there is no need to beg for that much.

Required, a type of Floyd,o (v^3), a SPFA or Dijkstra, multiply V,SPFA o (kve) Dijkstra O (v^3), heap optimization O (veloge)

(= =) It seems too much to say.

Minimum spanning tree

The spanning tree of a connected graph is a very small connected sub-graph, which contains all the vertices in the graph, but only enough to form the n-1 edge of a tree. For the connected weighted graph G, the spanning tree is also weighted. The sum of the weights of each edge on the spanning tree, called the tree's right. The least-weighted spanning tree, called the minimum spanning Tree of g (mst,minimum Spanning trees). There are generally two algorithms prim and Kruskal to solve the problem of minimum spanning tree.

1. PRIM

The prim algorithm is based on a greedy strategy: each time you select a point nearest to the current point set, add MST. More for dense graphs. Initially, the MST is a collection of only one point, and since each point is ultimately contained within the MST, the prim algorithm can start at any point in the diagram. With DJI

---restore content ends---

=====================================

found that the previous picture of the study is very bad, nothing, now began to organize the graph theory of knowledge

The author is a Konjac konjac, Orz, you gods.

=====================================

Definition: The topological ordering of a directed acyclic graph (Directed acyclic graph, or DAG), in which all vertices in the graph are arranged in a linear sequence, so that any pair of vertices in the graph are U and V, if <u,v>∈e (G), then u appears before v in a linear sequence.

It seems to make sense, but I don't understand what it is talking about.

For example, now there is a job, the job has 5 parts, respectively, V1,V2,V3,V4,V5

Well, then to do v2 first have to do V1, V3; To do v1 first have to do V4, v5

Then a sequence of topological sorts is V4, V5, V1, v3, v2

In fact, it means the relationship between restriction and restriction (I don't know the clarity of the description)

There is no ENG to the existence loop of the graph to make topological sort.

Topology Sorting algorithm:

A vertex output of 0 is selected each time (regardless of the order, so the answer is not unique).

If you finally find that the number of vertices in the output is less than n (or written | v|), the presence of a circuit is indicated.

Initialize: top=0 (stack top pointer);

The initial state of all the vertices in the degree of 0 is stacked;

I=0 (counter);

While top>0 (stack non-empty) do

Vertex v (stack top element) is out of stack and output;

Counter I increased by 1;

The for-v adjacency vertex u do//with adjacency table, each edge is accessed 1 times, so the total complexity is O (| e|); With the adjacency matrix, the complexity of O (n) is required each time;

Dec (Indgr[u]);

If indgr[u]=0 then vertex u into the stack;

If i<| v| Then exit (with loop information).

Shortest circuit problem:

In the weighted graph G = (v,e), if the vertex vi,vj is the two vertices of figure g, the path length from vertex Vi to VJ is defined as the sum of the weights of each edge of the path. There may be multiple paths from Vertex VI to VJ, where a path with the smallest path length is called the shortest path of Vertex VI to VJ. For non-weighted graphs, as long as the weighted value of each edge is 1, it can be treated as a weighted graph.

Single Source Shortest path SSSP (Single-source shortest path) from a vertex (source point) to the shortest path of another vertex (end point)

Common algorithms:

Dijkstra

Bellman-ford (upgrade to SPFA)

Multi-source Shortest path APSP (all Pairs shortest Paths) The shortest path between each pair of vertices in the graph.

Common algorithms:

Floyd

1. SPFA

Each time the team first node is removed u, and the current shortest path estimate of U point (u,v) is relaxed, if the shortest path estimate of the V point is adjusted and the V point is not in the current queue, the V point is added to the queue. This keeps the nodes out of the queue for relaxation operations until the queue is empty.

Determine if there is a negative ring: If a point enters the queue more than N/2 times, there is a negative ring. On average O (KE), K is the smaller constant.

However, it is possible to get the grid graph and the negative weight ring card to O (VE)

--wyh Poly

2. Dijkstra

Initialize: Dis[v]=w[s,v];

Wherein, w[s,v]=maxint means s to v without direct edge

dis[s]=0; S={s}; s represents a set of points that have been expanded

For I:=1 to N-1 does take a vertex u out of the v-s to expand,

Requirements: Dis[u]=min{dis[v]|v∈v-s}//Here is also the key to the algorithm, S to u shortest path d[u] is no longer small. You can use heap optimization here.

S=s+{u}

Each side of the for U connection <u,v> do

Relax (U,V)

No heap optimization O (v^2) recommended dense graph use

Heap optimization O (eloge) Recommended sparse graph use

3. Floyd: This is simply too simple to say, using the idea of dynamic planning, Complexity O (v^3), but you can find the shortest path between all pairs of points.

But generally there is no need to beg for that much.

Required, a type of Floyd,o (v^3), a SPFA or Dijkstra, multiply V,SPFA o (kve) Dijkstra O (v^3), heap optimization O (veloge)

(= =) It seems too much to say.

Minimum spanning tree

The spanning tree of a connected graph is a very small connected sub-graph, which contains all the vertices in the graph, but only enough to form the n-1 edge of a tree. For the connected weighted graph G, the spanning tree is also weighted. The sum of the weights of each edge on the spanning tree, called the tree's right. The least-weighted spanning tree, called the minimum spanning Tree of g (mst,minimum Spanning trees). There are generally two algorithms prim and Kruskal to solve the problem of minimum spanning tree.

1. PRIM

The prim algorithm is based on a greedy strategy: each time you select a point nearest to the current point set, add MST. More for dense graphs. Initially, the MST is a collection of only one point, and since each point is ultimately contained within the MST, the prim algorithm can start at any point in the diagram. Similar to Djikstra, the details are updated later.

2. Kruskal

Also, in a future article will be described in detail, please look forward to.

Graph theory Knowledge Finishing (2) topological sequencing, shortest path, minimum spanning tree

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.