Anda di halaman 1dari 23

Pohon Merentang

Matematika Diskrit

1
Pohon Merentang (spanning tree)

 Pohon merentang dari graf terhubung adalah upagraf


merentang yang berupa pohon.
 Pohon merentang diperoleh dengan memutus sirkuit di
dalam graf.

G T1 T2 T3 T4

2
 Setiap graf terhubung mempunyai paling sedikit satu buah
pohon merentang.

 Graf tak-terhubung dengan k komponen mempunyai k buah


hutan merentang yang disebut hutan merentang (spanning
forest).

3
Aplikasi Pohon Merentang
1. Jumlah ruas jalan seminimum mungkin yang
menghubungkan semua kota sehingga setiap kota tetap
terhubung satu sama lain.
2. Perutean (routing) pesan pada jaringan komputer.

(a) (b)
Router

Subnetwork

(a) Jaringan komputer, (b) Pohon merentang multicast


4
Pohon Merentang Minimum

 Graf terhubung-berbobot mungkin mempunyai lebih dari 1


pohon merentang.
 Pohon merentang yang berbobot minimum –dinamakan pohon
merentang minimum (minimum spanning tree ).

a a
45
55 d d
25 30 25 30
c h c h
b b
40 20 40 20
50
5 15 5 15
g g
e e
35 10 10
f f

5
Algoritma pada MST
 Algoritma Kruskal
◦ menggunakan edge
◦ dalam tiap tahapan membetuk forest
 Algoritma Prim
◦ menggunakan verteks
◦ dalm tiap tahapan membetuk tree

6
Graph – MST – ALGORITMA KRUSKAL

Algoritma Kruskal
1. Create Tree berisi semua verteks tanpa edge
2. Tambahkan edge minimum cost
Hapus edge dr graph
(edge baru tidak boleh membentuk cycle
graph dgn tree terbentuk)
3. Ulang langkah 2 hingga n-1 edge berada
dlm tree (n: jumlah vertex dlm graph)

7
Graph – MST – Contoh Kruskal (1)
0 28
0 10
28 1
10 14
1 5 16
14 6
5 16
25 2
6
25 2 24 18 12
24 18 12
4
4 22 3
22 3 0
0 28 28
10 10
1 1
14 14
5 16 5 16
6 6
25 2 25 2
24 18 24 18 12
12
4 4
22 3 22 3
8
Graph – MST – Contoh Kruskal (1) - lanjutan

0 28 0 28
10 10
1 1
14 14
5 16 5 16
6 6
25 2 25 2
24 18 12 24 18 12
4 4
22 3 22 3
0 28
10
Beberapa edge yg digambar dgn garis 1
putus diabaikan karena akan 14
membentuk cycle pd MST.
5 16
6
25 2
24 18 12
MST dgn titik awal 0 : Total cost = 99
4
22 3
9
Graph – Contoh Kruskal (2)
N2 2 N3 4 N4 N2 N3 N4
1 7
N1 6 N5 N1 N5
4 5 7 6
3 8
8 1
N6 N7 N8 N6 N7 N8

N2 N3 N4 N2 N3 N4

N1 N5 N1 N5

N6 N7 N8 N6 N7 N8
N2 N3 N4
N2 N3 N4

N1 N5 N1 N5

N6 N7 N8
N6 N7 N8 10
Graph – MST – Contoh Kruskal (2) - Lanjutan

N2 2 N3 4 N4 N2 N3 N4
1 7
N1 6 N5
4 5 7 6 N1 N5
3 8
8 1
N6 N7 N8 N6 N7 N8

N2 N3 N4 N2 N3 N4

N1 N5 N1 N5

N6 N7 N8 N6 N7 N8

MST : cost = 23

11
Graph – MST - Contoh Kruskal (3)

12
Graph – MST – Algoritma Prim

//T dan TV berisi edge dan verteks MST


T = { }; //no edge
TV={0}; //1 verteks sembarang
while (edge di T < n-1) {
let (u,v) be a least cost edge such that u Є TV and
v Є TV;
if (there no such edge) break;
add v to TV;
add (u,v) to T;
}
if (T contains fewer than n-1 edges) printf (“no
spanning tree”);

13
Graph – MST - Alternatif Algoritma Prim

Alternatif Algoritma Prim ((Sugih Jamin (jamin@eecs.umich.edu


))

1. given G = (V;E) a weighted, connected,


undirected graph
2. separate V into two sets:
T: nodes on the MST
Tc: those not
3. T initially empty, choose a random node and add
it to T
4. select an edge with the smallest cost/weight/
distance from any node in T that connects to a
node v in Tc, move v to T
5. repeat step 4 until T c is empty

14
Graph – MST - Contoh Prim (1)

0 28
10
1
14
5 16
6
25 2
24 18 12
VT T cost mst
4 0 (0,5) 10 (0,5)
22 3
5 (5,4) 25 (5,4)

4 (4,3) 22 (4,3)

3 (3,2) 12 (3,2)

2 (2,1) 16 (2,1)

1 (1,6) 14 (1,6)

15
Graph – MST – Contoh Prim (2)

T VT alternatif edge cost

(a,d) a b 13

c 8

d 1

1
16
Graph – MST – Contoh Prim (2) - lanjutan
T VT alternatif edge cost
(a,d) a b 13
(d,e) c 8
d c 5
e 4
f 5
5

T VT alternatif edge cost


(a,d) a b 13
(d,e) c 8
(e,f) d c 5
f 5
e c 3
f 2
7 17
Graph – MST – Contoh Prim (2) - lanjutan
T VT alternatif edge cost
(a,d) a b 13
(d,e) c 8
(e,f) d c 5
(e,c) f 5
10 e c 3

T VT alternatif edge cost


(a,d) a b 13
(d,e) c 8
(e,f) d c 5
(e,c) f 5
(a,b) e - -
c b 15
23
(a,c), (d,c) dan (d,f) tidak dapat dipilih karena akan membentuk 18cyc
Graph – MST – Contoh Prim (2) - lanjutan

19
Graph – MST - Contoh Prim (3)
N2 N3 N4 edge yang mungkin
2 4
edge yg dipilih
1 7
6 7
N1 4 5 6 N5
3 8
8 1 N2 N3 N4
N6 N7 N8 2 4
1 7
6 7
N1 4 5 6 N5
3 8
N2 N3 N4 8 1
2 4 N6 N7 N8
1 7
6 7
N1 4 5 6 N5
3 8
Edge yg
8
mungkin 1
N6 N7 N8 20
Graph – MST – Contoh Prim (3)
N N N
2 4
2 3 4
1 7
6 7
N 4 5 6 N
1 3 8 5
N N N
8 1 2 4
N N N 2 3 4
6 7 1 7
8
6 7
N 4 5 6 N
1 5
3 8
8 1
N2 N3 N4 N N N
2 4 6 7 8
1 7
6 7
N1 4 5 6 N5
3 8
8 1
N6 N7 N8
21
Graph – MST – Contoh Prim (3)

N2 N3 N4
2 4
1 7
6 7
N1 4 5 6 N5
3 8
8 1
N6 N7 N8

N2 N3 N4
2 4
1 7
6 7
N1 4 5 6 N5
3 8
8 1
N6 N7 N8
22
Tentukan dan gambarkan pohon merentang minimum dari graf di bawah ini
(tahapan pembentukannya tidak perlu ditulis).
a 5 b 4 c

2 3 5 6 3
7 e 1
d f
6 8 3 4 4

g 4 h 2 i

23

Anda mungkin juga menyukai