0% found this document useful (0 votes)
2 views

tree

The document provides an overview of binary trees, including definitions and characteristics of strictly binary trees, complete binary trees, and binary search trees. It also discusses tree traversal methods, spanning trees, minimum spanning trees, and AVL trees, highlighting their properties and balancing techniques. Additionally, examples of constructing AVL trees with various elements are included.

Uploaded by

saikatpaulprint
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

tree

The document provides an overview of binary trees, including definitions and characteristics of strictly binary trees, complete binary trees, and binary search trees. It also discusses tree traversal methods, spanning trees, minimum spanning trees, and AVL trees, highlighting their properties and balancing techniques. Additionally, examples of constructing AVL trees with various elements are included.

Uploaded by

saikatpaulprint
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

BINARY TREE

A binary tree is a tree data structure.


In a binary tree, any node in the tree can have at most two children.
BINARY TREE
Node
Edge
Root
Path
Children
Parent
Sibling
Subtree
Leaf node
level
Height
STRICTLY BINARY TREE
If in a tree, non-leaf nodes have exactly two children then that tree is called strictly
binary tree.
In strictly binary tree, every leaf nodes have degree 0 and every non-leaf nodes have
degree 2.
A strictly binary tree with n leaf nodes has (2n − 1) total number of nodes.
Thus, strictly binary tree always have odd number of nodes.
COMPLETE BINARY TREE
A complete binary tree is a type of binary tree in which every level, except possibly
the last, is fully filled, and all nodes are as far left as possible.
ARRAY REPRESENTATION OF BINARY TREE
BINARY SEARCH TREE
Binary search tree is a node-based binary tree data structure with the following
properties:
The left subtree contains the nodes with keys less than the node’s key.
The right subtree contains the nodes with keys greater than the node’s key.
Both the right and left subtree should also be binary search tree.
There should not be any duplicate nodes.
TREE TRAVERSAL IN BINARY SEARCH TREE
Pre order: (Root - Left - Right)
Post order: (Left - Right - Root)
In order: (Left - Root - Right)
TREE TRAVERSAL IN BINARY SEARCH TREE
Consider the given tree and find the in-order, pre-order and post-order of the tree.
TREE TRAVERSAL IN BINARY SEARCH TREE
Consider the given tree and find the in-order, pre-order and post-order of the tree.
TREE TRAVERSAL IN BINARY SEARCH TREE
Consider the given tree and find the in-order, pre-order and post-order of the tree.
Consider the following traversals of the tree.
Inorder = {2, 5, 6, 10, 12, 14, 15}
Preorder = {10, 5, 2, 6, 14, 12, 15}
Consider the following traversals of the tree.
Consider the following traversals of the tree.
Consider the following traversals of the tree.
Spanning Tree
A spanning tree of a graph G is a tree which contains all the vertices
of the graph G.
Minimum Spanning Tree
Minimum spanning tree in an undirected connected weighted graph is
a spanning tree with minimum weight.

Example: Prim’s Algorithm


Minimum Spanning Tree
Minimum Spanning Tree
AVL TREE
An AVL Tree is a self-balancing binary search tree (BST) where the
difference in heights between the left and right subtrees of any node
(known as the balance factor) is no more than 1.
If at any point the balance factor becomes greater than 1 or less than -1
due to insertion or deletion of nodes, the tree is rebalanced using
specific tree rotations.
The four possible rotations used to maintain balance are: Left Rotation
(LL), Right Rotation (RR), Left-Right Rotation (LR) and Right-Left Rotation
(RL)
AVL TREE
INSERT THE ELEMENTS 30, 20, 40, 10, 25, 50 TO CONSTRUCT AND AVL TREE.
AVL TREE
INSERT THE ELEMENTS 21,26,30,9,4,14,28 TO CONSTRUCT AND AVL TREE.
AVL TREE
INSERT THE ELEMENTS 21,26,30,9,4,14,28, 18, 15, 10, 2, 3, 7 TO CONSTRUCT AND
AVL TREE.
AVL TREE
INSERT THE ELEMENTS JAN, FEB, MAR, APR, MAY, JUNE, JULY, AUG, SEP, OCT,
NOV, DEC TO CONSTRUCT AND AVL TREE.

You might also like