SAS Day23 ITE048 Discrete Structure
SAS Day23 ITE048 Discrete Structure
A. LESSON PREVIEW/REVIEW
1) Introduction (2 mins)
On the previous lesson try to recall some of the important key notes of the lesson.
In this course, a very popular tree will be discussed and presented. There are many trees with
different algorithms. Binary tree is one of these trees. Before you continue with the lesson
proper, please consider Activity 1 and accomplish what is needed. So let’s get started.
B. MAIN LESSON
BINARY TREE
Binary trees are among the most important special types of rooted trees. Every vertex in a
binary tree has at most two children. Moreover, each child is designated as either a left child or
right child. When a binary tree is drawn, a left child is drawn to the left and right child is drawn to
the right.
A binary tree is a rooted tree in which each vertex has no children, one child or two children. If
a vertex has one child, that child is designated as either a left child or a right child.
A full binary tree is a binary tree in which each vertex has two or no children.
Basic Terminology:
1. Root: A binary tree has a unique node called the root of the tree.
2. Left Child: The node to the left of the root is called its left child.
3. Right Child: The node to the right of the root is called its right child.
4. Parent: A node having a left child or right child or both are called the parent of the nodes.
5. Siblings: Two nodes having the same parent are called siblings.
6. Leaf: A node with no children is called a leaf. The number of leaves in a binary tree can
vary from one (minimum) to half the number of vertices (maximum) in a tree.
7. Descendant: A node is called descendant of another node if it is the child of the node or
child of some other descendant of that node. All the nodes in the tree are descendants of
the root.
8. Left Subtree: The subtree whose root is the left child of some node is called the left
subtree of that node.
Example: For the tree as shown in fig:
• Which node is the root?
• Which nodes are leaves?
• Name the parent node of each node
Right Subtree: The subtree whose root is the right child of some node is called the right
subtree of that node.
Level of a Node: The level of a node is its distance from the root. The level of root is defined
as zero. The level of all other nodes is one more than its parent node. The maximum number
of nodes at any level N is 2N.
Depth or Height of a tree: The depth or height of a tree is defined as the maximum number
of nodes in a branch of a tree. This is more than the maximum level of the tree, i.e., the depth
of root is one. The maximum number of nodes in a binary tree of depth d is 2d-1, where d ≥1.
External Nodes: The nodes which have no children are called external nodes or terminal
nodes.
Internal Nodes: The nodes which have one or more than one children are called internal
nodes or non-terminal nodes.
Binary Expression Trees:
An algebraic expression can be conveniently expressed by its expression tree. An expression
having binary operators can be decomposed into
<left operand or expression> (operator) <right operand or expression>
Depending upon precedence of evaluation.
Binary search trees are useful in locating data. In general, there will be many ways to place
I. Instruction: Draw the unique binary tree for the given Inorder and Postorder traversal
is given as follows:
I. Instruction: Convert the following tree as shown in fig into a binary tree.
Draw here:
C. LESSON WRAP-UP
FAQs
1. What are the different types of trees aside from binary tree?
ANSWER:
• B-tree • Self-balancing tree
• Binary search tree • Splay tree
• AA tree • Heap, Binary heap, Binomial heap,
Fibonacci heap
• AVL tree • tree, R* tree, R+ tree, Hilbert R-tree
• Red–black tree • Trie, Hash tree
Mark the place in the work tracker which is simply a visual to help you track how much
work you have accomplished and how much work there is left to do. This tracker will be
part of your activity sheet.
To develop habits on thinking about learning, answer the questions below about
your learningexperience.
KEY CORRECTIONS
Answer Skill Building Activities
Solution: We know that the root of the binary tree is the last node in
the postorder traversal. Hence, one in the root node.
Now, check the inorder traversal, we know that root is at the center,
hence all the nodes that are left to the root node in inorder traversal
are the nodes of left subtree and, all that are right to the root node
are the nodes of the right subtree.
Now, visit the next node from back in postorder traversal and
check its position in inorder traversal, if it is on the left of root then
draw it as left child and if it is on the right, then draw it as the right
child.
Repeat the above process for each new node, and we obtain the
binary tree as shown in fig: