SlideShare a Scribd company logo
1 of 21
Course: MCA
Subject: Data and File Structure
Unit-4
Tree and Graph
NONLINEAR DATA STRUCTURE
 2 primary types:
• Trees
• Graphs
• All trees are graphs, but not all graphs are trees
• Recursion is useful and is the easiest way to process
them.
• It helps keep track of what's been processed and what
remains
Graphs
•Graphs can have multiple references in and multiple references out
(whereas tree node only has one reference in)
•Graphs can be directed or undirected and cyclic or acyclic
Trees
• Single parent
• 0 or more children
• A node with no children is called a "leaf"
• The topmost node is called the "root"
• N-ary trees
• Binary trees
N-ary Trees
 The best example of an n-ary tree is your computer’s
directory system.
 It has a single starting point and then 0 or more
branches.
Binary Trees and Binary Search Trees
• Binary search trees allow for fast insertion and removal of
elements
• They are specially designed for fast searching
• A binary tree consists of two nodes, each of which has two
child nodes
• All nodes in a binary search tree fulfill the property that:
• Descendants to the left have smaller data values than the node
data value
• Descendants to the right have larger data values than the node
data value
BST Tree Nodes
• All nodes in a binary search tree fulfill the property that:
• Descendants to the left have smaller data values than
the node data value
• Descendants to the right have larger data values than the
node data value
BST (Balanced Binary Trees)
• Balanced tree: each node has approximately as many
descendants on the left as on the right
• If a binary search tree is balanced, then adding an
element takes O(log(n)) time
• If the tree is unbalanced, insertion can be slow
• Perhaps as slow as insertion into a linked list
Traversing a Tree
 Which were used for the binary tree can now be used for the
general.
 When the general tree has been represented as a binary tree, the
algorithms l tree.
 In-order traversals make no sense when a general tree is converted
to a binary tree.
 In the general tree each node can have more than two children so
trying to insert the parent node in between the children is rather
difficult, especially if there is an odd number of children.
 Pre - order
 This is a process where the root is accessed and processed and
then each of the subtrees is preorder processed. It is also called a
depth-first traversal.
Traversing a Tree
 Pre-order Traversal
 In this way the resulting printout has all nodes at any given
level starting in the same tab column.
 It is relatively easy to draw lines to produce the original
general tree except that the tree is on its side with it's root at the
left rather than with the root at the top.
Tree Traversal
• Tree traversal schemes include
• Preorder traversal (root, left, right)
• Inorder traversal (left, root, right)
• Postorder traversal ( left, right, root)
• Preorder generates prefix expression,(polish notation) from
an expression trees
• Inorder generates a sorted ordering
• Postorder generates a post fix expression, also useful for
node deletion
Height of a BST
 Insert 7
 Insert 4
 Insert 1
 Insert 9
 Insert 5
 It’s a complete tree!
7
4 9
1 5
height = log(5)+1 =
3
BSTs with heights O(log n)
 It would be ideal if a BST was always close to a full
binary tree
 It’s enough to guarantee that the height of tree is
O(log n)
 To guarantee that we have to make the structure of the
tree and insertion and deletion algorithms more
complex
 e.g. AVL trees (balanced), 2-3 trees, 2-3-4 trees (full
but not binary), red–black trees (if red vertices are
ignored then it’s like a full tree)
What is a graph?
 A data structure that consists of a set of nodes
(vertices) and a set of edges that relate the nodes to
each other
 The set of edges describes relationships among the
vertices
Formal definition of graphs
 A graph G is defined as follows:
G=(V,E)
V(G): a finite, nonempty set of vertices
E(G): a set of edges (pairs of vertices)
Directed vs. undirected graphs (cont.)
 When the edges in a graph have a direction, the
graph is called directed (or digraph)
 When the edges in a graph have no direction, the
graph is called undirected.
 Warning: if the graph is directed, the order of the
vertices in each edge is important !!
Breadth-first searching[1]
 A breadth-first search (BFS)
explores nodes nearest the root
before exploring nodes further
away
 For example, after searching A,
then B, then C, the search
proceeds with D, E, F, G
 Node are explored in the order
A B C D E F G H I J K L M N O P Q
 J will be found before N
L M N O P
G
Q
H JI K
FED
B C
A
Depth-first searching[2]
 A depth-first search (DFS)
explores a path all the way to a
leaf before backtracking and
exploring another path
 For example, after searching A,
then B, then D, the search
backtracks and tries another path
from B
 Node are explored in the order A
B D E H L M N I O P C F G J K
Q
 N will be found before JL M N O P
G
Q
H JI K
FED
B C
A
A spanning tree of a graph is just a subgraph that
contains all the vertices and is a tree.
A graph may have many spanning trees.
o
r
o
r
o
r
Some Spanning Trees from Graph AGraph
A
Spanning Trees[3]
Minimum Spanning Trees[4]
The Minimum Spanning Tree for a given graph is the
Spanning Tree of minimum cost for that graph.
5
7
2
1
3
4
2
1
3
Complete Graph Minimum Spanning Tree
References
 An introduction to Datastructure with application by jean Trembley and sorrenson
 Data structures by schaums and series –seymour lipschutz
 http://en.wikipedia.org/wiki/Book:Data_structures
 http://www.amazon.com/Data-Structures-Algorithms
 http://www.amazon.in/Data-Structures-Algorithms-Made-Easy/dp/0615459811/
 http://www.amazon.in/Data-Structures-SIE-Seymour-Lipschutz/dp
 List of Images
1. http://www.algolist.net/Algorithms/Graph/Undirected/breadth-first_search
2. http://www.expertsmind.com/questions/depth-first-search-30153061.aspx
3. http://en.wikipedia.org/wiki/Book:Data_structure/spanning tree
4. http://en.wikipedia.org/wiki/Book:Data_structure

More Related Content

What's hot (20)

Graph theory
Graph theoryGraph theory
Graph theory
 
Breadth first search and depth first search
Breadth first search and  depth first searchBreadth first search and  depth first search
Breadth first search and depth first search
 
Link list
Link listLink list
Link list
 
Graph traversal-BFS & DFS
Graph traversal-BFS & DFSGraph traversal-BFS & DFS
Graph traversal-BFS & DFS
 
Binomial Heap
Binomial HeapBinomial Heap
Binomial Heap
 
introduction to graph theory
introduction to graph theoryintroduction to graph theory
introduction to graph theory
 
2.5 bfs & dfs 02
2.5 bfs & dfs 022.5 bfs & dfs 02
2.5 bfs & dfs 02
 
3.3 hierarchical methods
3.3 hierarchical methods3.3 hierarchical methods
3.3 hierarchical methods
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 
Graph algorithm
Graph algorithmGraph algorithm
Graph algorithm
 
Lecture notes data structures tree
Lecture notes data structures   treeLecture notes data structures   tree
Lecture notes data structures tree
 
Dfs
DfsDfs
Dfs
 
Threaded Binary Tree
Threaded Binary TreeThreaded Binary Tree
Threaded Binary Tree
 
DFS and BFS
DFS and BFSDFS and BFS
DFS and BFS
 
Binary tree
Binary tree Binary tree
Binary tree
 
graph.ppt
graph.pptgraph.ppt
graph.ppt
 
Indexing and Hashing
Indexing and HashingIndexing and Hashing
Indexing and Hashing
 
Connectivity of graph
Connectivity of graphConnectivity of graph
Connectivity of graph
 
5.5 graph mining
5.5 graph mining5.5 graph mining
5.5 graph mining
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
 

Viewers also liked (18)

Lecture 10 data structures and algorithms
Lecture 10 data structures and algorithmsLecture 10 data structures and algorithms
Lecture 10 data structures and algorithms
 
Implementation of trees
Implementation of trees Implementation of trees
Implementation of trees
 
non linear data structure -introduction of tree
non linear data structure -introduction of treenon linear data structure -introduction of tree
non linear data structure -introduction of tree
 
Non Linear Data Structures
Non Linear Data StructuresNon Linear Data Structures
Non Linear Data Structures
 
Lecture7 data structure(tree)
Lecture7 data structure(tree)Lecture7 data structure(tree)
Lecture7 data structure(tree)
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
 
Graphs bfs dfs
Graphs bfs dfsGraphs bfs dfs
Graphs bfs dfs
 
Tree
TreeTree
Tree
 
Lecture8 data structure(graph)
Lecture8 data structure(graph)Lecture8 data structure(graph)
Lecture8 data structure(graph)
 
Tree
TreeTree
Tree
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Graphs ppt
Graphs pptGraphs ppt
Graphs ppt
 
Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and Algorithm
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 

Similar to 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 graphRai University
 
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 graphRai University
 
B tree ,B plus and graph
B tree ,B plus and graph B tree ,B plus and graph
B tree ,B plus and graph RaaviKapoor
 
