4 - Introduction to Tree, Binary Tree and Expression Tree - 2101702130 - Andrean
Pertemuan ke - 4
20-03-2018
2101702130 - Andrean
20-03-2018
Tree & Binary Tree
Tree Concept
DEGREE
of TREE = 3
DEGREE
of C = 2
HEIGHT
= 3
PARENT
of C = A
CHILDREN
of A = B, C, D
SIBILING
of F = G
ANCESTOR
of F = A, C
DESCENDANT
of C = F, G
Node at the top is called as root..
Nodes that do not have children are
called leaf.
Nodes that have the same parent are
called sibling.
Degree of
node is the total sub tree of the node.
Height/Depth
is
the maximum degree of nodes in a tree.
If there is a line that connects p
to q, then p is called the ancestor of
q, and q is a descendant of
p.
Binary Tree Concept
is a rooted tree data structure in
which each node has at most two children.
•Those two children usually
distinguished as left child and right child.
•Node which doesn’t have any child
is called leaf.
Type of Binary Tree
•PERFECT
binary tree is a
binary tree in which every level are at the same depth.A perfect binary tree is a complete binary tree.
•COMPLETE
binary tree is a
binary tree in which every level, except possibly the last, is completely
filled, and all nodes are as far left as possible.
•SKEWED
binary tree is a
binary tree in which each node has at most one child.
•BALANCED
binary tree is a
binary tree in which no leaf is much farther away from the root than any other
leaf (different balancing scheme allows different definitions of “much
farther”).
Property of Binary Tree
Maximum
number of nodes on level k of a binary tree is 2k.
Maximum number of nodes on a binary
tree of height h is 2h+1 - 1.
Binary Tree Using Linked List
struct
node {
int data;
struct node *left;
struct node *right;
struct node *parent;
}root=NULL;
Expression Tree Concept
Prefix : *+ab/-cde
Postfix :
ab+cd-e/*
Infix :
(a+b)*((c-d)/e)
2101702130 - Andrean
Komentar
Posting Komentar