# آموزش ساختمان داده ها - بخش هفتم

• View
18

2

Embed Size (px)

### Text of آموزش ساختمان داده ها - بخش هفتم

1. 1. faradars.org/fvds9402 : ( : ( ): ) 1 FaraDars.org
2. 2. faradars.org/fvds9402 2 G = (V,E)VE. V:E:() 1-: 2-: . FaraDars.org
4. 4. faradars.org/fvds9402 4 a b cd deg-(a) = 1 deg+(a) = 2 deg-(d) = 2 deg+(d) = 1 deg-(c) = 0 deg+(c) = 2 deg-(b) = 4 deg+(b) = 2 FaraDars.org
5. 5. faradars.org/fvds9402 (Multi Edge). 5 FaraDars.org
6. 6. faradars.org/fvds9402 . :n-1: 6 2 )1( nn FaraDars.org
7. 7. faradars.org/fvds9402 . : :v,uuv vu. 7 FaraDars.org
8. 8. faradars.org/fvds9402 (Bipartite) UV. UV.G=(V,U,E). 8 v5 v1 v2 v3 v4 v6 v1 v6 v2v5 v3 v4 FaraDars.org
11. 11. faradars.org/fvds9402 (subgraph) G=(V,E)H=(W,F): WV and FE 11 FaraDars.org
15. 15. faradars.org/fvds9402 () ij ij1. 15 a b c d 1 2 4 5 3 6 001110 111000 000101 010011 654321 M VE FaraDars.org
16. 16. faradars.org/fvds9402 Connectivity 16 a b c d a b c d Weakly connected no path from b to d. Strongly connected FaraDars.org
17. 17. faradars.org/fvds9402 1-()(DFS : Depth First Search) 2-(-)(BFS : Breadth First Search) DFSBFS. 17 FaraDars.org
18. 18. faradars.org/fvds9402 (BFS) ( ). . . . 18 FaraDars.org
20. 20. faradars.org/fvds9402 BFS. A B C D E F G H 20 FaraDars.org
22. 22. faradars.org/fvds9402 BFS2. 2 , 6 , 1 , 3 , 7 , 5 , 4 , 8 22 2 16 731 573 457 845 84 8 FaraDars.org
23. 23. faradars.org/fvds9402 r s t u v w x y FaraDars.org
24. 24. faradars.org/fvds9402 r s t u v w x y sQ: FaraDars.org
25. 25. faradars.org/fvds9402 r s t u v w x y wQ: r FaraDars.org
26. 26. faradars.org/fvds9402 r s t u v w x y rQ: t x FaraDars.org
27. 27. faradars.org/fvds9402 r s t u v w x y Q: t x v FaraDars.org
28. 28. faradars.org/fvds9402 r s t u v w x y Q: x v u FaraDars.org
29. 29. faradars.org/fvds9402 r s t u v w x y Q: v u y FaraDars.org
30. 30. faradars.org/fvds9402 r s t u v w x y Q: u y FaraDars.org
31. 31. faradars.org/fvds9402 r s t u v w x y Q: y FaraDars.org
32. 32. faradars.org/fvds9402 1 r s t u v w x y Q: FaraDars.org
33. 33. faradars.org/fvds9402 BFS. A B C D E F A D B C E F A D B C F E 33 FaraDars.org
34. 34. faradars.org/fvds9402 bfs(v){ front = rear = NULL; cout link ) if ( !visited[w -> vertex] ) { cout vertex; addq ( &front , &rear , w -> vertex ); visited[ w -> vertex ]=TRUE; }}} 34 FaraDars.org
35. 35. faradars.org/fvds9402 (DFS) . . . 35 FaraDars.org
36. 36. faradars.org/fvds9402 Depth-First Search (DFS) FaraDars.org
37. 37. faradars.org/fvds9402 DFS. A B D F E C G 37 FaraDars.org
38. 38. faradars.org/fvds9402 DFS. a b c g d e f i h 38 FaraDars.org
39. 39. faradars.org/fvds9402 DFS. 1 , 4 , 7 , 8 , 9 , 6 , 5 , 2 , 3 1 , 2 , 3 , 6 , 9 , 8 , 7 , 4 , 5 1 , 2 , 3 , 6 , 5 , 4 , 7 , 8 , 9 39 FaraDars.org
40. 40. faradars.org/fvds9402 DFS. A B E D F C A B D F E C A D E F B C 40 FaraDars.org
41. 41. faradars.org/fvds9402 DFS. A B F I H G C D E 41 FaraDars.org
43. 43. faradars.org/fvds9402 dfs (v) { visited[v] = TRUE; cout link ) if ( ! Visited [w -> vertex] ) dfs ( w -> vertex ); } 43 FaraDars.org
44. 44. faradars.org/fvds9402 (DFS)4. 1-(tree edge):DFS. 2-(forward edge):(a,b)DFSba. 3-(back edge):(a,b)DFSab. 4-(cross edge):3. :. 44 FaraDars.org
47. 47. faradars.org/fvds9402 tree edge : (s,z) , (z,y) , (y,x) , (z,w) , (t,v) , (t,u) forward edge : (s,w) back edge : (x,z) , (u,t) cross edge : (w,x) , (v,w) , (v,s) , (u,v) 47 FaraDars.org
49. 49. faradars.org/fvds9402 d[u] : when u is discovered f[u] : when searching adj of u is finished u v w FaraDars.org
50. 50. faradars.org/fvds9402 d[u] = 1 u v w FaraDars.org
51. 51. faradars.org/fvds9402 d[u] = 1 u v w d[v] = 2 FaraDars.org
52. 52. faradars.org/fvds9402 d[u] = 1 d[v] = 2 f[v] = 3 u v w FaraDars.org
53. 53. faradars.org/fvds9402 d[u] = 1 d[v] = 2 f[v] = 3 u v w d[w] = 4 FaraDars.org
54. 54. faradars.org/fvds9402 d[u] = 1 d[v] = 2 f[v] = 3 d[w] = 4 f[v] = 5 u v w FaraDars.org
55. 55. faradars.org/fvds9402 d[u] = 1 f[u] = 6 d[v] = 2 f[v] = 3 d[w] = 4 f[w] = 5 u v w FaraDars.org
56. 56. faradars.org/fvds9402 1/u x v y zw FaraDars.org
57. 57. faradars.org/fvds9402 1/u x 2/v y zw FaraDars.org
58. 58. faradars.org/fvds9402 1/u x 2/v 3/ y zw FaraDars.org
59. 59. faradars.org/fvds9402 1/u 4/ x 2/v 3/ y zw FaraDars.org
60. 60. faradars.org/fvds9402 1/u 4/5 x 2/v 3/ y zw FaraDars.org
61. 61. faradars.org/fvds9402 1/u 4/5 x 2/v 3/6 y zw FaraDars.org
62. 62. faradars.org/fvds9402 1/u 4/5 x 2/7v 3/6 y zw FaraDars.org
63. 63. faradars.org/fvds9402 1/8u 4/5 x 2/7v 3/6 y zw FaraDars.org
64. 64. faradars.org/fvds9402 1/8u 4/5 x 2/7v 3/6 y z9/w FaraDars.org
65. 65. faradars.org/fvds9402 1/8u 4/5 x 2/7v 3/6 y 10/ z9/w FaraDars.org
66. 66. faradars.org/fvds9402 1/8u 4/5 x 2/7v 3/6 y 10/11 z9/w FaraDars.org
67. 67. faradars.org/fvds9402 1/8u 4/5 x 2/7v 3/6 y 10/11 z9/12w FaraDars.org
69. 69. faradars.org/fvds9402 : 1-(u,v)TreeForward: 2-(u,v)Back: 3-(u,v)Cross: 69 uvvu ffdd vuuv ffdd uuvv fdfd FaraDars.org
70. 70. faradars.org/fvds9402 (topological sort) DAG:(Directed Acyclic Graph) 70 FaraDars.org
71. 71. faradars.org/fvds9402 : 0 1 3 2 4 5 0 1 3 2 5 4 0 1 2 3 4 5 71 FaraDars.org
73. 73. faradars.org/fvds9402 ( ) . t u v s z w y x 73 FaraDars.org
74. 74. faradars.org/fvds9402 Topological-Sort(G) 1 call DFS(G) to compute finishing times f[v] for each vertex v 2 as each vertex is finished, insert it onto the front of a linked list 3 return the linked list of vertices 74 FaraDars.org
75. 75. faradars.org/fvds9402 (): . :(MST) MST 1- 2- 75 FaraDars.org
76. 76. faradars.org/fvds9402 () 76 5 1 A H B F E D C G 3 2 4 6 3 4 3 4 8 4 3 10 FaraDars.org
77. 77. edge dv (D,E) 1 (D,G) 2 (E,G) 3 (C,D) 3 (G,H) 3 (C,F) 3 (B,C) 4 5 1 A H B F E D C G 3 2 4 6 3 4 3 4 8 4 3 10 edge dv (B,E) 4 (B,F) 4 (B,H) 4 (A,H) 5 (D,F) 6 (A,B) 8 (A,F) 10 FaraDars.org
78. 78. edge dv (D,E) 1 (D,G) 2 (E,G) 3 (C,D) 3 (G,H) 3 (C,F) 3 (B,C) 4 5 1 A H B F E D C G 3 2 4 6 3 4 3 4 8 4 3 10 edge dv (B,E) 4 (B,F) 4 (B,H) 4 (A,H) 5 (D,F) 6 (A,B) 8 (A,F) 10 FaraDars.org
79. 79. edge dv (D,E) 1 (D,G) 2 (E,G) 3 (C,D) 3 (G,H) 3 (C,F) 3 (B,C) 4 5 1 A H B F E D C G 3 2 4 6 3 4 3 4 8 4 3 10 edge dv (B,E) 4 (B,F) 4 (B,H) 4 (A,H) 5 (D,F) 6 (A,B) 8 (A,F) 10 FaraDars.org
80. 80. edge dv (D,E) 1 (D,G) 2 (E,G) 3 (C,D) 3 (G,H) 3 (C,F) 3 (B,C) 4 5 1 A H B F E D C G 3 2 4 6 3 4 3 4 8 4 3 10 edge dv (B,E) 4 (B,F) 4 (B,H) 4 (A,H) 5 (D,F) 6 (A,B) 8 (A,F) 10 FaraDars.org
81. 81. edge dv (D,E) 1 (D,G) 2 (E,G) 3 (C,D) 3 (G,H) 3 (C,F) 3 (B,C) 4 5 1 A H B F E D C G 3 2 4 6 3 4 3 4 8 4 3 10 edge dv (B,E) 4 (B,F) 4 (B,H) 4 (A,H) 5 (D,F) 6 (A,B) 8 (A,F) 10 FaraDars.org
82. 82. edge dv (D,E) 1 (D,G) 2 (E,G) 3 (C,D) 3 (G,H) 3 (C,F) 3 (B,C) 4 5 1 A H B F E D C G 3 2 4 6 3 4 3 4 8 4 3 10 edge dv (B,E) 4 (B,F) 4 (B,H) 4 (A,H) 5 (D,F) 6 (A,B) 8 (A,F) 10 FaraDars.org
83. 83. edge dv (D,E) 1 (D,G) 2 (E,G) 3 (C,D) 3 (G,H) 3 (C,F) 3 (B,C) 4 5 1 A H B F E D C G 3 2 4 6 3 4 3 4 8 4 3 10 edge dv (B,E) 4 (B,F) 4 (B,H) 4 (A,H) 5 (D,F) 6 (A,B) 8 (A,F) 10 FaraDars.org
84. 84. edge dv (D,E) 1 (D,G) 2 (E,G) 3 (C,D) 3 (G,H) 3 (C,F) 3 (B,C) 4 5 1 A H B F E D C G 3 2 4 6 3 4 3 4 8 4 3 10 edge dv (B,E) 4 (B,F) 4 (B,H) 4 (A,H) 5 (D,F) 6 (A,B) 8 (A,F) 10 FaraDars.org
85. 85. edge dv (D,E) 1 (D,G) 2 (E,G) 3 (C,D) 3 (G,H) 3 (C,F) 3 (B,C) 4 5 1 A H B F E D C G 3 2 4 6 3 4 3 4 8 4 3 10 edge dv (B,E) 4 (B,F) 4 (B,H) 4 (A,H) 5 (D,F) 6 (A,B) 8 (A,F) 10 FaraDars.org
86. 86. edge dv (D,E) 1 (D,G) 2 (E,G) 3 (C,D) 3 (G,H) 3 (C,F) 3 (B,C) 4 5 1 A H B F E D C G 3 2 4 6 3 4 3 4 8 4 3 10 edge dv (B,E) 4 (B,F) 4 (B,H) 4 (A,H) 5 (D,F) 6 (A,B) 8 (A,F) 10 FaraDars.org
87. 87. edge dv (D,E) 1 (D,G) 2 (E,G) 3 (C,D) 3 (G,H) 3 (C,F) 3 (B,C) 4 5 1 A H B F E D C G 3 2 4 6 3 4 3 4 8 4 3 10 edge dv (B,E) 4 (B,F) 4 (B,H) 4 (A,H) 5 (D,F) 6 (A,B) 8 (A,F) 10 FaraDars.org
88. 88. edge dv (D,E) 1 (D,G) 2 (E,G) 3 (C,D) 3 (G,H) 3 (C,F) 3 (B,C) 4 5 1 A H B F E D C G 3 2 4 6 3 4 3 4 8 4 3 10 edge dv (B,E) 4 (B,F) 4 (B,H) 4 (A,H) 5 (D,F) 6 (A,B) 8 (A,F) 10 FaraDars.org
89. 89. edge dv (D,E) 1 (D,G) 2 (E,G) 3 (C,D) 3 (G,H) 3 (C,F) 3 (B,C) 4 5 1 A H B F E D C G 2 3 3 3 edge dv (B,E) 4 (B,F) 4 (B,H) 4 (A,H) 5 (D,F) 6 (A,B) 8 (A,F) 10 Total Cost = 21 4 }not considered FaraDars.org
90. 90. () A F B C D E 2 7 4 5 8 6 4 5 3 8 FaraDars.org
91. 91.

Documents
Science
Documents
Documents
Internet
Documents
Documents
Documents
Documents
Data & Analytics
Documents
Documents
Documents
Education
Documents
Documents
Documents
Documents
Documents
Technology
Documents
Documents
Documents
Documents
Spiritual
Documents
Documents
Education