Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

TERMINOLOGY

1.> Leaf(External)(Terminal)Node:- It is a node which does not have any child nodes (eg.
D,E,F,G)

2.> Root Node :- It is the first (i.e topmost) node


It does not have any parent node
3.> Internal Node :- It is a node that has child nodes

4.> Sibling Node:- Nodes that appear from the same parent

5.>Indegree of a node No. of edges going into the node


Indegree of root =0
Tree cannot have node with Indegree>1
6.>Outdegree of a node No. of edges going out of the node
Outdegree of leaf =0
Tree cannot have node with Outdegree>2
7. Edge The connecting line between 2 nodes is called edge
8. Path Sequence of continous edges between 2 nodes

1. Size of Tree Total number of nodes in the tree


2. Depth of a Node (or Level of a Number of edges from root to that node
node) Depth of root=0
3. Height of a Node Number of edges from Node to the deepest leaf of it's subtree
Height of each Leaf =0
Height of Root = Height of tree = Depth of tree
4. Height of tree = Depth of tree Number of edges in the longest path from root to it's deepest leaf

Q1. What is a Binary Tree


A tree is called binary tree if each node has zero child, one child or two children (i.e each node has atmost 2
children)
Empty tree is also a valid binary tree.

Q2. What is a strict Binary Tree


A binary tree is called strict binary tree if each node has exactly two children or no children.

Q3. What is a Perfect Binary Tree


A binary tree is called perfect binary tree if each node has exactly two children and all leaf nodes are at the
same level.
Q4. What is a Full Binary Tree 
A Binary Tree is full if every node has 0 or 2 children.
We can also say a full binary tree is a binary tree in which all nodes except leaves have two children.
number of leaf nodes(L)= number of internal nodes(i)+ 1=> L=i+1

18
/ \
15 30
/ \ / \
40 50 100 40

18
/ \
15 20
/ \
40 50
/ \
30 50

Q4. i.> What is a Skewed Binary Tree


A skewed binary tree is a type of binary tree in which all the nodes have only either one child or no child.
ii.> Left Skewed Binary Tree
These are those skewed binary trees in which all the nodes are having a left child or no child at all.
It is a left sided dominated tree.
All the right children remain as null.
iii.> Right Skewed Binary Tree
These are those skewed binary trees in which all the nodes are having a right child or no child at all.
It is a right sided dominated tree.
All the left children remain as null.

Q5. What is a Complete Binary Tree:


 A Binary Tree is complete Binary Tree if all levels are completely filled except possibly the last level and the last
level has all keys as left as possible
Following are examples of Complete Binary Trees
18
/ \
15 30
/ \ / \
40 50 100 40

18
/ \
15 30
/ \ / \
40 50 100 40
/ \ /
8 7 9
Practical example of Complete Binary Tree is Binary Heap.

Q6. What is a Binary Search Tree 


Binary Tree is a node-based binary tree data structure which has the following properties:
 The left subtree of a node contains only nodes with keys(data) lesser than the node’s key.
 The right subtree of a node contains only nodes with keys(data) greater than the node’s key.
 The left and right subtree each must also be a binary search tree.
 There must be no duplicate nodes

Properties of Binary Trees

1) The maximum no. of nodes at level ‘h’ of a binary tree = Total no. of nodes at level 'h' of a perfect binary
tree=2h.
2) The maximum no of nodes (n) in a perfect binary tree = Total number of nodes (n) in a perfect binary
tree = 20+21+22+…….+2h = 2h+1-1
3) Max no. of leaves in a binary tree=Total number of leaves (l) in a perfect binary tree = 2 h
4) In Binary tree where every node has 0 or 2 children, number of leaf nodes(l) = 1+ nodes with two children(i).
5) In a Binary Tree with N nodes, minimum possible height or minimum number of levels is  ? Log2(N+1) ?  
Q7. How to determine if a binary tree is height-balanced?
Ans:- 1.> An empty tree is height-balanced.
2.> A non-empty binary tree T is balanced if:
1) Left subtree of T is balanced
2) Right subtree of T is balanced
3) The difference between heights of left subtree and right subtree is not more than 1. (i.e
balance factor is not more than 1)

The above height balancing scheme is used in AVL trees…….

Balance factor =Ht(left subtree) - Ht(right subtree)

Q7. AVL Tree (Basics):-


Ans:- 1. It is a height balanced binary tree where balance factor of each node is b/w -1 to +1 (i.e -1<= balance
factor <= 1)
2. Otherwise Tree is said to be unbalanced and needs to be balanced

Balance Factor = height (left subtree) - height (right subtree)


a. If balance factor of any node is 1, it means that the left sub-tree is one level higher than the right sub-
tree.
b. If balance factor of any node is 0, it means that the left sub-tree and right sub-tree contain equal
height.
c. If balance factor of any node is -1, it means that the left sub-tree is one level lower than the right sub-
tree.

Q1. QUEUE BASICS


:-

You might also like