SlideShare a Scribd company logo
BINARY SEARCH TREE
( USING ARRAY AND LINKED LIST)
REPRESENTED BY :-
AYESHA NADEEM
MAHNOOR JABBAR
UNAIZA MATLOOB
TEHREEM IQBAL
BINARY TREE :-
A data structure where each node has at most two children…
Array Representation of Binary tree:-
• Start from root index..
• Filling array level by level..
• From left to right..
INDEX MAPPING:-
• The root is at index is ‘0’.
• For a node at index ‘I’.
a.Left child at index ( 2i +1)
b.Right child at index (2i+2)
c.Parent is at index (i- ½)
BINARY TREES USING LINKED LIST
• REPRESENTATION OF BINARY TREE IN MEMORY :
BINARY TREE WILL MAINTAIN IN MEMORY BY LINKED REPRESENTATION USING
THREE PARALLEL ARRAYS..
1. INFO (CONTAIN DATA OF NODE )
2. LEFT (CONTAIN LOCATION OF LEFT SIDE)
3. RIGHT (CONTAIN LOCATION OF RIGHT SIDE)
4. ROOT (CONTAIN LOCATION OF ROOT ELEMENT )
LEFT INFO RIGHT
BINARY SEARCH TREE.pptx all about trees how hey grow
INSERTION IN BINARY SEARCH TREE :-
Definition:-
“ Insertion in a binary search tree is the process of adding a new node to
the tree while maintaining the BST property..”
• A new key is always inserted at the leaf by maintaining the property of the
binary search tree . We start searching for a key from the root until we hit a
leaf node . Once a leaf node is identified , the new node is added as a child of
the leaf node.
• Types :
i. Inserting a leaf node : New nodes are inserted as leaf nodes…
ii. Inserting an internal node : A new node can be inserted as an internal node..
STEPS FOR INSERTING A NODE :-
i. Initialize a current node with the root of the tree..
ii. Compare the value to be inserted with the node’ s element..
iii. If the new element is less than current element, the current node becomes the left child of
the parent and continue recursively to find the parent node for the new element ..
iv. If the new element is greater than the current element , the current node becomes the right
child of the parent and continue recursively ..
v. Insert the value at the leaf node or null position..
8
3
10
14
13
1 6
4 7
EXAMPLE1 EXAMPLE 2
DELETION IN BINARY SEARCH TREE:-
Definintion :
“ In a binary search tree , deletion involves removing a node while maintaining the BST
properties.. ”
CASES :-
• Node to be deleted has no children.
• Node to be deleted has one children.
• Node to be deleted has two children.
Types:-
In a Binary Search Tree (BST), there are three types of deletion:
1. Deletion of a leaf node: Removing a node with no children.
2. Deletion of a node with one child: Removing a node with either a left or right child.
3. Deletion of a node with two children: Removing a node with both left and right children.
STEPS FOR DELETING ANY NODE:-
Here are the steps for deletion in a Binary Search Tree (BST):
1. Search for the node to be deleted: Find the node with the given key.
2. Check the number of children: Determine if the node has zero, one, or two children.
3. Delete the node based on the number of children: - Zero children: Remove the node. -
One child: Replace the node with its child. - Two children: Find the in-order successor or
predecessor, and replace the node with it.
4. Rebalance the tree (if necessary): Ensure the BST properties are maintained after deletion.
H
25
40
21
35
15
37
10
5 20
3 6
13
Example:

More Related Content

PPTX
UNIT 2 TREES & GRAPH COMPLETE NOTES OF DATA STRUCTURE
PPTX
PPTX
Binary Search Tree
PDF
Binary tree
PPTX
9e28d06f-bae9-487e-8360-0e2c0a8c2972.pptx
PDF
B Tree, Introduction ,example,Splay tree
PPTX
Lec 10_Binary Search Tree in data structure and algorithm.pptx
PPTX
Trees in data structure
UNIT 2 TREES & GRAPH COMPLETE NOTES OF DATA STRUCTURE
Binary Search Tree
Binary tree
9e28d06f-bae9-487e-8360-0e2c0a8c2972.pptx
B Tree, Introduction ,example,Splay tree
Lec 10_Binary Search Tree in data structure and algorithm.pptx
Trees in data structure

