SlideShare a Scribd company logo
CS1301 Data Structures
Unit III Non LINEAR DATA STRUCTURE
 Preliminaries
 Binary Tree
 The Search Tree ADT
 Binary Search Tree
 AVL Tree
 Tree Traversals
 Hashing - General Idea
 Hash Function
 Separate Chaining
 OpenAddressing
 Linear Probing
 Priority Queue (Heaps) - Model - Simple Implementations
 Binary Heap
Trees
• Finite set of one or more nodes that there is a
specially designated node called root and zero or
more non empty sub trees T1, T2,.. each of whose
roots are connected by a directed edge from Root
R
• A tree T is a set of nodes storing elements such
that the nodes have a parent-child relationship
that satisfies the following
– if T is not empty, T has a special tree called the root
that has no parent
– each node v of T different than the root has a unique
parent node w; each node with parent w is a child of w
Trees
Trees
• Root : node which doesn’t have a parent
• Node : Item of information
• Leaf/ terminal : node which doesn’t have children
• Siblings : children of same parents
• Path : sequence of nodes n1,n2,n3,….,nk such
that ni is parent of ni+1 for 1<= i<k. there is
exactly only one path from each node to root;
path from A to L is A,C,F,L
• Length : no. of edges on the path ; length of A to
L is 3
• Degree : number of subtrees of a node; A -> 4, C-
>2 degree of tree is maximum no.of any node in
the tree ; degree of tree is 4
Trees
• Level : initially letting the root be at level one,
if a node is at level L then its children are at
level L + 1
– Level of A is 1; Level of B, C, D is 2; Level of
F,G,H,I,J is 3, Level of K,L,M is 4
• Depth : For any node n, the depth of n is the
unique path from root to n
– Depth of root is 0; Depth of L is 3
• Height : For any node n, the height of the node
is the length of the longest path from n to the
leaf
CHAPTER 5 7
Level and Depth
K L
E F
B
G
C
M
H I J
D
A
Level
1
2
3
4
node (13)
degree of a node
leaf (terminal)
nonterminal
parent
children
sibling
degree of a tree (3)
ancestor
level of a node
3
2 1 3
2 0 0 1 0 0
0 0 0
1
2 2 2
3 3 3 3 3 3
4 4 4
Trees
• Binary Tree
–Tree in which no node can have more
than two children
Trees
• Binary Tree Node Declaration
Struct Treenode
{
int element;
Struct Treenode *Left;
Struct TreeNode *Right;
};
Trees
• Binary Tree
–Comparison between general tree &
Binary Tree
General Tree Binary Tree
Has any no. of children Has not more than two
children
Trees
• Full Binary Tree
– Full binary tree of h has 2^h+1 -1 nodes
Trees
• Complete Binary Tree
– A complete binary tree is a binary tree, which is
completely filled, with the possible exception of
the bottom level, which is filled from left to right
– A full binary tree can be a complete binary tree,
but all complete binary tree is not a full binary tree
Trees
• Representation of Binary Tree
–Two ways
• Linear Representation
• Linked Representation
Trees
• Linear Representation of Binary
Tree
– Elements are represented using arrays
– For any element in position i, the left child is in
position 2i, right child is in position (2i+1) and
parent in position (i/2)
Trees
• Linked Representation of Binary
Tree
– Elements are represented using pointers
– Each node in linked representation has two fields
• Pointer to left subtree
• Data field
• Pointer to right subtree
– In leaf node, both pointer fields are assigned as
NULL
Trees
• Expression Tree
– Is a binary tree
– Leaf nodes are operands and interior nodes are
operators
– Expression tree be traversed by inorder , preorder,
postorder traversal
Trees
• Constructing an Expression Tree
1. Read one symbol at a time from postfix
expression
2. Check whether symbol is an operand or
operator
1. If operand, create a one –node tree and
push a pointer on to the stack
2. If operator, pop two pointers from the
stack namely T1 and T2 and form a new
tree with root as the operator and T2 as a
left child and T1 as a right child. A
pointer to this new tree is pushed onto the
stack
Trees
• Example
Trees
• Example
Trees
• Binary Search Tree
–Is a binary tree
–For every node x in the tree, value of all
the keys in its left subtree are smaller than
the value X and value of all the keys in the
right subtree are larger than the value X
Trees
• Binary Search Tree
–Every binary search tree is a binary tree
–All binary tree need not be bnary
search tree
Trees
• Declaration Routine for Binary Search
Tree
Trees
• Routine for Make an empty tree
Trees
• Insertion
Trees
• Insertion - Example
Trees
• Insertion - Example
Trees
• Routine for Insertion
Trees
• Find
Trees
• Find – Example to find 10
Trees
• Find – Example to find 10
Trees
• Routine for Find
Trees
• Find Minimum
–Returns position of the smallest element in
a tree
–Start at the root and go left as long as there
is a left child, the stopping point will be
the smallest element
Trees
• Find Minimum – example
Trees
• Find Minimum – Recursive routine
Trees
• Find Minimum – Non Recursive
routine
Trees
• Find Maximum
–Returns the largest element in the tree
–To perform, start at the root and go right as
long as there is a right child
–Stopping point is the largest element
Trees
• Find Maximum - Example
Trees
• Find Maximum – Recursive Routine
Trees
• Find Maximum – Non Recursive
Routine
Trees
• Deletion
–Complex in BST
–To delete an element, consider the
following 3 possibilities
• Node to be deleted is a leaf node
• Node with one child
• Node with two children
Trees
• Deletion
– Node to be deleted is a leaf node
Trees
• Deletion
• Node with one child : deleted by adjusting its
parent pointer that points to its child node
Trees
• Deletion
• Node with two children : to replace the data of
node to be deleted with its smallest data of right subtree
and recursively delete that node
Trees
• Deletion
• Node with two children
Trees
• Deletion
• Node with two children
Trees
• Deletion
• Node with two children
Trees
• Deletion
• Node with two children
Trees
• Deletion
• Node with two children
Trees
• Deletion
• Node with two children
Trees
• Deletion Routine
Trees
• Deletion Routine
Trees
• AVL Tree (Adelson - Velskill and
Landis)
–Binary search tree except that for every
node in the tree, the height of left and right
subtrees can differ by atmost 1
–Balance factor is the height of left subtree
minus height of right subtree; -1, 0, or +1
–If Balance factor is less than or greater than
1, the tree has to be balanced by making
single or double rotations
Trees
• AVL Tree (Adelson Velskill and
Landis)
Trees
• AVL Tree (Adelson Velskill and
Landis)
Trees
• AVL Tree (Adelson Velskill and Landis)
– AVL tree causes imbalance, when anyone of the
following conditions occur
• An insertion into the left subtree of the left child of
node
• An insertion into the right subtree of the left child
of node
• An insertion into the left subtree of the right child
of node
• An insertion into the right subtree of the right
child of node
Imbalances can overcome by
1. Single rotation
2. Double rotation
Trees
• AVL Tree (Adelson Velskill and
Landis)
• Single rotation
– Performed to fix case1 and case 4
Case 1: An insertion into the left subtree of the left
child of node
Trees
• AVL Tree (Adelson Velskill and
Landis)
• Single rotation
– Performed to fix case1 and case 4
Case 1: An insertion into the left subtree of the left
child of node

