SlideShare une entreprise Scribd logo
1  sur  16
Data Structure(Part 2)
BY:SURBHI SAROHA
Syllabus
• Trees
• Binary search trees
• Multidimensional arrays
Trees
• Trees: Unlike Arrays, Linked Lists, Stack and queues, which are linear
data structures, trees are hierarchical data structures.
• Tree Vocabulary: The topmost node is called root of the tree.
• The elements that are directly under an element are called its children.
• A tree is a nonlinear hierarchical data structure that consists of nodes
connected by edges.
• The element directly above something is called its parent.
• For example, ‘a’ is a child of ‘f’, and ‘f’ is the parent of ‘a’. Finally,
elements with no children are called leaves.
Example
• tree
• ----
• j <-- root
• / 
• f k
• /  
• a h z <-- leaves
Tree
Tree Terminologies
• Node
• A node is an entity that contains a key or value and pointers to its
child nodes.
• The last nodes of each path are called leaf nodes or external
nodes that do not contain a link/pointer to child nodes.
• The node having at least a child node is called an internal node.
• Edge
• It is the link between any two nodes.
Cont…
• Root
• It is the topmost node of a tree.
• Height of a Node
• The height of a node is the number of edges from the node to the
deepest leaf (ie. the longest path from the node to a leaf node).
• Depth of a Node
• The depth of a node is the number of edges from the root to the node.
• Height of a Tree
• The height of a Tree is the height of the root node or the depth of the
deepest node.
Cont….
• Degree of a Node
• The degree of a node is the total number of branches of that node.
• Forest
• A collection of disjoint trees is called a forest.
• Types of Tree
• Binary Tree
• Binary Search Tree
• AVL Tree
• B-Tree
Binary search trees
• Binary Search 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 lesser
than the node’s key.
• The right subtree of a node contains only nodes with keys greater
than the node’s key.
• The left and right subtree each must also be a binary search tree.
BST Tree
Cont…..
• A Binary Search Tree (BST) is a tree in which all the nodes follow the below-
mentioned properties −
• The value of the key of the left sub-tree is less than the value of its parent (root)
node's key.
• The value of the key of the right sub-tree is greater than or equal to the value of its
parent (root) node's key.
• Following are the basic operations of a tree −
• Search − Searches an element in a tree.
• Insert − Inserts an element in a tree.
• Pre-order Traversal − Traverses a tree in a pre-order manner.
• In-order Traversal − Traverses a tree in an in-order manner.
• Post-order Traversal − Traverses a tree in a post-order manner.
Node
• Define a node having some data, references to its left and right
child nodes.
• struct node {
• int data;
• struct node *leftChild;
• struct node *rightChild;
• };
Multidimensional arrays
• A multi-dimensional array is an array of arrays. 2-dimensional
arrays are the most commonly used. They are used to store data in
a tabular manner.
• Consider following 2D array, which is of the size 3×5. For an array
of size N×M, the rows and columns are numbered
from 0 to N−1 and columns are numbered from 0 to M−1,
respectively. Any element of the array can be accessed
by arr[i][j] where 0≤i<N and 0≤j<M. For example, in the following
array, the value stored at arr[1][3] is 14.
Cont…
• 2D array declaration:
• To declare a 2D array, you must specify the following:
• Row-size: Defines the number of rows
• Column-size: Defines the number of columns
• Type of array: Defines the type of elements to be stored in the
array i.e. either a number, character, or other such datatype. A
sample form of declaration is as follows:
• type arr[row_size][column_size]
Cont….
Thank you 

Contenu connexe

Tendances

Data mining – introduction
Data mining – introductionData mining – introduction
Data mining – introduction
Fiddy Prasetiya
 

Tendances (20)

Trees krw
Trees krwTrees krw
Trees krw
 
Bsc cs ii dfs u-3 tree and graph
Bsc cs  ii dfs u-3 tree and graphBsc cs  ii dfs u-3 tree and graph
Bsc cs ii dfs u-3 tree and graph
 
Search tree & graph
Search tree & graphSearch tree & graph
Search tree & graph
 
Basic of trees 2
Basic of trees 2Basic of trees 2
Basic of trees 2
 
Introduction to tree ds
Introduction to tree dsIntroduction to tree ds
Introduction to tree ds
 
