BAB 5

24
179

description

BAB 5. TREE. (Pohon). 179. Peng-alokasi-an memory. struktur. Stack Queue Tree. Satu dimensi. Stack. linear. Array. (statis). Queue. Dua dimensi. Graph. Tree. Stack Queue. Linear. non linear. Linked- List. Graph. (dinamis). Non Linear. Tree Graph. A. B. C. D. - PowerPoint PPT Presentation

Transcript of BAB 5

Page 1: BAB  5

179

Page 2: BAB  5

Stack

Queue

Tree

Graph

linear

nonlinear

Array

Linked-List

(statis)

(dinamis)

struktur Peng-alokasi-anmemory

Satu dimensi

Dua dimensi

Linear

NonLinear

StackQueueTree

Graph

StackQueue

TreeGraph

Page 3: BAB  5

Contoh sebuah TREE

5.1. Tree, M-ary Tree dan Binary Tree Gambar-5.1

A

CB D

E F IHG

NMJ K L

179

Page 4: BAB  5

Gambar-5.1A

CB D

E F IHG

NMJ K L

179

a. Tree dan Graph

T = G

Tree

merupakan bagian dari

Graph.

Page 5: BAB  5

A

CB D

E F IHG

NMJ K L

179

b. Simpul (Vertex, Node), dan Busur (Edge, Arc)

T = ( V,E)

V = { v0, v1, v2, . . . . . . , v13 }

E = { e0, e1, e2, . . . . . , e12 }

Gambar-5.1

v1 v2 v3

e0

v0

e1

v13

e12

e2

Page 6: BAB  5

Gambar-5.1A

CB D

E F IHG

NMJ K L

179

c. Superordinat dan Subordinat,

Father dan Son

Untuk contoh pohon diatas :Simpul B merupakan superordinat simpul E dan F.

Simpul E dan F mempunyai superordinat yang sama yaitu simpul B.

Simpul B mempunyai 2 subordinat yaitu simpul E dan simpul F

Page 7: BAB  5

Gambar-5.1A

CB D

E F IHG

NMJ K L

179

d. Akar (Root) dan Daun

(Leaf/Leaves)

Root

Akar = Simpul yang tak mempunya superordinat.

Daun = simpul yang tak mempunyai subordinat

Dari pohon diatas : Akar = Simpul : A. Daun = Simpul : C, E, G, I, J, K, L, M, N

Page 8: BAB  5

Gambar-5.1A

CB D

E F IHG

NMJ K L

179

Level

0

1

2

3

Depth = 3

e. Level dan Depth

Tingkat dan Kedalaman

Root

Akar berada di Level : 0

Subordinat Level i adalah Level : i+1

Page 9: BAB  5

Gambar-5.1A

CB D

E F IHG

NMJ K L

179

f. Degree (Derajat) Simpul dan Degree Pohon

Degree Simpul A = 3 B = 2 C = 0

Simpul daun, degree = 0

Degree Pohon :Untuk pohon ini degree pohon dapat diduga = 3,Tapi masih mungkin 4, 5 dan seterusnyaYang pasti bukan = 2

Page 10: BAB  5

179

Pohon M-Arydan

Pohon Binary

Page 11: BAB  5

179

Pohon M-Ary

M = 12345

dan setreusnya

M menyatakan derajat pohon

Khusus untukM=2,

DisebutBinary Tree

(Pohon Biner)

Page 12: BAB  5

179

Contoh sebuah TREEdengan derajat = 3(3-Ary Tree)

Gambar-5.2 a Gambar-5.2 b

D

JI

FE

B

K

HG

C

A

C

D

B

A

Page 13: BAB  5

179

Sebuah simpul pohon M-ary dimana M=3 digambarkan dengan Linked-List

Gambar-5.3

Link1 Link2 Link3

INFOtypedef struct Node { int INFO; struct Node *Link1; struct Node *Link2; struct Node *Link3;};typedef struct Node Simpul;

Strukturnya dapat dibuat dengan :

Page 14: BAB  5

179

Pohon Binary

Page 15: BAB  5

LEFT RIGHT

INFO

Sebuah simpulPohon Biner digambarkan dalam bentuk Linked-List

Gambar-5.4

typedef struct Node { struct Node *LEFT; int INFO; struct Node *RIGHT;};typedef struct Node Simpul;

Strukturnya dapat dibuat dengan :

typedef struct Node { int INFO; struct Node *LEFT; struct Node *RIGHT;};typedef struct Node Simpul;

atau

Page 16: BAB  5

typedef struct Node { struct Node *LEFT; int INFO; struct Node *RIGHT;};typedef struct Node Simpul;Simpul *First, *Last, *P, *Q, *Root;

P = (Simpul * …………………);P->INFO = X; //misal X = 25Root = P;P->Left = NULL;P->Right = NULL;

// membuat Simpul Akar

25

PRoot

Page 17: BAB  5

182

Contoh sebuah Pohon Biner

Gambar-5.5 a

A

B C

ED F

H IG

H Gambar-5.5 b

A

B

ED

G

Gambar-5.5 c

A

C

F

H I

H

Page 18: BAB  5

179

Gambar 5.6 a

A

CB D

E F HG

JI

1 3 5

6 9 11 14

16 19 21

Contoh Soal.Soal-1. Sebuah pohon M-ary dengan 10 buah simpul Bila M = 3 , maka Ditanya berapa jumlah Null-Link:

h. Link, Null-Link dan Bukan Null-Link

Page 19: BAB  5

179

Gambar-5.6 bPohon 3-ary Skewed Right(Skewed to the right)

E

F

G

H

J

J

A

B

C

D

12

3

5

7

9

4

11

13

15

17

19 21

Page 20: BAB  5

179

E

F

G

H

J

J

A

B

C

D

1 23

5

7

9

4

11

13

15

17

19 21

Jawab :

Pohon dengan M = 3Jumlah simpul 10, jadi : n = 10

Jumlah Null-Link = n * (M-1) + 1 = 10 * (3-1) + 1 = 10 * 2 + 1 = 21

A

CB D

E F HG

JI

1 3 5

6 9 11 14

16 19 21

Page 21: BAB  5

Soal-2. Sebuah Pohon Biner dengan 10 buah simpul Ditanya berapa jumlah Null-Link:

A

B C

ED F

H IG

H

23 4

1

78

9

10 11

5 6

A

B

C

D

E

F

G

H

I

J

2

3

4

5

6

7

8

9

10 11

1

Page 22: BAB  5

Soal-2. Sebuah Pohon Biner dengan 10 buah simpul Ditanya berapa jumlah Null-Link:

A

B C

ED F

H IG

H

23 4

1

78

9

10 11

5 6

Jawab :

Pohon Biner, berarti M = 2Jumlah simpul 10, jadi : n = 10

Jumlah Null-Link = n * ( M - 1 ) + 1 = 10 * ( 2 - 1 ) + 1 = 10 * 1 + 1 = 11

Page 23: BAB  5

5.2 Konversi Pohon M-ary ke Pohon Biner

A

CB D

E F IHG

NMJ K L

Level

0

1

2

3

Depth = 3

Soal : Konversikan pohon M-Ary berikut ini menjadi Pohon Biner

Page 24: BAB  5

Bentuk Transformasibelum membentuk Pohon Biner

C

G

K

D

E F

J L NM

IH

B

A

Gambar-5.10 c

Pohon Biner hasil konversi dari pohon M-ary Gambar-5.10 a

N

A

B

C

D

E

F

J

K

L

G

H

IM

Level

0

1

2

3

4

5

6

186

A

CB D

E F IHG

NMJ K L

Level

0

1

2

3