Upload presentasi
Presentasi sedang didownload. Silahkan tunggu
1
Pertemuan 22 Graph Operation
Matakuliah : T0026/Struktur Data Tahun : 2005 Versi : 1/1 Pertemuan 22 Graph Operation
2
Learning Outcomes Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : Mahasiswa dapat menghasilkan program modular untuk mengimplementasikan graph operation dan spanning tree
3
Pengertian graph operation Graph traversal Depth First Search
Outline Materi Pengertian graph operation Graph traversal Depth First Search Breadth First Search Contoh operasi DFS dan DFS Spanning Tree Contoh konstruksi Spanning Tree
4
Depth First Search (DFS) Bread First Search (BFS)
Graph Traversal Depth First Search (DFS) Algoritma akan memanfaatkan stack Bread First Search (BFS) Algoritma akan memanfaatkan queue Pembahasan DFS dan BFS akan menggunakan representasi Adjacency List Pada saat mengunjungi sebuah node, nama node akan dicetak
5
Graph – DEPTH FIRST SEARCH
Algoritma DFS : For (all v in G) visited[v] = FALSE; void dfs (int v) { node_pointer w; visited[v] = TRUE; printf (“%d”, v); for (w = graph[v]; w; w=w->link) if (!visited[w->vertex]) dfs(w->vertex); }
6
Graph – BREADTH FIRST SEARCH (BFS)
Algoritma BFS: void BFS(G){ for (all v in G) { if (visited[v] = FALSE){ EnQueue(v,Queue); do { DeQueue(v, Queue); visited[v] = TRUE; Visit(v); for (all w adjacent to v) if (visited(w)= FALSE) EnQueue(w,Queue); } while (!Empty(Queue)); }
7
Graph – Contoh(1) Vo V1 V2 V3 V4 V5 V6 V7 1 2 3 4 5 6 7
Adjacency List : perhatikan urutan node pd edge list sesuai dengan urutan head node list Vo V1 V2 V3 V4 V5 V6 V7 1 2 3 4 5 6 7
8
v Stack Status visited Printout vo Empty v1 v2 v3 v2 v4 v7 v4 v2 v4 v5
Graph – Contoh(1) - DEPTH FIRST SEARCH (DFS) v Stack Status visited Printout vo Empty v1 v2 v3 v2 v4 v7 v4 v2 v4 v5 v5 v2 v4 v7 v6 - empty
9
Graph – Contoh(1) – Hasil DFS dan BFS
Hasil BFS Vo V1 V2 V3 V4 V5 V6 V7 Vo V1 V2 V3 V4 V5 V6 V7
10
Graph – BREADTH FIRST SEARCH (BFS)
v w Queue Printout Status visited vo v1 v2 v1 v2 v0 v3 v2 v3 v4 v2 v3 v4 v3 v4 v5 v3 v4 v5 v6 v3 v4 v5 v6 v4 v5 v6 v7 v4 v5 v6 v7 v5 v6 v7
11
Graph – BREADTH FIRST SEARCH (BFS)
v w Queue Printout Status visited v4 v1 v5 v6 v7 v7 v5 v2 v6 v7 v6 v3 empty
12
Graph – Contoh 2 A B F C E D A B C E D F
13
Graph – Contoh 2 - DFS verteks Stack Status visited Printout A B C C E E D C E F F
14
Graph – Contoh(2) - BFS v w Queue Printout Status visited A B C B C D
C D E F C D E F - empty
15
Graph – Contoh(2) – Hasil DFS dan BFS
Hasil DFS Hasil BFS A B F C E D A B F C E D
16
Graph – Contoh 3 A B E C F D G H A B C E F D G H
17
Graph – Contoh(3) - DEPTH FIRST SEARCH (DFS)
verteks Stack Status visited Printout A empty B C C E F D C E E G C E E H H E -
18
Graph – Contoh(3) - BREADTH FIRST SEARCH (BFS)
v w Queue Printout Status visited A B C B C D B C D C D E C D E F C D E F D E F E F G H
19
Graph – Contoh(3) - DEPTH FIRST SEARCH (DFS)
Hasil DFS Hasil BFS A B E C F D G H A B E C F D G H
Presentasi serupa
© 2024 SlidePlayer.info Inc.
All rights reserved.