# TREES - PowerPoint PPT Presentation

1 / 22

TREES. Tree. Minimal Terdiri dari 1 node (simpul). node. root. m – ary Tree. leaf. leaf. Branch. binary. Binary Tree. Binary juga disebut 2-ary Tree Yaitu Tree dengan anak <=2. +. A. B. Representasi Infix pada Tree. 1. Infix A+B. 2. Infix A * B ^ C – D. -. D. *. A. ^. B.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

TREES

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

## TREES

### Tree

• Minimal Terdiri dari 1 node (simpul)

node

root

m – ary Tree

leaf

leaf

Branch

binary

### Binary Tree

Binary juga disebut 2-ary Tree

Yaitu Tree dengan anak <=2

+

A

B

1. Infix A+B

2. Infix A * B ^ C – D

-

D

*

A

^

B

C

+

/

A

D

B

E

3. Infix (A+B) * C + D / E

+

*

C

• Tree dibawah

N0

Level 0

N3

Level 1

N1

N2

Level 2

N5

N4

N6

N7

N8

N9

N10

N11

Level 3

### Tree Level

• Keterangan

Root = N0

Leaf = N4,N5,N6,N7,N9,N10,N11

Branch node = N1,N2,N3,N8

T1 = N1,N4,N5,N6

T2 = N2,N7

T3 = N3,N8,N9,N10,N11

Depth = Max Level

N0

N3

N1

N9

N8

N4

N5

N6

N10

N11

N2

N7

1. Diagram Venn

### Representasi Tree

2. Pedigree Chart

N0

N3

N1

N2

N5

N4

N6

N7

N8

N9

N10

N11

N4

N5

N1

N6

N0

N2

N7

N10

N8

N3

N11

N9

3. Linear chart

### Representasi Tree

4. Nested Parentheses

(N0(N1(N4)(N5)(N6))(N2(N7))

(N3(N8(N10)(N11))(N9)))

N0

N1

N4

N5

N6

N2

N7

N3

N8

N10

N11

N9

5. Bar Chart

### Representasi Tree

6. Level-Number Chart

1 N0

2 N1

3 N4

3 N5

3 N6

2 N2

3 N7

2 N3

3 N8

4 N10

4 N11

3 N9

A

A

B

B

A

A

=

B

B

• General Tree

• Binary Tree

A

B

C

D

E

F

G

J

K

H

I

### Binary Tree dalam Array

• Representasi Binary Tree pada Array

Anak kiri = 2n

Anak Kanan = 2n+1

n = index saat ini

### Konversi General Tree ke Binary Tree

• Langkah-langkah konversi:

• menghapus semua cabang (branch) yang terhubung pada setiap node, kecuali cabang yang paling kiri. Selanjutnya menghubungkan semua node pada level yang sama dengan branch

• mengubah menjadi binary-tree, di mana branch kiri adalah branch yang vertical & branch kanan adalah branch yang horizontal.

B

B

A

Y

A

Y

Z

C

Z

J

P

H

C

H

I

J

X

I

P

N

O

N

X

O

B

A

C

Y

H

Z

I

J

N

P

O

X

### Konversi General Tree ke Binary Tree

Data

L – Child

R – Child

L

R

D

Print Data

• Traversal Inorder : L D R

• Traversal Preorder : D L R

• Traversal Postorder : L R D

B

A

A

B

C

C

D

E

• Inorder = A B C

• Preorder = B A C

• Postorder = A C B

• Inorder = D B E A C

• Preorder = A B D E C

• Postorder = D E B C A

A

A

A

B

B

C

D

B

C

D

E

C

E

F

G

F

D

E

F

G

G

Inorder : E FG B C D A

Preorder : A B E F G C D

Postorder : G F E D C B A

### Soal

Gambarkan Binary Tree yang dimaksud

• Traversal Preorder : ABCDEFGHI

• Traversal Inorder : CDEBFAIHG

• Traversal Postorder: EDACGFBH, jumlah child untuk masing-masing node adalah: A = 1; B = 2; C = 0; D = 1; E = 0; F = 1; G = 0; H = 2