Anda di halaman 1dari 22

Tree

Definition

• Struktur data terdiri dari akar, dan sub pohon dalam susunan hirarki.
• Suatu bentuk struktur data non-linear

2
Definition

• Biasanya digunakan untuk menjelaskan, hierarchical data relationships,


seperti:
• organizational structure
• classification tree / genealogy
• syntax tree / tree expression

3
Example

• Organization Structure
• Family tree
• Tournament tree

4
Example

• Organization Structure
• Arithmetic expression
Example : (4+3*7)-(5/(3+4)+6

5
Example

• Organization Structure
• Arithmetic expression
• Decision Tree

6
Tree Terminology

• Leaf (daun)
• Connection between nodes
• (parent, child, sibling)
• Level (tingkat)
• Degree (derajat)
• Height (ketinggian) dan depth (Kedalaman)
• Ancestor (leluhur) dan Descendant (keturunan)
• Forest

7
Tree Terminology
• Tree merupakan kumpulan dari banyak nodes
• Setiap node mungkin memiliki 0 or more successor
• Setiap node memiliki one predecessor
• Kecuali puncak simpul (root)

• Root merupakan node teratas tree


• Link yang menghubungkan node dan successors disebut branches /
edges

8
Tree Terminology
• Successors dari node disebut children (child)
• Predecessor dari node disebut parent
• Node dengan parent yang sama disebut siblings
• Nodes yang tidak memiliki child disebut leaf/external node
• Jumlah child dari node disebut degree

9
Tree Terminology
• Descendant merupakan daftar semua child / successor untuk leaf
• Ancestor merupakan daftar predecessor / parent untuk root
• Level node didefinisikan oleh 1 + jumlah koneksi antara node dan
root.

10
Tree Terminology

• Height dari tree adalah jumlah edge pada path ke


arah bawah terpanjang antara root dan leaf.
• Height dari node adalah jumlah edge pada path ke
arah bawah terpanjang antara node dan leaf.
• Depth node adalah jumlah edge dari node ke root
node root tree

11
Terminology
Degree = 2
Root
Degree = 3

Node / Vertex

Degree = 0

12
Exercise on Tree Terminology
• Root =
• Sibling C =
• Parent F =
• Child B =
• Leaf =
• Level E =
• Tree height =
• Degree B =
• Ancestor I =
• Descendant B =

13
Exercise on Tree Terminology
• Buatlah tree
• Dataset: {A, X, W, H, B, E, S}
• Root: A
• Ancestor of S: {E, A}
• {X, W, E} adalah siblings
• {H, B} adalah descendant dan keduanya adalah children dari W

14
Question?
Tree Notations / Representing Tree
• Tree Diagram Notation
• Classical node-link diagrams
• Venn Diagram Notation
• Nested sets / Tree Maps
• Bracket Notation
• Nested Parentheses
• Level Notation
• Outlines / tree views

16
Tree Diagram Notation

17
Venn Diagram Notation

18
Bracket Notation

19
Level Notation

20
Exercise on Tree Notation
• Buatlah Venn Diagram, Bracket, dan level notation. Dari tree tersebut

Y R S

Q T U W Z

P M N

21
Question?

Anda mungkin juga menyukai