More Related Content

What's hot

Discrete Mathematics Tree
Discrete Mathematics  TreeDiscrete Mathematics  Tree
Discrete Mathematics Tree
Masud Parvaze
 
Tree
TreeTree
Trees data structure
Trees data structureTrees data structure
Trees data structure
Sumit Gupta
 
Tree (Data Structure & Discrete Mathematics)
Tree (Data Structure & Discrete Mathematics)Tree (Data Structure & Discrete Mathematics)
Tree (Data Structure & Discrete Mathematics)
Daffodil International University
 
Tree
TreeTree
Tree data structure
Tree data structureTree data structure
Tree data structure
Lovely Professional University
 
Tree(Directed and undirected tree)
Tree(Directed and undirected tree)Tree(Directed and undirected tree)
Tree(Directed and undirected tree)
Mahmoud Hikmet
 
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
sumitbardhan
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
shameen khan
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
Mahmoud Alfarra
 
Trees
TreesTrees
Trees
Ali Saleem
 
Trees
TreesTrees
Data Structure: TREES
Data Structure: TREESData Structure: TREES
Data Structure: TREES
TABISH HAMID
 
Binary tree
Binary treeBinary tree
Binary tree
Rajendran
 
Binary tree
Binary treeBinary tree
Binary tree
MKalpanaDevi
 

What's hot (19)

Trees
TreesTrees
Trees
 
Discrete Mathematics Tree
Discrete Mathematics  TreeDiscrete Mathematics  Tree
Discrete Mathematics Tree
 