Unit 1 Basic concepts to DS
Unit 1 Basic concepts to DSUnit 1 Basic concepts to DS
Unit 1 Basic concepts to DS
 
Trees
TreesTrees
Trees
 
Binary trees
Binary treesBinary trees
Binary trees
 
relational database
relational databaserelational database
relational database
 
Data structures
Data structuresData structures
Data structures
 
Linear Data Structures - List, Stack and Queue
Linear Data Structures - List, Stack and QueueLinear Data Structures - List, Stack and Queue
Linear Data Structures - List, Stack and Queue
 
Tree(Data Structure)
Tree(Data Structure)Tree(Data Structure)
Tree(Data Structure)
 
Advanced Trees
Advanced TreesAdvanced Trees
Advanced Trees
 
Classification of datastructure.ppt
Classification of datastructure.pptClassification of datastructure.ppt
Classification of datastructure.ppt
 
Data mining – introduction
Data mining – introductionData mining – introduction
Data mining – introduction
 
tree in Data Structures
tree in Data Structurestree in Data Structures
tree in Data Structures
 
Sachin noire 2024
Sachin noire 2024Sachin noire 2024
Sachin noire 2024
 
Relational database terms
Relational database termsRelational database terms
Relational database terms
 
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCEARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
 
Tree
TreeTree
Tree
 

Similaire à Data structure(Part 2)

tree-160731205832.pptx
tree-160731205832.pptxtree-160731205832.pptx
tree-160731205832.pptx
MouDhara1
 
cppggggggggggggggggggggggggggggggggggggggg.pptx
cppggggggggggggggggggggggggggggggggggggggg.pptxcppggggggggggggggggggggggggggggggggggggggg.pptx
cppggggggggggggggggggggggggggggggggggggggg.pptx
ShruthiS594607
 

Similaire à Data structure(Part 2) (20)

tree-160731205832.pptx
tree-160731205832.pptxtree-160731205832.pptx
tree-160731205832.pptx
 
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
 
Tree
TreeTree
Tree
 
DSA-Unit-2.pptx
DSA-Unit-2.pptxDSA-Unit-2.pptx
DSA-Unit-2.pptx
 
Tree
TreeTree
Tree
 
Unit 5 Tree.pptx
Unit 5 Tree.pptxUnit 5 Tree.pptx
Unit 5 Tree.pptx
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
 
Unit III.ppt
Unit III.pptUnit III.ppt
Unit III.ppt
 
Binary Search Tree.pptx
Binary Search Tree.pptxBinary Search Tree.pptx
Binary Search Tree.pptx
 
Tree 11.ppt
Tree 11.pptTree 11.ppt
Tree 11.ppt
 
Data Structures 4
Data Structures 4Data Structures 4
Data Structures 4
 
BINARY SEARCH TREE
BINARY SEARCH TREEBINARY SEARCH TREE
BINARY SEARCH TREE
 
Tree
TreeTree
Tree
 
Tree Introduction.pptx
Tree Introduction.pptxTree Introduction.pptx
Tree Introduction.pptx
 
Binary tree
Binary treeBinary tree
Binary tree
 
cppggggggggggggggggggggggggggggggggggggggg.pptx
cppggggggggggggggggggggggggggggggggggggggg.pptxcppggggggggggggggggggggggggggggggggggggggg.pptx
cppggggggggggggggggggggggggggggggggggggggg.pptx
 
Module - 5_Trees.pdf
Module - 5_Trees.pdfModule - 5_Trees.pdf
Module - 5_Trees.pdf
 
Mca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graphMca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graph
 
Bca ii dfs u-3 tree and graph
Bca  ii dfs u-3 tree and graphBca  ii dfs u-3 tree and graph
Bca ii dfs u-3 tree and graph
 
Lecture 9: Binary tree basics
Lecture 9: Binary tree basicsLecture 9: Binary tree basics
Lecture 9: Binary tree basics
 

Plus de SURBHI SAROHA (20)

Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2
 
Management Information System(Unit 2).pptx
Management Information System(Unit 2).pptxManagement Information System(Unit 2).pptx
Management Information System(Unit 2).pptx
 
Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)
 
Management Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxManagement Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptx
 
Introduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptxIntroduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptx
 
JAVA (UNIT 5)
JAVA (UNIT 5)JAVA (UNIT 5)
JAVA (UNIT 5)
 
