FIG -6 data structure

Seven, Fig.

1. Basic Concepts

Vertex V, the set of vertices relationship the VR
① vertex: FIG data element is referred vertices (nodes in the tree as the difference between said vertex)

② Relationship between the vertex set the VR
E (set of edges): None of the set of the vertices of graph
A (arc current): set of directed graph of vertices

③ arc (FIG directed edge)
→ W V: V is the starting point / end of the arc, w is the terminal point / head arc (where the arrow)


Of
undirected graph: the number of vertices adjacent to the vertex of the called side

Digraph: an arc into the head of the vertex number of the vertex referred
to is the number of vertices of the tail's called the vertex of


Network: with a right to the edge of the graph is called a weighted graph, also known as network

Directed and undirected complete graph complete graph
with n vertices undirected complete graph has n (n-1) / 2 edges
of n nodes to have complete graph has n (n-1) edges


Path, the loop
path: a contiguous sequence of vertices consisting of the even order
path length: the number of paths upper side
, such as (D, C), (C , B) is a path of length 2

Simple path: the path is not repeated sequence of vertices

Loop: the first path and the last vertex same vertex

Simple loop: the sequence of vertexes figure, except for the first and last vertex same vertex, the other repeat loop vertices do not occur.

FIG communication, strongly connected FIG.

FIG :( any communication ① undirected graph) has a path (communication) between two vertices
(non-connected undirected graph) referred to as maximum communication component connected subgraph

No n vertices have at least n-1 edges connected graph

② FIG :( strongly connected digraph) any two vertices vi, vj. vi to vj, vj vi has a path to the
(non-connected directed graph) referred to as maximum strongly connected subgraphs strongly connected component
has n nodes of the strongly connected graph of arcs at least n


2. Special Graphs

Directed tree

If a directed graph of exactly into a vertex is 0, the remainder of the vertices are 1, it is a directed tree.

Directed acyclic graph (DAG)

Acyclic digraph

It determines whether a ring has ① ② depth-first traversal of the directed graph topological sorting


3. The storage structure of FIG;

3-1 adjacency matrix (sequential storage)

Spatial adjacency matrix occupies only storage node point number in the figures related to, regardless of the number of dense matrices suitable side ⇒

(1) undirected graphs:
A [i] [j] = 1, i of vertices adjacent to the vertex j

A [i] [j] = 0, the vertex of vertices i and j are not adjacent (i = j includes a)

It is a symmetric matrix without the adjacency matrix


(2) directed graph:
A [I] [J] = Wij, if (vi, vj), or <vi, vj> ∈VR

A [i] [j] = ∞, and vice versa (including i = j)


3-2 adjacency list (chain stores)

Storage space adjacent to the table number and the number of figures and number of nodes related edges about sparse matrix suitable ⇒

(1) i for the establishment of a single list for each vertex of a single list for each node, i.e., a single vertex to store the list header (information), information about remaining storage node side.

(2) a single vertex can be appreciated by the vertex list and the table section edge part table, the edge list storage node connected to the adjacent vertex and the current vertex number and a pointer to the next node side

(3) a single list of all nodes header node (vertex nodes) are sequentially stored in an array

(4) ① directed graph adjacency list: single linked list stored for each vertex point of each arc in the head.
② reverse directed graph adjacency list: single linked list stored for each vertex point of the arc to the end of the arc

The adjacent multi-table 3-3: dual side adjacent table

Attached to the same side of all vertices in the list in the same series

Thus each edge node in the two links simultaneously (apex) of the list


4. Loop



Depth-first search traversal (pseudocode)

Preorder similar tree traversal

Thought:
first visit starting point V, which is marked as accessible;
select arbitrary V adjacent unvisited vertex w, and access it;
any w and select the adjacent unvisited vertex and visit a repeated get on.
When all adjacent vertices a vertex have been visited outdated, then turn back to the apex recently visited

Application / test center

1. recursive stack staging means ⇒ node

2. a depth-first (DFS) searches can traverse a communication branch.
To access all the nodes, you must call (K) times the depth-first traversal algorithm
times the depth of the k connected components FIG shall call (k) first traversal algorithm

