Basic algorithm (vi)--figure

Source: Internet
Author: User

First, the concept of the graph

The graph is one of the four basic logical structure sets, the linear structure, the tree structure and the graph structure, namely the graph structure, and the graph structure is the most complicated structure. In the structure of a graph, any two nodes can be correlated, that is, the adjacency between nodes is arbitrary. In a tree structure, nodes have hierarchical relationships, and each layer node can only be associated with at most one node in the previous layer, but may be related to multiple nodes in the next layer. The structure of graphs can describe a variety of complex data objects, which is widely used.

Ii. various Terms

• Forward graph, no-map: Figure G consists of two sets of V and E, recorded as g= (V,e), wherein V is a vertex of a poor non-empty set; E is the set of edges, and the edge is a pair of vertices in V. If the pairs of vertices are ordered, the graph is called a forward graph, and ordered pairs are surrounded by angle brackets <>; Conversely, if the vertex pairs are unordered, the graph is called an no-map, and the unordered pairs are enclosed in parentheses ().

• Right, weighted graph: The side of the graph is accompanied by a value, this value is called right. A graph with weights on each edge is called a weighted graph.

• Degrees, degrees, and degrees of vertex: the degree of vertex v in the non-graph is the number of edges associated with that vertex. If the graph is a forward graph, then the number of arcs with the vertex v as the end point is called the degree of V, and the number of arcs with vertex V as the origin is called the Out degree of the V, and the degree of penetration + the degree of the direction graph.

• Sub-graph: Set g= (V,e) is a graph, if E ' is a subset of E, V ' is a subset of V, and the edge of E ' is only associated with the vertex in V ', then the figure g ' = (V ', E ') is called a sub-graph of Figure G.

• Path, path long distance: The path of the graph is the edge of one vertex to another, the number of edges passed is called the path length; the path to the graph is the arc of one vertex to another, and the path length is the number of arcs above the path.

• Together, connected graphs, connected components: in undirected graphs, V and V ' are connected if there is a path from vertex v to Vertex v '. If any two vertices VI and VJ in the figure are connected, the graph is called a connected graph.

Changliantong, strongly connected graphs, strongly connected components: for undirected graphs, if any pair of vertices VI and VJ (I!=J) have vertex VI to VJ Path also has VJ to V path, that is, two vertices bidirectional connectivity, then called the graph is a strong connected graph. The strongly connected sub-graph of a forward graph is called a strong connected component.

• Spanning tree, generating forest: a spanning tree of connected graphs, which is a minimal connected sub-graph containing all the vertices of the connected graph. If the number of vertices of the connected graph G is n, then the number of sides of the spanning tree of G is n-1. If the number of sides of a sub-graph G ' of G is greater than n-1, there must be a ring in G '. Conversely, if the number of sides of G ' is less than n-1, then G ' must not be connected. In a non-connected graph, a very small connected sub-graph is obtained from each connected component, that is, a spanning tree, which makes up a non-connected graph spanning forest.

These concepts are necessary to solve the problem of some of the reserves needed to focus on memory and understanding.

Third, the storage of graphs

1. Adjacency Matrix: the adjacency matrix of the graph (adjacency matrix) represents the way in which a two-dimensional array is used. With the adjacency matrix, you can see immediately whether there is an edge between the two vertices, just check whether the adjacency matrix re-i and column J are non-0 values. For a graph with no direction, the adjacency matrix is symmetric.

Note: The adjacency matrix of a graph is unique, but its adjacency table representation is not unique. This is because in the adjacency table representation, the link order of each side junction igniter depends on the algorithm that establishes the adjacency table and the input order of the edges. In other words, the order of the nodes is arbitrary in each linear list of adjacency tables.

2. adjacency table

Exercises:

1. In one diagram, the sum of the degrees of all vertices equals the times of       the number of all sides.

A. B. 1 c. 2 D. 4

2. In a given graph, the sum of the degrees of all vertices is equal to the out of all vertices and       times.

A. B. 1 c. 2 D. 4

3. A non-graph with n vertices has       a maximum of one edge.

A. N B. N (n-1) C. N (n-1)/2 D. 2n

4. There is an       edge in the non-direction full graph with 4 vertices.

A. 6 B. C. D. 20

5. An undirected graph with 6 vertices should       have at least one edge to ensure that it is a connected graph.

A. 5 B. 6 c. 7 D. 8

6. In an undirected graph with n vertices, at least one edge is required       to connect all vertices.

A. N B. n+1 c. n-1 D. n/2

7. For a graph with n vertices, if the adjacency matrix is used, the size of the matrix is       .

A. N B. (n-1) 2 c. n-1 D. n2

8. For a graph with n vertices and e edges, if the adjacency matrix is used, the size of the table head vector is     1 ; The total number of nodes in all adjacency matrices is 2 .

1 A. N B. n+1 c. n-1 D. n+e

2 A. E/2 B. e C. 2e D. N+e

9. A graph is known, if the depth search from vertex A to traverse, you can get a vertex sequence of     1  , by the width of the search method to traverse, you can get     the vertex sequence is 2    .

1 A. abecdf B. acfebd c. aebcfd D. AEDFCB

2 A. Abcedf b. abcefd c. aebcfd D. acfdeb

9th picture

10. The adjacency table storage structure of a given graph is known

(1) According to the depth-first traversal algorithm of the graph, the vertex sequence obtained from the V1 vertex is    1  .

(2) According to the width-first traversal algorithm of the graph, the vertex sequence obtained from the V1 vertex is    2  .

1 A. v1,v2,v3,v5,v4 B. v1,v2,v3,v4,v5

C. v1,v3,v4,v5,v2 D. v1,v4,v3,v5,v2

2 A. v1,v2,v3,v4,v5 B. v1,v3,v2,v4,v5

C. v1,v2,v3,v5,v4 D. v1,v4,v3,v5,v2

10th picture

11. The depth-first traversal algorithm for graphs stored with adjacency tables is similar to binary trees         .

A. Sequential Traversal B. Middle sequence traversal c. post-order traversal D. Traverse by layer

12. The width-first traversal algorithm for graphs stored with adjacency tables is similar to binary trees         .

A. Sequential Traversal B. Middle sequence traversal c. post-order traversal D. Traverse by layer

13. Determine if a graph exists loop in addition to the use of topological sorting methods, can also be       exploited.

A. Finding the critical path method B. Dijkstra method for finding the shortest path

C. Width-first traversal algorithm D. Depth-First traversal algorithm

Blank questions

At least       one edge of a connected graph of 1.n vertices.

2. In the adjacency matrix of the No-right graph G, if (vi, VJ) or <vi, vj> belongs to the edge set of Figure G, then      the corresponding element      a[i][j] equals, otherwise equals.

3. In the adjacency matrix of the No-power graph G, if a[i][j] equals 1, then equals     a[j][i] =.

4. The adjacency table of Figure G is known, and its depth-first search sequence          starting from the V1 vertex is the width-first search sequence from the          v1 vertex.

 

4th picture

5. It is known that the adjacency matrix of a graph indicates that the method of calculating the degree of the first node is.

6. The adjacency matrix of a graph is known to indicate that the method of deleting all edges from the I node is .

Basic Algorithm (vi)--figure

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.