DBMS (UNIT 5)
DBMS (UNIT 5)DBMS (UNIT 5)
DBMS (UNIT 5)
 
DBMS UNIT 4
DBMS UNIT 4DBMS UNIT 4
DBMS UNIT 4
 
JAVA(UNIT 4)
JAVA(UNIT 4)JAVA(UNIT 4)
JAVA(UNIT 4)
 
OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)
 
OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)
 
DBMS UNIT 3
DBMS UNIT 3DBMS UNIT 3
DBMS UNIT 3
 
JAVA (UNIT 3)
JAVA (UNIT 3)JAVA (UNIT 3)
JAVA (UNIT 3)
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)
 
DBMS (UNIT 2)
DBMS (UNIT 2)DBMS (UNIT 2)
DBMS (UNIT 2)
 
JAVA UNIT 2
JAVA UNIT 2JAVA UNIT 2
JAVA UNIT 2
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)
 
Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
 

Dernier

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Dernier (20)

On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 

Data structure(Part 2)

  • 2. Syllabus • Trees • Binary search trees • Multidimensional arrays
  • 3. Trees • Trees: Unlike Arrays, Linked Lists, Stack and queues, which are linear data structures, trees are hierarchical data structures. • Tree Vocabulary: The topmost node is called root of the tree. • The elements that are directly under an element are called its children. • A tree is a nonlinear hierarchical data structure that consists of nodes connected by edges. • The element directly above something is called its parent. • For example, ‘a’ is a child of ‘f’, and ‘f’ is the parent of ‘a’. Finally, elements with no children are called leaves.
  • 4. Example • tree • ---- • j <-- root • / • f k • / • a h z <-- leaves
  • 6. Tree Terminologies • Node • A node is an entity that contains a key or value and pointers to its child nodes. • The last nodes of each path are called leaf nodes or external nodes that do not contain a link/pointer to child nodes. • The node having at least a child node is called an internal node. • Edge • It is the link between any two nodes.
  • 7. Cont… • Root • It is the topmost node of a tree. • Height of a Node • The height of a node is the number of edges from the node to the deepest leaf (ie. the longest path from the node to a leaf node). • Depth of a Node • The depth of a node is the number of edges from the root to the node. • Height of a Tree • The height of a Tree is the height of the root node or the depth of the deepest node.
  • 8. Cont…. • Degree of a Node • The degree of a node is the total number of branches of that node. • Forest • A collection of disjoint trees is called a forest. • Types of Tree • Binary Tree • Binary Search Tree • AVL Tree • B-Tree
  • 9. Binary search trees • Binary Search 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 lesser than the node’s key. • The right subtree of a node contains only nodes with keys greater than the node’s key. • The left and right subtree each must also be a binary search tree.
  • 11. Cont….. • A Binary Search Tree (BST) is a tree in which all the nodes follow the below- mentioned properties − • The value of the key of the left sub-tree is less than the value of its parent (root) node's key. • The value of the key of the right sub-tree is greater than or equal to the value of its parent (root) node's key. • Following are the basic operations of a tree − • Search − Searches an element in a tree. • Insert − Inserts an element in a tree. • Pre-order Traversal − Traverses a tree in a pre-order manner. • In-order Traversal − Traverses a tree in an in-order manner. • Post-order Traversal − Traverses a tree in a post-order manner.
  • 12. Node • Define a node having some data, references to its left and right child nodes. • struct node { • int data; • struct node *leftChild; • struct node *rightChild; • };
  • 13. Multidimensional arrays • A multi-dimensional array is an array of arrays. 2-dimensional arrays are the most commonly used. They are used to store data in a tabular manner. • Consider following 2D array, which is of the size 3×5. For an array of size N×M, the rows and columns are numbered from 0 to N−1 and columns are numbered from 0 to M−1, respectively. Any element of the array can be accessed by arr[i][j] where 0≤i<N and 0≤j<M. For example, in the following array, the value stored at arr[1][3] is 14.
  • 14. Cont… • 2D array declaration: • To declare a 2D array, you must specify the following: • Row-size: Defines the number of rows • Column-size: Defines the number of columns • Type of array: Defines the type of elements to be stored in the array i.e. either a number, character, or other such datatype. A sample form of declaration is as follows: • type arr[row_size][column_size]