Never depart to any one of vertices of a graph, once DFS to access all the nodes, the communication must FIG view (only one connected component)

169 textbooks


3. Analyzing can without / with whether a loop / loop the figure
(1) undirected graph: dfs encountered back side (side of vertex has been visited) ⇒ there must be a ring

(2) directed graph: j is the known spanning tree vertex descendants of vertex v (v → j)
appears one side (→ v j) from the vertex to vertex v j ⇒ FIG before when DFS (v) End v and j there must be a ring comprising

(Tianqin 216-16)

4. There may be a topological sort of a directed acyclic graph, a depth-first traversal methods.
Print corresponding vertex, the vertex sequence output from the inverse topology return stack is pushed

183 textbooks



BFS traversal (pseudo-code)

Similar levels of traversing the tree (the need to use the same queue)

Thought: first visit starting vertex v,
and then select all of the adjacent vertices v W1 ... wn access,
in turn accesses W1 ... wn of all adjacent vertices (except already visited), and so on.


Algorithm execution: ① in FIG either take a vertex access enqueuing, and vertex marked as visited

② When the queue is not empty when the loop is executed: dequeued, checking all dequeued vertex adjacent vertices, access has not been visited adjacent vertices and enqueue

③ team out of the loop is empty

application

1. When each side of the same weight (equivalent to FIG no right), breadth-first search traversal may be used to resolve the single-source shortest path problem
⇒ from the source to the remaining vertex of the shortest path is always

For an equal / not entitled to the right in FIG. FIG, BFS source always according to the distance (0-degree) to traverse from near to far
distance refers to the number of vertices of the current vertex points on the source path (as will be appreciated spanning tree the number of layers)

(Tianqin 216-17)

2. queue means for temporarily storing node


time complexity

FIG traverse substantially adjacent to each vertex point of the process to find its
lookup to find adjacent edge vertices + ⇒ neighbor
is obviously the depth / breadth traversal same time complexity (depending on the memory structure), but different vertices access order


(1) the adjacency matrix : time complexity is 0 (n²);
adjacency matrix storage, regardless <Vi, Vj> whether there is a path, each side will be traversed.
Matrix size n * n, i.e., time complexity of O (n²)

(2) adjacent to the table, the time complexity of 0 (n + e)
If the use of the adjacent table storing, for each node access time, each path has a side access, the time complexity is O (n + e)



Test sites:

No unrelated to its vertex traversal order of the storage structure of FIG.


The spanning tree (with / undirected)

FIG no non-spanning tree communication

Depth / Breadth First Search (generation) Tree: FIG depth / breadth-first search traversal experienced during the retention side, the remaining sides deleted, trees formed

Minimum spanning tree (for undirected graphs)

Communication weighted minimum spanning tree (undirected) graph with n vertices: weight of the side and the minimum sum of n communication subgraph of vertices

N vertices spanning tree, and only the n-1 sides;


(1) Prim neighbor algorithm (pseudo)

Each time the select smallest side (connected to the selected edge) of the adjacent side, (with selected side) circuit configured to discard selected times small lip

Time complexity is 0 (n²), with vertices in the graph relating only (independent of the number of edges) ⇒ FIG suitable dense

Each point adjacency matrix adjacency find minimum weight required edge 0 (n) time

Comprehensive title (painting Table): 2007 sixth title overall title / title in 13 years overall seventh title


(2) the Kruskal (dummy)

Selecting a smallest side of each of the sides is not selected, and (selected edge) give up circuit configured to select the second smallest side

Time complexity (elog₂e), the number of edges e of the graph (regardless of the number of vertices) applied to a sparse FIG ⇒

E sides in the minimum weight to find a trip heapsort ⇒ 0 (log₂e)
is selected from th e ⇒0 (elog₂e)


Test sites

1: The only cost of the minimum spanning tree

2: minimum weight edge will not necessarily appear in all of the minimum spanning tree

3: a graph (or even communication) spanning tree (morphology) is not necessarily the only

4: Morphology prim and minimum spanning tree algorithm is not always krustal different


