Data Structure (Tree)
-
Upload
adam-mukharil-bachtiar -
Category
Software
-
view
115 -
download
1
Transcript of Data Structure (Tree)
![Page 1: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/1.jpg)
Tree
Adam M.B.
![Page 2: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/2.jpg)
DEFINITION
![Page 3: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/3.jpg)
TreeTree is data structure that is non linear
and can be used to represents data in
hierarchy between those elements. For
example: organization structure, family
tree, and the tournament.
![Page 4: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/4.jpg)
Components of Tree
A
B C D
E F G
Root (akar)
Leaf (daun)
Level/Tingkat1
2
3
Subtree
Node/Vertex/Simpul
Edge/Link
![Page 5: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/5.jpg)
TERMINOLOGY
![Page 6: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/6.jpg)
Terminology of Tree• Predecessor node that is above certain node.
• Successor node that is below certain node
• Ancestor all nodes that is before certain node and
in the same path.
• Descendant all nodes that is after certain node
and in the same path.
![Page 7: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/7.jpg)
Terminology of Tree
• Parent predecessor that is one level above
certain node.
• Sibling nodes that have same parent
• Degree number of child in one node.
![Page 8: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/8.jpg)
Ilustration
Predecessor(B) : ASuccessor(A) : B,C,DAncestor(E) : B,ADescendant(B) : E,F
A
BC
D
E F G
Parent(E) : BSibling(E) : FDegree(A) : 3
![Page 9: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/9.jpg)
Binary Tree
Binary
TreeThe
maximum degree of
one node is 2.
Maximum node until level N is
2N - 1 The
maximum number of node each level is 2
(N-1)
![Page 10: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/10.jpg)
Binary TreeA
B
G
C
D E F
Left Child Right Child
Root
Maximum node on 3rd level = 2(N-1)
Maximum node until 3rd level = 2N - 1
Parent
= 2(3-1)
= 22
= 4
= 23- 1= 8 - 1= 7
![Page 11: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/11.jpg)
Types of Binary TreeFull Binary Tree Complete Binary Tree
A
B
G
C
D E F
A
B C
D E
• All nodes (except leaf) have two children.
• Each subtree has same length of path.
• All nodes (except leaf) have two children.
• Each subtree can has different length of path.
![Page 12: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/12.jpg)
m
MAKING OF BINARY TREE
![Page 13: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/13.jpg)
Making of Binary Tree
• From input data
• From general tree
• From result of traversal process
![Page 14: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/14.jpg)
From Input Data• If value of inserted node is bigger
than parent then it will be right
subtree.
• If value of inserted node is smaller
than parent then it will be left
subtree.
• This tree is known as binary search
tree.
![Page 15: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/15.jpg)
From Input DataExample:H will be rootA < H : A will be left child of HK > H : K will be right child of HC < H C > A :C will be right child of AB < H B > A B < C : B will be left child of CL > H L > K : L will be right child of KJ < H J < K : J will be left child of K
H
A
L
K
B
C J
AH KCBLJ
![Page 16: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/16.jpg)
Make binary tree from these input data:• GHCKJALBEFD• KGMDLSBRJP
Exercise
![Page 17: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/17.jpg)
From General Tree
• First son in general tree will be left
son in binary tree
• Next brother of first son in general
tree will be right son in binary tree.
![Page 18: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/18.jpg)
From General TreeGeneral Tree Binary Tree
A
B
H
C
D E F G
I
A
B
H
CD
E F
GI
![Page 19: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/19.jpg)
From General Tree (Program)
One node in general tree
One node in binary tree
First Son(FS)
Next Brother
(NB)
Data Field(Info)
Left Son(LS)
Right Son(RS)
Data Field(Info)
![Page 20: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/20.jpg)
From General Tree (Program)General Tree
A
B
H
C
D E F G
I
General Tree(Linked List)
A
B
Head
CD
F
G
H
I
E
![Page 21: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/21.jpg)
From General Tree (Program)Binary Tree(Linked List)
A
B
D
E F
C
I G
H
Head
Binary Tree
A
B
H
CD
E F
GI
![Page 22: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/22.jpg)
From General Tree (Program)
General Tree(Linked List)
A
B
Head
CD
F
G
H
I
E
Binary Tree(Linked List)
Head
A
B
D
E F
C
I G
H
![Page 23: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/23.jpg)
Make binary tree from this general tree:
Exercise
K
L
Y
W
M O X
ZR
N
P Q
![Page 24: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/24.jpg)
Make binary tree from this statement:• K, C, P, E, M, B, R, G, Q, F, W
• E = A + BDH – F G - K
Exercise
![Page 25: Data Structure (Tree)](https://reader036.fdocuments.net/reader036/viewer/2022062400/58cfd6931a28ab13238b4f21/html5/thumbnails/25.jpg)
Contact Person:Adam Mukharil Bachtiar
Informatics Engineering UNIKOMJalan Dipati Ukur Nomor. 112-114 Bandung 40132
Email: [email protected]: http://adfbipotter.wordpress.com
Copyright © Adam Mukharil Bachtiar 2012
GRACIASTHANK YOU