tree-160731205832.pptx
tree-160731205832.pptxtree-160731205832.pptx
tree-160731205832.pptxMouDhara1
 
Farhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana Shaikh
 
data_structures_and_applications_-_module-4.ppt
data_structures_and_applications_-_module-4.pptdata_structures_and_applications_-_module-4.ppt
data_structures_and_applications_-_module-4.pptssuser5c874e
 
trees in data structure
trees in data structure trees in data structure
trees in data structure shameen khan
 
Data structures and Algorithm analysis_Lecture4.pptx
Data structures and Algorithm analysis_Lecture4.pptxData structures and Algorithm analysis_Lecture4.pptx
Data structures and Algorithm analysis_Lecture4.pptxAhmedEldesoky24
 
chapter 6.1.pptx
chapter 6.1.pptxchapter 6.1.pptx
chapter 6.1.pptxTekle12
 
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-10sumitbardhan
 
Data structure(Part 2)
Data structure(Part 2)Data structure(Part 2)
Data structure(Part 2)SURBHI SAROHA
 

Similar to Mca iii dfs u-4 tree and graph (20)

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
 
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
 
Tree 11.ppt
Tree 11.pptTree 11.ppt
Tree 11.ppt
 
B tree ,B plus and graph
B tree ,B plus and graph B tree ,B plus and graph
B tree ,B plus and graph
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
 
tree-160731205832.pptx
tree-160731205832.pptxtree-160731205832.pptx
tree-160731205832.pptx
 
Unit 3 trees
Unit 3   treesUnit 3   trees
Unit 3 trees
 
Tree
TreeTree
Tree
 
Module - 5_Trees.pdf
Module - 5_Trees.pdfModule - 5_Trees.pdf
Module - 5_Trees.pdf
 
Data Structures 5
Data Structures 5Data Structures 5
Data Structures 5
 
Data Structures 4
Data Structures 4Data Structures 4
Data Structures 4
 
Farhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructure
 
data_structures_and_applications_-_module-4.ppt
data_structures_and_applications_-_module-4.pptdata_structures_and_applications_-_module-4.ppt
data_structures_and_applications_-_module-4.ppt
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
Data structures and Algorithm analysis_Lecture4.pptx
Data structures and Algorithm analysis_Lecture4.pptxData structures and Algorithm analysis_Lecture4.pptx
Data structures and Algorithm analysis_Lecture4.pptx
 
DSA-Unit-2.pptx
DSA-Unit-2.pptxDSA-Unit-2.pptx
DSA-Unit-2.pptx
 
chapter 6.1.pptx
chapter 6.1.pptxchapter 6.1.pptx
chapter 6.1.pptx
 
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
 
Data structure(Part 2)
Data structure(Part 2)Data structure(Part 2)
Data structure(Part 2)
 
Module 8.1 Trees.pdf
Module 8.1 Trees.pdfModule 8.1 Trees.pdf
Module 8.1 Trees.pdf
 

More from Rai University

Brochure Rai University
Brochure Rai University Brochure Rai University
Brochure Rai University Rai University
 
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,Rai University
 
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02Rai University
 
Bsc agri 2 pae u-4.3 public expenditure
Bsc agri  2 pae  u-4.3 public expenditureBsc agri  2 pae  u-4.3 public expenditure
Bsc agri 2 pae u-4.3 public expenditureRai University
 
Bsc agri 2 pae u-4.2 public finance
Bsc agri  2 pae  u-4.2 public financeBsc agri  2 pae  u-4.2 public finance
Bsc agri 2 pae u-4.2 public financeRai University
 
Bsc agri 2 pae u-4.1 introduction
Bsc agri  2 pae  u-4.1 introductionBsc agri  2 pae  u-4.1 introduction
Bsc agri 2 pae u-4.1 introductionRai University
 
Bsc agri 2 pae u-3.3 inflation
Bsc agri  2 pae  u-3.3  inflationBsc agri  2 pae  u-3.3  inflation
Bsc agri 2 pae u-3.3 inflationRai University
 
Bsc agri 2 pae u-3.2 introduction to macro economics
Bsc agri  2 pae  u-3.2 introduction to macro economicsBsc agri  2 pae  u-3.2 introduction to macro economics
Bsc agri 2 pae u-3.2 introduction to macro economicsRai University
 
Bsc agri 2 pae u-3.1 marketstructure
Bsc agri  2 pae  u-3.1 marketstructureBsc agri  2 pae  u-3.1 marketstructure
Bsc agri 2 pae u-3.1 marketstructureRai University
 