Similar to BINARY SEARCH TREE.pptx all about trees how hey grow (20)

PDF
Trees second part in data structures with examples
PPTX
Binary search tree
PPTX
Binary tree
PPTX
4. Apply data structures such as arrays, linked lists, and trees as an abstra...
PPT
Binary trees
PPTX
Search tree,Tree and binary tree and heap tree
PPTX
VCE Unit 05.pptx
PPT
BINARY TREE REPRESENTATION.ppt
PPTX
Binary tree
PPTX
learn tree, linked list, queue, stack, and other algo
PPTX
Binary Search Tree (BST)
PPTX
Tree Data Structure in Advanced Data Structure
PPTX
lecture on introduction to Binary Search Tree
PPT
Introduction to data structure by anil dutt
PDF
Chapter 7 - Binary Search Tree in the context of DSA.pdf
PPTX
Unit 3 - Part 1_Threaded Binary Tree.pptx
PPTX
DOC-20220815-WA0027..pptx
PPTX
Binary Search Tree
Trees second part in data structures with examples
Binary search tree
Binary tree
4. Apply data structures such as arrays, linked lists, and trees as an abstra...
Binary trees
Search tree,Tree and binary tree and heap tree
VCE Unit 05.pptx
BINARY TREE REPRESENTATION.ppt
Binary tree
learn tree, linked list, queue, stack, and other algo
Binary Search Tree (BST)
Tree Data Structure in Advanced Data Structure
lecture on introduction to Binary Search Tree
Introduction to data structure by anil dutt
Chapter 7 - Binary Search Tree in the context of DSA.pdf
Unit 3 - Part 1_Threaded Binary Tree.pptx
DOC-20220815-WA0027..pptx
Binary Search Tree
Ad

Recently uploaded (20)

PPTX
Small Fleets, Big Change: Overcoming Obstacles in the Transition to MHD Elect...
PPTX
Zeem: Transition Your Fleet, Seamlessly by Margaret Boelter
PDF
RPL-ASDC PPT PROGRAM NSDC GOVT SKILLS INDIA
PDF
Volvo EC300D L EC300DL excavator weight Manuals.pdf
PDF
EC290C NL EC290CNL Volvo excavator specs.pdf
PPTX
Understanding Machine Learning with artificial intelligence.pptx
PDF
Presentation.pdf ...............gjtn....tdubsr..........
PDF
book-slidefsdljflsk fdslkfjslf sflgs.pdf
PDF
Life Cycle Analysis of Electric and Internal Combustion Engine Vehicles
PDF
Volvo EC290C NL EC290CNL Hydraulic Excavator Specs Manual.pdf
PPTX
Fire Fighting Unit IV industrial safety.pptx
PDF
harrier-ev-brochure___________________.pdf
PPTX
1. introduction-to-bvcjdhjdfffffffffffffffffffffffffffffffffffmicroprocessors...
PPTX
UNIT-2(B) Organisavtional Appraisal.pptx
PPTX
laws of thermodynamics with diagrams details
PPTX
capstoneoooooooooooooooooooooooooooooooooo
PDF
How Much does a Volvo EC290C NL EC290CNL Weight.pdf
PPTX
Culture by Design.pptxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PDF
EC290C NL EC290CNL - Volvo Service Repair Manual.pdf
PDF
Caterpillar CAT 311B EXCAVATOR (8GR00001-UP) Operation and Maintenance Manual...
Small Fleets, Big Change: Overcoming Obstacles in the Transition to MHD Elect...
Zeem: Transition Your Fleet, Seamlessly by Margaret Boelter
RPL-ASDC PPT PROGRAM NSDC GOVT SKILLS INDIA
Volvo EC300D L EC300DL excavator weight Manuals.pdf
EC290C NL EC290CNL Volvo excavator specs.pdf
Understanding Machine Learning with artificial intelligence.pptx
Presentation.pdf ...............gjtn....tdubsr..........
book-slidefsdljflsk fdslkfjslf sflgs.pdf
Life Cycle Analysis of Electric and Internal Combustion Engine Vehicles
Volvo EC290C NL EC290CNL Hydraulic Excavator Specs Manual.pdf
Fire Fighting Unit IV industrial safety.pptx
harrier-ev-brochure___________________.pdf
1. introduction-to-bvcjdhjdfffffffffffffffffffffffffffffffffffmicroprocessors...
UNIT-2(B) Organisavtional Appraisal.pptx
laws of thermodynamics with diagrams details
capstoneoooooooooooooooooooooooooooooooooo
How Much does a Volvo EC290C NL EC290CNL Weight.pdf
Culture by Design.pptxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
EC290C NL EC290CNL - Volvo Service Repair Manual.pdf
Caterpillar CAT 311B EXCAVATOR (8GR00001-UP) Operation and Maintenance Manual...
Ad