Tree
TreeTree
Tree
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Tree (Data Structure & Discrete Mathematics)
Tree (Data Structure & Discrete Mathematics)Tree (Data Structure & Discrete Mathematics)
Tree (Data Structure & Discrete Mathematics)
 
Tree
TreeTree
Tree
 
Tree data structure
Tree data structureTree data structure
Tree data structure
 
Lecture 5 trees
Lecture 5 treesLecture 5 trees
Lecture 5 trees
 
Tree(Directed and undirected tree)
Tree(Directed and undirected tree)Tree(Directed and undirected tree)
Tree(Directed and undirected tree)
 
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Trees
TreesTrees
Trees
 
Binary tree
Binary treeBinary tree
Binary tree
 
Trees
TreesTrees
Trees
 
Data Structure: TREES
Data Structure: TREESData Structure: TREES
Data Structure: TREES
 
Binary tree
Binary treeBinary tree
Binary tree
 
Binary trees
Binary treesBinary trees
Binary trees
 
Binary tree
Binary treeBinary tree
Binary tree
 

Viewers also liked

BinarySearchTree-bddicken
BinarySearchTree-bddickenBinarySearchTree-bddicken
BinarySearchTree-bddicken
Benjamin Dicken
 
Lecture 9 data structures and algorithms
Lecture 9 data structures and algorithmsLecture 9 data structures and algorithms
Lecture 9 data structures and algorithmsAakash deep Singhal
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
Krish_ver2
 
Introduction to Data structure & Algorithms - Sethuonline.com | Sathyabama Un...
Introduction to Data structure & Algorithms - Sethuonline.com | Sathyabama Un...Introduction to Data structure & Algorithms - Sethuonline.com | Sathyabama Un...
Introduction to Data structure & Algorithms - Sethuonline.com | Sathyabama Un...
sethuraman R
 
Tree and binary tree
Tree and binary treeTree and binary tree
Tree and binary tree
Zaid Shabbir
 
Binary expression tree
Binary expression treeBinary expression tree
Binary expression tree
Shab Bi
 

Viewers also liked (7)

BinarySearchTree-bddicken
BinarySearchTree-bddickenBinarySearchTree-bddicken
BinarySearchTree-bddicken
 
Lecture 9 data structures and algorithms
Lecture 9 data structures and algorithmsLecture 9 data structures and algorithms
Lecture 9 data structures and algorithms
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
 
Introduction to Data structure & Algorithms - Sethuonline.com | Sathyabama Un...
Introduction to Data structure & Algorithms - Sethuonline.com | Sathyabama Un...Introduction to Data structure & Algorithms - Sethuonline.com | Sathyabama Un...
Introduction to Data structure & Algorithms - Sethuonline.com | Sathyabama Un...
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Tree and binary tree
Tree and binary treeTree and binary tree
Tree and binary tree
 
Binary expression tree
Binary expression treeBinary expression tree
Binary expression tree
 

Similar to Data structures 3

Module - 5_Trees.pdf
Module - 5_Trees.pdfModule - 5_Trees.pdf
Module - 5_Trees.pdf
AnuradhaJadiya1
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
worldchannel
 
TERMINOLOGIES OF TREE, TYPES OF TREE.pptx
TERMINOLOGIES OF TREE, TYPES OF TREE.pptxTERMINOLOGIES OF TREE, TYPES OF TREE.pptx
TERMINOLOGIES OF TREE, TYPES OF TREE.pptx
KALPANAC20
 
Tree Basic concepts of Tree in Data Structure
Tree Basic concepts of Tree in Data StructureTree Basic concepts of Tree in Data Structure
Tree Basic concepts of Tree in Data Structure
Manoj PAtil
 
TREES34.pptx
TREES34.pptxTREES34.pptx
TREES34.pptx
BharathChalla5
 
Tree
TreeTree
358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10
sumitbardhan
 
Unit 5 Tree.pptx
Unit 5 Tree.pptxUnit 5 Tree.pptx
Unit 5 Tree.pptx
SurajSharma266169
 
Farhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructure
Farhana Shaikh
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
SeethaDinesh
 
unit 4 for trees data structure notes it is
unit 4 for trees data structure notes it isunit 4 for trees data structure notes it is
unit 4 for trees data structure notes it is
logesswarisrinivasan
 
Search tree,Tree and binary tree and heap tree
Search tree,Tree  and binary tree and heap treeSearch tree,Tree  and binary tree and heap tree
Search tree,Tree and binary tree and heap tree
zia eagle
 
