SlideServe
Menu
Preferences
© SlideServe · v2026

Data Structures

darva avatar
12 slides · 370 Views · 150 likes · Sep 10, 2014

Data Structures. Week 10 : Graph(Shortest Path) http://www.cs.hongik.ac.kr/~rhanha/rhanha_teaching.html. e. 2. b. 4. f. 1. 2. 6. 7. a. c. h. 3. 2. 2. d. g. 5. Dijkstra’s Algorithm. 1 2 3 4 5 6 7 8. 1. 1 2 3 4 5 6 7 8. b. 1. 7. a. c. 2.

Data Structures - slide 1
01 / 12Data Structures
1 / 17

Download Presentation

Data Structures
An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

More Related Content

Presentation Transcript
  1. Data Structures Week 10: Graph(Shortest Path) http://www.cs.hongik.ac.kr/~rhanha/rhanha_teaching.html

  2. e 2 b 4 f 1 2 6 7 a c h 3 2 2 d g 5 Dijkstra’s Algorithm 1 2 3 4 5 6 7 8 1 1 2 3 4 5 6 7 8

  3. b 1 7 a c 2 d

  4. e 2 b 4 f 1 7 a c 2 d

  5. e 2 b 4 f 1 2 7 a c 2 d g 5

  6. e 1 2 b f 1 7 a c 2 d g 5

  7. e 2 b f 1 2 6 a c h 2 d g 5

  8. e 2 b f 1 2 6 a c h 2 d g 5

  9. e 2 b f 1 2 a c h 2 2 d g 5

  10. Add data 1 #include <stdio.h> #define N 8 #define M 9999 int a[N+1][N+1] = {{0,0,0,0,0,0,0,0,0}, {0,0,1,7,2,M,M,M,M}, {0,1,0,M,M,2,4,M,M}, {0,7,M,0,M,M,2,3,M}, {0,2,M,M,0,M,M,5,M}, {0,M,2,M,M,0,1,M,M}, {0,M,4,2,M,1,0,M,6}, {0,M,M,3,5,M,M,0,2}, {0,M,M,M,M,M,6,2,0}};

  11. Program- initialize void main(void) { int j,k,p,start,min; leng[N+1], /*마디까지의 거리*/ v[N+1]; /*확정 플래그*/ for (k=1;k<=N;k+1) { leng[k]=M; v[k]=0; } leng[start]=0;

  12. Program- main loop for(j=1;j<=N;j++){ min=M; for(k=1;k<=N;k++){ if(v[k]==0 && leng[k]<min){ p=k; min=leng[k]; } } v[p]=1; /*최소의 마디 확정*/ if(min==M){ return(0); /*해당 노드는 다른 노드와 연결되지 않았음*/ } /*p를 경유하여 k에 이르는 길이가 그곳까지의 최단거리보다 작으면 경신*/ for(k=1;k<=N;k++){ if((leng[p]+a[p][k])<leng[k]) leng[k]=leng[p]+a[p][k]; } } /*end of main*/