tree

42
tReE Tenia Wahyuningrum, S.Kom. MT www.st3telkom.ac.id

Upload: tenia-wahyuningrum

Post on 04-Jul-2015

238 views

Category:

Technology


2 download

DESCRIPTION

membahas pohon dalam struktur data, pohon biner, dan penelusuran pohon biner

TRANSCRIPT

Page 1: Tree

tReE

Tenia Wahyuningrum, S.Kom. MT

www.st3telkom.ac.id

Page 2: Tree

Tree …

Kumpulan node yang saling

terhubung satu sama lain

dalam suatu kesatuan yang

membentuk layakya struktur sebuah

pohon.

www.st3telkom.ac.idTenia Wahyuningrum

Page 3: Tree

Tree … merepresentasikan suatu struktur

hirarki (one-to-many)

tampak sebagai kumpulan node dari

atas ke bawah.

www.st3telkom.ac.idTenia Wahyuningrum

Page 4: Tree

Tree …

salah satu bentuk implementasi

banyak linked list yang

digunakan untuk menggambarkan

hubungan yang bersifat hirarkis

www.st3telkom.ac.idTenia Wahyuningrum

Page 5: Tree

Karena harapan lah, kita menanam pohon

Meskipun kita tahu tak akan memetik buahnya berpuluh-puluh tahun kemudian

Page 6: Tree

Family tree

www.st3telkom.ac.idTenia Wahyuningrum

Contoh penggunaan struktur

tree

Page 7: Tree

Tournamen schedule

www.st3telkom.ac.idTenia Wahyuningrum

Contoh penggunaan struktur

tree

Page 8: Tree

Organization Structure

www.st3telkom.ac.idTenia Wahyuningrum

Contoh penggunaan struktur

tree

Page 9: Tree

Tree anatomy

R

ST

X

ZY

WVU

Root

Internal Node

Leaf

Child of X

Subtree

Parent of Z and Y

Level 0

Level 1

Level 2

Level 3

Page 10: Tree

Terminologi Tree

www.st3telkom.ac.idTenia Wahyuningrum

Page 11: Tree

a Tree

R

S T

ZY WVU

www.st3telkom.ac.idTenia Wahyuningrum

Ancestor (U) = T, R

Descendant (T) = U, V, W

Parent (Y) = S

Child (R) = S, T

Sibling (U) = V, W

Size = 8

Height = 3

Root = R

Leaf = Y, Z, U, V, W

Degree (T) = 3

Page 12: Tree

www.st3telkom.ac.idTenia Wahyuningrum

Representasi Tree

Page 13: Tree

Notasi Tingkat

Tree Representation

www.st3telkom.ac.idTenia Wahyuningrum

Page 14: Tree

Notasi Kurung

(A(B(D,E(I,J)),C(F,G,H)))

Tree Representation

www.st3telkom.ac.idTenia Wahyuningrum

Page 15: Tree

Latihan• Buat diagram venn, notasi kurung dan

notasi tingkat!X

Y R S

QT WU

Z

P M

N

www.st3telkom.ac.idTenia Wahyuningrum

Page 16: Tree

• Identifikasikan !

Ancestor (N) =

Descendant (Y) =

Parent (Z) =

Child (Q) =

Sibling (U) =

Size =

Height =

Root =

Leaf =

Degree (R) =

www.st3telkom.ac.idTenia Wahyuningrum

Page 17: Tree

Binnary Tree

Semakin tinggi pohon, semakin kuat angin meniupnya

Page 18: Tree

– Suatu tree dengan syarat bahwa tiap

node hanya boleh memiliki maksimal dua

subtree dan kedua subtree tersebut harus

terpisah.

– Tiap node dalam binary tree hanya boleh

memiliki paling banyak dua child.

www.st3telkom.ac.idTenia Wahyuningrum

Page 19: Tree

www.st3telkom.ac.idTenia Wahyuningrum

Binary Tree

Page 20: Tree

Binary Tree

www.st3telkom.ac.idTenia Wahyuningrum

A

B C

ED GF

Page 21: Tree

www.st3telkom.ac.idTenia Wahyuningrum

A

B C

ED

Binary Tree

