KEMBAR78
Data Structure (Tree) | PPSX
Tree
Adam M.B.
DEFINITION

Tree
Tree 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.
Components of Tree
A
B C D
E F G
Root (akar)
Leaf (daun)
Level/Tingkat
1
2
3
Subtree
Node/Vertex/Simpul
Edge/Link
TERMINOLOGY

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.
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.
Ilustration
Predecessor(B) : A
Successor(A) : B,C,D
Ancestor(E) : B,A
Descendant(B) : E,F
A
B
C
D
E F G
Parent(E) : B
Sibling(E) : F
Degree(A) : 3
Binary Tree
Binary
Tree
The
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)
Binary Tree
A
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
Types of Binary Tree
Full 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.
m
MAKING OF
BINARY TREE

Making of Binary Tree
• From input data
• From general tree
• From result of traversal process
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.
From Input Data
Example:
H will be root
A < H :
A will be left child of H
K > H :
K will be right child of H
C < H  C > A :
C will be right child of A
B < H  B > A  B < C :
B will be left child of C
L > H  L > K :
L will be right child of K
J < H  J < K :
J will be left child of K
H
A
L
K
B
C J
AH KCBLJ
Make binary tree from these input data:
• GHCKJALBEFD
• KGMDLSBRJP
Exercise
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.
From General Tree
General Tree Binary Tree
A
B
H
C
D E F G
I
A
B
H
CD
E F
GI
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)
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
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
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
Make binary tree from this general tree:
Exercise
K
L
Y
W
M O X
ZR
N
P Q
Make binary tree from this statement:
• K, C, P, E, M, B, R, G, Q, F, W
• E = A + BDH – F
G - K
Exercise
Contact Person:
Adam Mukharil Bachtiar
Informatics Engineering UNIKOM
Jalan Dipati Ukur Nomor. 112-114 Bandung 40132
Email: adfbipotter@gmail.com
Blog: http://adfbipotter.wordpress.com
Copyright © Adam Mukharil Bachtiar 2012

Data Structure (Tree)

  • 1.
  • 2.
  • 3.
    Tree Tree is datastructure 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.
  • 4.
    Components of Tree A BC D E F G Root (akar) Leaf (daun) Level/Tingkat 1 2 3 Subtree Node/Vertex/Simpul Edge/Link
  • 5.
  • 6.
    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.
  • 7.
    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.
  • 8.
    Ilustration Predecessor(B) : A Successor(A): B,C,D Ancestor(E) : B,A Descendant(B) : E,F A B C D E F G Parent(E) : B Sibling(E) : F Degree(A) : 3
  • 9.
    Binary Tree Binary Tree The maximum degree ofone node is 2. Maximum node until level N is 2N - 1 The maximum number of node each level is 2 (N-1)
  • 10.
    Binary Tree A B G C D EF 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
  • 11.
    Types of BinaryTree Full 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.
  • 12.
  • 13.
    Making of BinaryTree • From input data • From general tree • From result of traversal process
  • 14.
    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.
  • 15.
    From Input Data Example: Hwill be root A < H : A will be left child of H K > H : K will be right child of H C < H  C > A : C will be right child of A B < H  B > A  B < C : B will be left child of C L > H  L > K : L will be right child of K J < H  J < K : J will be left child of K H A L K B C J AH KCBLJ
  • 16.
    Make binary treefrom these input data: • GHCKJALBEFD • KGMDLSBRJP Exercise
  • 17.
    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.
  • 18.
    From General Tree GeneralTree Binary Tree A B H C D E F G I A B H CD E F GI
  • 19.
    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)
  • 20.
    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
  • 21.
    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
  • 22.
    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
  • 23.
    Make binary treefrom this general tree: Exercise K L Y W M O X ZR N P Q
  • 24.
    Make binary treefrom this statement: • K, C, P, E, M, B, R, G, Q, F, W • E = A + BDH – F G - K Exercise
  • 25.
    Contact Person: Adam MukharilBachtiar Informatics Engineering UNIKOM Jalan Dipati Ukur Nomor. 112-114 Bandung 40132 Email: adfbipotter@gmail.com Blog: http://adfbipotter.wordpress.com Copyright © Adam Mukharil Bachtiar 2012