Bsc agri 2 pae u-3 perfect-competition
Bsc agri  2 pae  u-3 perfect-competitionBsc agri  2 pae  u-3 perfect-competition
Bsc agri 2 pae u-3 perfect-competitionRai University
 

More from Rai University (20)

Brochure Rai University
Brochure Rai University Brochure Rai University
Brochure Rai University
 
Mm unit 4point2
Mm unit 4point2Mm unit 4point2
Mm unit 4point2
 
Mm unit 4point1
Mm unit 4point1Mm unit 4point1
Mm unit 4point1
 
Mm unit 4point3
Mm unit 4point3Mm unit 4point3
Mm unit 4point3
 
Mm unit 3point2
Mm unit 3point2Mm unit 3point2
Mm unit 3point2
 
Mm unit 3point1
Mm unit 3point1Mm unit 3point1
Mm unit 3point1
 
Mm unit 2point2
Mm unit 2point2Mm unit 2point2
Mm unit 2point2
 
Mm unit 2 point 1
Mm unit 2 point 1Mm unit 2 point 1
Mm unit 2 point 1
 
Mm unit 1point3
Mm unit 1point3Mm unit 1point3
Mm unit 1point3
 
Mm unit 1point2
Mm unit 1point2Mm unit 1point2
Mm unit 1point2
 
Mm unit 1point1
Mm unit 1point1Mm unit 1point1
Mm unit 1point1
 
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
 
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
 
Bsc agri 2 pae u-4.3 public expenditure
Bsc agri  2 pae  u-4.3 public expenditureBsc agri  2 pae  u-4.3 public expenditure
Bsc agri 2 pae u-4.3 public expenditure
 
Bsc agri 2 pae u-4.2 public finance
Bsc agri  2 pae  u-4.2 public financeBsc agri  2 pae  u-4.2 public finance
Bsc agri 2 pae u-4.2 public finance
 
Bsc agri 2 pae u-4.1 introduction
Bsc agri  2 pae  u-4.1 introductionBsc agri  2 pae  u-4.1 introduction
Bsc agri 2 pae u-4.1 introduction
 
Bsc agri 2 pae u-3.3 inflation
Bsc agri  2 pae  u-3.3  inflationBsc agri  2 pae  u-3.3  inflation
Bsc agri 2 pae u-3.3 inflation
 
Bsc agri 2 pae u-3.2 introduction to macro economics
Bsc agri  2 pae  u-3.2 introduction to macro economicsBsc agri  2 pae  u-3.2 introduction to macro economics
Bsc agri 2 pae u-3.2 introduction to macro economics
 
Bsc agri 2 pae u-3.1 marketstructure
Bsc agri  2 pae  u-3.1 marketstructureBsc agri  2 pae  u-3.1 marketstructure
Bsc agri 2 pae u-3.1 marketstructure
 
Bsc agri 2 pae u-3 perfect-competition
Bsc agri  2 pae  u-3 perfect-competitionBsc agri  2 pae  u-3 perfect-competition
Bsc agri 2 pae u-3 perfect-competition
 

Recently uploaded

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
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 17Celine George
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 

Recently uploaded (20)

INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
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
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 