Page 22: Tree

www.st3telkom.ac.idTenia Wahyuningrum

A

B E

C F

D

Binary Tree

Page 23: Tree

Jumlah maksimum node pada setiap

tingkat adalah 2n

Node pada binary tree maksimum

berjumlah 2n-1

www.st3telkom.ac.idTenia Wahyuningrum

Node pada Binary Tree

Page 24: Tree

www.st3telkom.ac.idTenia Wahyuningrum

A

B C

ED GF

Node pada Binary Tree

Tingkat ke-0, jumlah max = 20

Tingkat ke-1, jumlah max = 21

Tingkat ke-2, jumlah max = 22

Page 25: Tree

Latihan• Gambarkan pohon biner dengan

ketentuan sbb : Ancestor (M) = Z, X

Descendant (Y) = K, L

Parent (N) = Z

Child (Z) = M, N

Sibling (Y) = Z

Size = 7

Height = 3

Root = X

Leaf = K, L, M, N

www.st3telkom.ac.idTenia Wahyuningrum

Page 26: Tree

xxx

www.st3telkom.ac.idTenia Wahyuningrum

Penelusuran Pohon Biner

Jika kau teriaki dan maki pohon, lambat laun pohon akan mati

Page 27: Tree

Definisi• Penelusuran seluruh node pada binary

tree.

• Metode :

–Preorder

–Inorder

–Postorder

www.st3telkom.ac.idTenia Wahyuningrum

Page 28: Tree

PreOrder Traversal

1. Cetak data pada root

2. Secara rekursif mencetak seluruh data

pada subpohon kiri

3. Secara rekursif mencetak seluruh data

pada subpohon kanan

www.st3telkom.ac.idTenia Wahyuningrum

Page 29: Tree

Preorder Example (visit =

print)a

b c

a b c

www.st3telkom.ac.idTenia Wahyuningrum

Page 30: Tree

Preorder Example (visit =

print)a

b c

d ef

g h i j

a b d g h e i c f j

www.st3telkom.ac.idTenia Wahyuningrum

Page 31: Tree

Preorder Of Expression Tree

+

a b

-

c d

+

e f

*

/

Gives prefix form of expression!

/ * + a b - c d + e f

www.st3telkom.ac.idTenia Wahyuningrum

Page 32: Tree

InOrder Traversal

1.Secara rekursif mencetak seluruh data

pada subpohon kiri

2.Cetak data pada root

3.Secara rekursif mencetak seluruh data

pada subpohon kanan

www.st3telkom.ac.idTenia Wahyuningrum

Page 33: Tree

Inorder Example (visit = print)a

b c

b a c

www.st3telkom.ac.idTenia Wahyuningrum

Page 34: Tree

Inorder Example (visit = print)

a

b c

d ef

g h i j

g d h b e i a f j c

www.st3telkom.ac.idTenia Wahyuningrum

Page 35: Tree

Postorder Traversal

1.Secara rekursif mencetak seluruh data

pada subpohon kiri

2.Secara rekursif mencetak seluruh data

pada subpohon kanan

3.Cetak data pada root

www.st3telkom.ac.idTenia Wahyuningrum

Page 36: Tree

Postorder Example (visit =

print)a

b c

b c a

www.st3telkom.ac.idTenia Wahyuningrum

Page 37: Tree

Postorder Example (visit =

print) a

b c

d ef

g h i j

g h d i e b j f c a

www.st3telkom.ac.idTenia Wahyuningrum

Page 38: Tree

Postorder Of Expression Tree

+

a b

-

c d

+

e f

*

/

Gives postfix form of expression!

a b + c d - * e f + /

www.st3telkom.ac.idTenia Wahyuningrum

Page 39: Tree

Latihan• Telusuri pohon biner berikut dengan

menggunakan metode pre, in, post !

www.st3telkom.ac.idTenia Wahyuningrum

Page 40: Tree

Latihan 1

+

*

3 5

-

2 /

8 4

www.st3telkom.ac.idTenia Wahyuningrum

Page 41: Tree

Latihan 2

www.st3telkom.ac.idTenia Wahyuningrum

2

7 5

62 9

4115

Page 42: Tree