6. The shortest path (directed graph)

Dijkstra

A shortest path to the remaining vertices each vertex of
the directed graph {V, E}, as a set of points V

Thought: vo∈ initial set S (S VO shortest path to the vertex has been determined)
every time a set of arcs from S to each vertex set VS selected shortest
vertex w which is connected into S, and then to an intermediate point w , vo ~ w
update set S to each vertex set VS weighted length


1. Code title
P [v]: vo to the node on the shortest path remaining vertex v
P [v] [w] = true: the w nodes on the shortest path to v v0

D [v]: vo to v weighted shortest path length
Final [v] = true: the shortest path has been obtained vo v (in the set S)

Weighted adjacency matrix: <i, i> = ∞

Code: (1) for all vertices v (0 ~ vexnum-1)
initialized Final [V], D [V], P [V] [W]
(2) initialization, vo belonging to the S set
(3) to find the shortest arc vw the set S into w
(4) and updates the shortest path length

2. Paint (worksheet) of the title
has been incorporated into the vertex (S), which does not incorporate the apex (VS),
dist [] i.e., D [], the shortest path length weighted
path [w]: v0-w of the shortest path sequence w a node

15 years of comprehensive title seventh title



Floyd (shortest path between each pair of vertices)

The time complexity of 0 (n³)



7. topology (directed acyclic graph)

AOV

Of the directed acyclic graph G (only one side edge of the arrow) topological sort, not necessarily the only sequence topology
of G all vertices arranged in a linear sequence, such that any pair of vertices FIG u and v, if present, from the u to v path, then the topological sorting sequence must appear in front of v u

Test sites / applications

1: directed graph adjacency matrix storage, matrix elements below the main diagonal are all zero topological ⇒ sequence may not be unique, but the FIG.

2. The number of vertices strong graph must be greater than one ring

3: a topological sort algorithm based on topological sort adjacency table stored in a AOV network, the topology of an ordered sequence obtained is not necessarily unique

4: Topological ordering may be determined whether the circuit in the FIG
Topological Sort FIG If a completed, this circuit does not exist in FIG.



Critical path, AOE (Activity on the side)

1. The concept of
critical path: from the source point (0-degree) to sink all paths (a 0 degree), the path having a maximum path length

Representative longest path ② ① FIG completion minimum time period

Critical Path is not unique

(1) extension of the completion of key activities will affect the completion time of the entire project
(2) One of the key activities completed ahead of schedule, the entire project may not be completed ahead of time

when a number of critical path exists, the time in which the activity on a critical path shortened only This section will lead to critical path becomes non-critical path, but can not shorten the construction period

2. critical path
earliest events provided VE (k) is the vertex k represents the time, i.e., the path from the source point to the vertex in the k longest: occur earliest time. Maximum: to ensure that activities can be completed in front

Time without postpone the completion of the whole project, the latest event occurred: the latest time occurred

Seeking critical path
(1) Find the earliest time event ve (i) occurs
① of FIG have to be topologically sorted, topological sorting sequence obtained vertices
② the event source set 0 VE (0) = 0
③ sequentially obtains each vertex representing events earliest time, taking the longest side

(2) time required event vl (i) occurs at the latest:
① disposed n the event sink disposed VL (n) = VE (n)
② in turn provided with a sink connection event (point) vl
event k, vl (k) is the vl (j) - after (<k, j> weight) Min

Minimum: All two successor nodes, to ensure that both sides have to be able to complete
the event successor node k has m, n,
then vl (k) = min {vl (m) - <k, m>, vl (n) - <K, n->}


(. 3) find the earliest events / latest occurrence time
① earliest time event e (ak) = event occurs the event occurrence time of the maximum
② activity latest time l (ak) = end point of time activity the latest occurrence time - activity duration

Test sites

1. Some key activities completed ahead of schedule, not necessarily the whole project completed ahead of schedule
(there may be multiple critical paths, critical path may not include other key activities completed in advance)

2.13 Comprehensive questions Q7 / 2007 fourth title overall title

Published 46 original articles · won praise 15 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_41850194/article/details/102742252