Mca iii dfs u-4 tree and graph

  • 1. Course: MCA Subject: Data and File Structure Unit-4 Tree and Graph
  • 2. NONLINEAR DATA STRUCTURE  2 primary types: • Trees • Graphs • All trees are graphs, but not all graphs are trees • Recursion is useful and is the easiest way to process them. • It helps keep track of what's been processed and what remains
  • 3. Graphs •Graphs can have multiple references in and multiple references out (whereas tree node only has one reference in) •Graphs can be directed or undirected and cyclic or acyclic
  • 4. Trees • Single parent • 0 or more children • A node with no children is called a "leaf" • The topmost node is called the "root" • N-ary trees • Binary trees
  • 5. N-ary Trees  The best example of an n-ary tree is your computer’s directory system.  It has a single starting point and then 0 or more branches.
  • 6. Binary Trees and Binary Search Trees • Binary search trees allow for fast insertion and removal of elements • They are specially designed for fast searching • A binary tree consists of two nodes, each of which has two child nodes • All nodes in a binary search tree fulfill the property that: • Descendants to the left have smaller data values than the node data value • Descendants to the right have larger data values than the node data value
  • 7. BST Tree Nodes • All nodes in a binary search tree fulfill the property that: • Descendants to the left have smaller data values than the node data value • Descendants to the right have larger data values than the node data value
  • 8. BST (Balanced Binary Trees) • Balanced tree: each node has approximately as many descendants on the left as on the right • If a binary search tree is balanced, then adding an element takes O(log(n)) time • If the tree is unbalanced, insertion can be slow • Perhaps as slow as insertion into a linked list
  • 9. Traversing a Tree  Which were used for the binary tree can now be used for the general.  When the general tree has been represented as a binary tree, the algorithms l tree.  In-order traversals make no sense when a general tree is converted to a binary tree.  In the general tree each node can have more than two children so trying to insert the parent node in between the children is rather difficult, especially if there is an odd number of children.  Pre - order  This is a process where the root is accessed and processed and then each of the subtrees is preorder processed. It is also called a depth-first traversal.
  • 10. Traversing a Tree  Pre-order Traversal  In this way the resulting printout has all nodes at any given level starting in the same tab column.  It is relatively easy to draw lines to produce the original general tree except that the tree is on its side with it's root at the left rather than with the root at the top.
  • 11. Tree Traversal • Tree traversal schemes include • Preorder traversal (root, left, right) • Inorder traversal (left, root, right) • Postorder traversal ( left, right, root) • Preorder generates prefix expression,(polish notation) from an expression trees • Inorder generates a sorted ordering • Postorder generates a post fix expression, also useful for node deletion
  • 12. Height of a BST  Insert 7  Insert 4  Insert 1  Insert 9  Insert 5  It’s a complete tree! 7 4 9 1 5 height = log(5)+1 = 3
  • 13. BSTs with heights O(log n)  It would be ideal if a BST was always close to a full binary tree  It’s enough to guarantee that the height of tree is O(log n)  To guarantee that we have to make the structure of the tree and insertion and deletion algorithms more complex  e.g. AVL trees (balanced), 2-3 trees, 2-3-4 trees (full but not binary), red–black trees (if red vertices are ignored then it’s like a full tree)
  • 14. What is a graph?  A data structure that consists of a set of nodes (vertices) and a set of edges that relate the nodes to each other  The set of edges describes relationships among the vertices
  • 15. Formal definition of graphs  A graph G is defined as follows: G=(V,E) V(G): a finite, nonempty set of vertices E(G): a set of edges (pairs of vertices)
  • 16. Directed vs. undirected graphs (cont.)  When the edges in a graph have a direction, the graph is called directed (or digraph)  When the edges in a graph have no direction, the graph is called undirected.  Warning: if the graph is directed, the order of the vertices in each edge is important !!
  • 17. Breadth-first searching[1]  A breadth-first search (BFS) explores nodes nearest the root before exploring nodes further away  For example, after searching A, then B, then C, the search proceeds with D, E, F, G  Node are explored in the order A B C D E F G H I J K L M N O P Q  J will be found before N L M N O P G Q H JI K FED B C A
  • 18. Depth-first searching[2]  A depth-first search (DFS) explores a path all the way to a leaf before backtracking and exploring another path  For example, after searching A, then B, then D, the search backtracks and tries another path from B  Node are explored in the order A B D E H L M N I O P C F G J K Q  N will be found before JL M N O P G Q H JI K FED B C A
  • 19. A spanning tree of a graph is just a subgraph that contains all the vertices and is a tree. A graph may have many spanning trees. o r o r o r Some Spanning Trees from Graph AGraph A Spanning Trees[3]
  • 20. Minimum Spanning Trees[4] The Minimum Spanning Tree for a given graph is the Spanning Tree of minimum cost for that graph. 5 7 2 1 3 4 2 1 3 Complete Graph Minimum Spanning Tree
  • 21. References  An introduction to Datastructure with application by jean Trembley and sorrenson  Data structures by schaums and series –seymour lipschutz  http://en.wikipedia.org/wiki/Book:Data_structures  http://www.amazon.com/Data-Structures-Algorithms  http://www.amazon.in/Data-Structures-Algorithms-Made-Easy/dp/0615459811/  http://www.amazon.in/Data-Structures-SIE-Seymour-Lipschutz/dp  List of Images 1. http://www.algolist.net/Algorithms/Graph/Undirected/breadth-first_search 2. http://www.expertsmind.com/questions/depth-first-search-30153061.aspx 3. http://en.wikipedia.org/wiki/Book:Data_structure/spanning tree 4. http://en.wikipedia.org/wiki/Book:Data_structure