BINARY SEARCH TREE.pptx all about trees how hey grow

  • 1. BINARY SEARCH TREE ( USING ARRAY AND LINKED LIST) REPRESENTED BY :- AYESHA NADEEM MAHNOOR JABBAR UNAIZA MATLOOB TEHREEM IQBAL
  • 2. BINARY TREE :- A data structure where each node has at most two children… Array Representation of Binary tree:- • Start from root index.. • Filling array level by level.. • From left to right..
  • 3. INDEX MAPPING:- • The root is at index is ‘0’. • For a node at index ‘I’. a.Left child at index ( 2i +1) b.Right child at index (2i+2) c.Parent is at index (i- ½)
  • 4. BINARY TREES USING LINKED LIST • REPRESENTATION OF BINARY TREE IN MEMORY : BINARY TREE WILL MAINTAIN IN MEMORY BY LINKED REPRESENTATION USING THREE PARALLEL ARRAYS.. 1. INFO (CONTAIN DATA OF NODE ) 2. LEFT (CONTAIN LOCATION OF LEFT SIDE) 3. RIGHT (CONTAIN LOCATION OF RIGHT SIDE) 4. ROOT (CONTAIN LOCATION OF ROOT ELEMENT ) LEFT INFO RIGHT
  • 6. INSERTION IN BINARY SEARCH TREE :- Definition:- “ Insertion in a binary search tree is the process of adding a new node to the tree while maintaining the BST property..” • A new key is always inserted at the leaf by maintaining the property of the binary search tree . We start searching for a key from the root until we hit a leaf node . Once a leaf node is identified , the new node is added as a child of the leaf node. • Types : i. Inserting a leaf node : New nodes are inserted as leaf nodes… ii. Inserting an internal node : A new node can be inserted as an internal node..
  • 7. STEPS FOR INSERTING A NODE :- i. Initialize a current node with the root of the tree.. ii. Compare the value to be inserted with the node’ s element.. iii. If the new element is less than current element, the current node becomes the left child of the parent and continue recursively to find the parent node for the new element .. iv. If the new element is greater than the current element , the current node becomes the right child of the parent and continue recursively .. v. Insert the value at the leaf node or null position.. 8 3 10 14 13 1 6 4 7
  • 9. DELETION IN BINARY SEARCH TREE:- Definintion : “ In a binary search tree , deletion involves removing a node while maintaining the BST properties.. ” CASES :- • Node to be deleted has no children. • Node to be deleted has one children. • Node to be deleted has two children. Types:- In a Binary Search Tree (BST), there are three types of deletion: 1. Deletion of a leaf node: Removing a node with no children. 2. Deletion of a node with one child: Removing a node with either a left or right child. 3. Deletion of a node with two children: Removing a node with both left and right children.
  • 10. STEPS FOR DELETING ANY NODE:- Here are the steps for deletion in a Binary Search Tree (BST): 1. Search for the node to be deleted: Find the node with the given key. 2. Check the number of children: Determine if the node has zero, one, or two children. 3. Delete the node based on the number of children: - Zero children: Remove the node. - One child: Replace the node with its child. - Two children: Find the in-order successor or predecessor, and replace the node with it. 4. Rebalance the tree (if necessary): Ensure the BST properties are maintained after deletion.