BINARY SEARCH TREE
BINARY SEARCH TREEBINARY SEARCH TREE
BINARY SEARCH TREE
ER Punit Jain
 
Lecture 9: Binary tree basics
Lecture 9: Binary tree basicsLecture 9: Binary tree basics
Lecture 9: Binary tree basics
Vivek Bhargav
 
Tree
TreeTree
Tree
sbkbca
 
Final tree.ppt tells about tree presentation
Final tree.ppt tells about tree presentationFinal tree.ppt tells about tree presentation
Final tree.ppt tells about tree presentation
nakulvarshney371
 
Unit 6 tree
Unit   6 treeUnit   6 tree
Unit 6 tree
Dabbal Singh Mahara
 
Lecture 5 tree.pptx
Lecture 5 tree.pptxLecture 5 tree.pptx
Lecture 5 tree.pptx
Abirami A
 

Similar to Data structures 3 (20)

Module - 5_Trees.pdf
Module - 5_Trees.pdfModule - 5_Trees.pdf
Module - 5_Trees.pdf
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
 
TERMINOLOGIES OF TREE, TYPES OF TREE.pptx
TERMINOLOGIES OF TREE, TYPES OF TREE.pptxTERMINOLOGIES OF TREE, TYPES OF TREE.pptx
TERMINOLOGIES OF TREE, TYPES OF TREE.pptx
 
Tree Basic concepts of Tree in Data Structure
Tree Basic concepts of Tree in Data StructureTree Basic concepts of Tree in Data Structure
Tree Basic concepts of Tree in Data Structure
 
TREES34.pptx
TREES34.pptxTREES34.pptx
TREES34.pptx
 
Tree
TreeTree
Tree
 
358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10
 
Unit 5 Tree.pptx
Unit 5 Tree.pptxUnit 5 Tree.pptx
Unit 5 Tree.pptx
 
Tree 11.ppt
Tree 11.pptTree 11.ppt
Tree 11.ppt
 
Unit III.ppt
Unit III.pptUnit III.ppt
Unit III.ppt
 
Farhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructure
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
unit 4 for trees data structure notes it is
unit 4 for trees data structure notes it isunit 4 for trees data structure notes it is
unit 4 for trees data structure notes it is
 
Search tree,Tree and binary tree and heap tree
Search tree,Tree  and binary tree and heap treeSearch tree,Tree  and binary tree and heap tree
Search tree,Tree and binary tree and heap tree
 
BINARY SEARCH TREE
BINARY SEARCH TREEBINARY SEARCH TREE
BINARY SEARCH TREE
 
Lecture 9: Binary tree basics
Lecture 9: Binary tree basicsLecture 9: Binary tree basics
Lecture 9: Binary tree basics
 
Tree
TreeTree
Tree
 
Final tree.ppt tells about tree presentation
Final tree.ppt tells about tree presentationFinal tree.ppt tells about tree presentation
Final tree.ppt tells about tree presentation
 
Unit 6 tree
Unit   6 treeUnit   6 tree
Unit 6 tree
 
Lecture 5 tree.pptx
Lecture 5 tree.pptxLecture 5 tree.pptx
Lecture 5 tree.pptx
 

More from Parthipan Parthi

Inheritance
Inheritance Inheritance
Inheritance
Parthipan Parthi
 
Switch statement mcq
Switch statement  mcqSwitch statement  mcq
Switch statement mcq
Parthipan Parthi
 
Oprerator overloading
Oprerator overloadingOprerator overloading
Oprerator overloading
Parthipan Parthi
 
802.11 mac
802.11 mac802.11 mac
802.11 mac
Parthipan Parthi
 
Ieee 802.11 wireless lan
Ieee 802.11 wireless lanIeee 802.11 wireless lan
Ieee 802.11 wireless lan
Parthipan Parthi
 
Computer network
Computer networkComputer network
Computer network
Parthipan Parthi
 
Ieee 802.11 wireless lan
Ieee 802.11 wireless lanIeee 802.11 wireless lan
Ieee 802.11 wireless lan
Parthipan Parthi
 
Session 6
Session 6Session 6
Session 6
Parthipan Parthi
 
Queuing analysis
Queuing analysisQueuing analysis
Queuing analysis
Parthipan Parthi
 
WAP
WAPWAP
Alternative metrics
Alternative metricsAlternative metrics
Alternative metrics
Parthipan Parthi
 
Ieee 802.11 wireless lan
Ieee 802.11 wireless lanIeee 802.11 wireless lan
Ieee 802.11 wireless lan
Parthipan Parthi
 
Io stream
Io streamIo stream
Io stream
Parthipan Parthi
 
Dbms lab questions
Dbms lab questionsDbms lab questions
Dbms lab questions
Parthipan Parthi
 
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3 REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3
Parthipan Parthi
 

More from Parthipan Parthi (20)

Inheritance
Inheritance Inheritance
Inheritance
 
Switch statement mcq
Switch statement  mcqSwitch statement  mcq
Switch statement mcq
 
Oprerator overloading
Oprerator overloadingOprerator overloading
Oprerator overloading
 
802.11 mac
802.11 mac802.11 mac
802.11 mac
 
Ieee 802.11 wireless lan
Ieee 802.11 wireless lanIeee 802.11 wireless lan
Ieee 802.11 wireless lan
 
Computer network
Computer networkComputer network
Computer network
 
Ieee 802.11 wireless lan
Ieee 802.11 wireless lanIeee 802.11 wireless lan
Ieee 802.11 wireless lan
 
Session 6
Session 6Session 6
Session 6
 
Queuing analysis
Queuing analysisQueuing analysis
Queuing analysis
 
WAP
WAPWAP
WAP
 
Alternative metrics
Alternative metricsAlternative metrics
Alternative metrics
 
Ethernet
EthernetEthernet
Ethernet
 
Ieee 802.11 wireless lan
Ieee 802.11 wireless lanIeee 802.11 wireless lan
Ieee 802.11 wireless lan
 
Data structures1
Data structures1Data structures1
Data structures1
 
Data structures 4
Data structures 4Data structures 4
Data structures 4
 
Data structures2
Data structures2Data structures2
Data structures2
 
Input output streams
Input output streamsInput output streams
Input output streams
 
Io stream
Io streamIo stream
Io stream
 
Dbms lab questions
Dbms lab questionsDbms lab questions
Dbms lab questions
 
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3 REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3
 

Recently uploaded

English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 

Recently uploaded (20)

English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 

Data structures 3

  • 2. Unit III Non LINEAR DATA STRUCTURE  Preliminaries  Binary Tree  The Search Tree ADT  Binary Search Tree  AVL Tree  Tree Traversals  Hashing - General Idea  Hash Function  Separate Chaining  OpenAddressing  Linear Probing  Priority Queue (Heaps) - Model - Simple Implementations  Binary Heap
  • 3. Trees • Finite set of one or more nodes that there is a specially designated node called root and zero or more non empty sub trees T1, T2,.. each of whose roots are connected by a directed edge from Root R • A tree T is a set of nodes storing elements such that the nodes have a parent-child relationship that satisfies the following – if T is not empty, T has a special tree called the root that has no parent – each node v of T different than the root has a unique parent node w; each node with parent w is a child of w
  • 5. Trees • Root : node which doesn’t have a parent • Node : Item of information • Leaf/ terminal : node which doesn’t have children • Siblings : children of same parents • Path : sequence of nodes n1,n2,n3,….,nk such that ni is parent of ni+1 for 1<= i<k. there is exactly only one path from each node to root; path from A to L is A,C,F,L • Length : no. of edges on the path ; length of A to L is 3 • Degree : number of subtrees of a node; A -> 4, C- >2 degree of tree is maximum no.of any node in the tree ; degree of tree is 4
  • 6. Trees • Level : initially letting the root be at level one, if a node is at level L then its children are at level L + 1 – Level of A is 1; Level of B, C, D is 2; Level of F,G,H,I,J is 3, Level of K,L,M is 4 • Depth : For any node n, the depth of n is the unique path from root to n – Depth of root is 0; Depth of L is 3 • Height : For any node n, the height of the node is the length of the longest path from n to the leaf
  • 7. CHAPTER 5 7 Level and Depth K L E F B G C M H I J D A Level 1 2 3 4 node (13) degree of a node leaf (terminal) nonterminal parent children sibling degree of a tree (3) ancestor level of a node 3 2 1 3 2 0 0 1 0 0 0 0 0 1 2 2 2 3 3 3 3 3 3 4 4 4
  • 8. Trees • Binary Tree –Tree in which no node can have more than two children
  • 9. Trees • Binary Tree Node Declaration Struct Treenode { int element; Struct Treenode *Left; Struct TreeNode *Right; };
  • 10. Trees • Binary Tree –Comparison between general tree & Binary Tree General Tree Binary Tree Has any no. of children Has not more than two children
  • 11. Trees • Full Binary Tree – Full binary tree of h has 2^h+1 -1 nodes
  • 12. Trees • Complete Binary Tree – A complete binary tree is a binary tree, which is completely filled, with the possible exception of the bottom level, which is filled from left to right – A full binary tree can be a complete binary tree, but all complete binary tree is not a full binary tree
  • 13. Trees • Representation of Binary Tree –Two ways • Linear Representation • Linked Representation
  • 14. Trees • Linear Representation of Binary Tree – Elements are represented using arrays – For any element in position i, the left child is in position 2i, right child is in position (2i+1) and parent in position (i/2)
  • 15. Trees • Linked Representation of Binary Tree – Elements are represented using pointers – Each node in linked representation has two fields • Pointer to left subtree • Data field • Pointer to right subtree – In leaf node, both pointer fields are assigned as NULL
  • 16. Trees • Expression Tree – Is a binary tree – Leaf nodes are operands and interior nodes are operators – Expression tree be traversed by inorder , preorder, postorder traversal
  • 17. Trees • Constructing an Expression Tree 1. Read one symbol at a time from postfix expression 2. Check whether symbol is an operand or operator 1. If operand, create a one –node tree and push a pointer on to the stack 2. If operator, pop two pointers from the stack namely T1 and T2 and form a new tree with root as the operator and T2 as a left child and T1 as a right child. A pointer to this new tree is pushed onto the stack
  • 20. Trees • Binary Search Tree –Is a binary tree –For every node x in the tree, value of all the keys in its left subtree are smaller than the value X and value of all the keys in the right subtree are larger than the value X
  • 21. Trees • Binary Search Tree –Every binary search tree is a binary tree –All binary tree need not be bnary search tree
  • 22. Trees • Declaration Routine for Binary Search Tree
  • 23. Trees • Routine for Make an empty tree
  • 29. Trees • Find – Example to find 10
  • 30. Trees • Find – Example to find 10
  • 32. Trees • Find Minimum –Returns position of the smallest element in a tree –Start at the root and go left as long as there is a left child, the stopping point will be the smallest element
  • 33. Trees • Find Minimum – example
  • 34. Trees • Find Minimum – Recursive routine
  • 35. Trees • Find Minimum – Non Recursive routine
  • 36. Trees • Find Maximum –Returns the largest element in the tree –To perform, start at the root and go right as long as there is a right child –Stopping point is the largest element
  • 38. Trees • Find Maximum – Recursive Routine
  • 39. Trees • Find Maximum – Non Recursive Routine
  • 40. Trees • Deletion –Complex in BST –To delete an element, consider the following 3 possibilities • Node to be deleted is a leaf node • Node with one child • Node with two children
  • 41. Trees • Deletion – Node to be deleted is a leaf node
  • 42. Trees • Deletion • Node with one child : deleted by adjusting its parent pointer that points to its child node
  • 43. Trees • Deletion • Node with two children : to replace the data of node to be deleted with its smallest data of right subtree and recursively delete that node
  • 44. Trees • Deletion • Node with two children
  • 45. Trees • Deletion • Node with two children
  • 46. Trees • Deletion • Node with two children
  • 47. Trees • Deletion • Node with two children
  • 48. Trees • Deletion • Node with two children
  • 49. Trees • Deletion • Node with two children
  • 52. Trees • AVL Tree (Adelson - Velskill and Landis) –Binary search tree except that for every node in the tree, the height of left and right subtrees can differ by atmost 1 –Balance factor is the height of left subtree minus height of right subtree; -1, 0, or +1 –If Balance factor is less than or greater than 1, the tree has to be balanced by making single or double rotations
  • 53. Trees • AVL Tree (Adelson Velskill and Landis)
  • 54. Trees • AVL Tree (Adelson Velskill and Landis)
  • 55. Trees • AVL Tree (Adelson Velskill and Landis) – AVL tree causes imbalance, when anyone of the following conditions occur • An insertion into the left subtree of the left child of node • An insertion into the right subtree of the left child of node • An insertion into the left subtree of the right child of node • An insertion into the right subtree of the right child of node Imbalances can overcome by 1. Single rotation 2. Double rotation
  • 56. Trees • AVL Tree (Adelson Velskill and Landis) • Single rotation – Performed to fix case1 and case 4 Case 1: An insertion into the left subtree of the left child of node
  • 57. Trees • AVL Tree (Adelson Velskill and Landis) • Single rotation – Performed to fix case1 and case 4 Case 1: An insertion into the left subtree of the left child of node