SlideShare a Scribd company logo
1 of 21
Download to read offline
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

Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operationsKamran Zafar
 
Different Sorting tecniques in Data Structure
Different Sorting tecniques in Data StructureDifferent Sorting tecniques in Data Structure
Different Sorting tecniques in Data StructureTushar Gonawala
 
Unit 4 external sorting
Unit 4   external sortingUnit 4   external sorting
Unit 4 external sortingDrkhanchanaR
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structureschauhankapil
 
Lecture notes data structures tree
Lecture notes data structures   treeLecture notes data structures   tree
Lecture notes data structures treemaamir farooq
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search TreeZafar Ayub
 
Breadth First Search (BFS)
Breadth First Search (BFS)Breadth First Search (BFS)
Breadth First Search (BFS)Dhrumil Panchal
 
Tree Traversal Algorithm in Data Structure
Tree Traversal Algorithm in Data StructureTree Traversal Algorithm in Data Structure
Tree Traversal Algorithm in Data StructureMeghaj Mallick
 
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 treezia eagle
 
Tree data structure
Tree data structureTree data structure
Tree data structureDana dia
 
Dijkstra Searching Algorithms.pptx
Dijkstra Searching Algorithms.pptxDijkstra Searching Algorithms.pptx
Dijkstra Searching Algorithms.pptxsandeep54552
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First SearchKevin Jadiya
 
Circular linked list
Circular linked list Circular linked list
Circular linked list sajinis3
 
trees in data structure
trees in data structure trees in data structure
trees in data structure shameen khan
 
1.8 splay tree
1.8 splay tree 1.8 splay tree
1.8 splay tree Krish_ver2
 

What's hot (20)

Binary trees1
Binary trees1Binary trees1
Binary trees1
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
 
Different Sorting tecniques in Data Structure
Different Sorting tecniques in Data StructureDifferent Sorting tecniques in Data Structure
Different Sorting tecniques in Data Structure
 
Unit 4 external sorting
Unit 4   external sortingUnit 4   external sorting
Unit 4 external sorting
 
Linked list
Linked listLinked list
Linked list
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
 
Lecture notes data structures tree
Lecture notes data structures   treeLecture notes data structures   tree
Lecture notes data structures tree
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Breadth First Search (BFS)
Breadth First Search (BFS)Breadth First Search (BFS)
Breadth First Search (BFS)
 
Tree Traversal Algorithm in Data Structure
Tree Traversal Algorithm in Data StructureTree Traversal Algorithm in Data Structure
Tree Traversal Algorithm in Data Structure
 
B trees dbms
B trees dbmsB trees dbms
B trees dbms
 
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 data structure
Tree data structureTree data structure
Tree data structure
 
Dijkstra Searching Algorithms.pptx
Dijkstra Searching Algorithms.pptxDijkstra Searching Algorithms.pptx
Dijkstra Searching Algorithms.pptx
 
Segment tree
Segment treeSegment tree
Segment tree
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 
Circular linked list
Circular linked list Circular linked list
Circular linked list
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
1.8 splay tree
1.8 splay tree 1.8 splay tree
1.8 splay 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
 
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
 
cppggggggggggggggggggggggggggggggggggggggg.pptx
cppggggggggggggggggggggggggggggggggggggggg.pptxcppggggggggggggggggggggggggggggggggggggggg.pptx
cppggggggggggggggggggggggggggggggggggggggg.pptxShruthiS594607
 

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
 
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
 
cppggggggggggggggggggggggggggggggggggggggg.pptx
cppggggggggggggggggggggggggggggggggggggggg.pptxcppggggggggggggggggggggggggggggggggggggggg.pptx
cppggggggggggggggggggggggggggggggggggggggg.pptx
 

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

6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroom6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroomSamsung Business USA
 
How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17Celine George
 
Shark introduction Morphology and its behaviour characteristics
Shark introduction Morphology and its behaviour characteristicsShark introduction Morphology and its behaviour characteristics
Shark introduction Morphology and its behaviour characteristicsArubSultan
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFEPART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFEMISSRITIMABIOLOGYEXP
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxDhatriParmar
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfChristalin Nelson
 
DBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfDBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfChristalin Nelson
 
Objectives n learning outcoms - MD 20240404.pptx
Objectives n learning outcoms - MD 20240404.pptxObjectives n learning outcoms - MD 20240404.pptx
Objectives n learning outcoms - MD 20240404.pptxMadhavi Dharankar
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxkarenfajardo43
 
ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6Vanessa Camilleri
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
Employablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptxEmployablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptxryandux83rd
 

Recently uploaded (20)

6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroom6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroom
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17
 
CARNAVAL COM MAGIA E EUFORIA _
CARNAVAL COM MAGIA E EUFORIA            _CARNAVAL COM MAGIA E EUFORIA            _
CARNAVAL COM MAGIA E EUFORIA _
 
Shark introduction Morphology and its behaviour characteristics
Shark introduction Morphology and its behaviour characteristicsShark introduction Morphology and its behaviour characteristics
Shark introduction Morphology and its behaviour characteristics
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFEPART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
 
Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...
Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...
Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdf
 
DBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfDBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdf
 
Chi-Square Test Non Parametric Test Categorical Variable
Chi-Square Test Non Parametric Test Categorical VariableChi-Square Test Non Parametric Test Categorical Variable
Chi-Square Test Non Parametric Test Categorical Variable
 
Objectives n learning outcoms - MD 20240404.pptx
Objectives n learning outcoms - MD 20240404.pptxObjectives n learning outcoms - MD 20240404.pptx
Objectives n learning outcoms - MD 20240404.pptx
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
 
ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
Employablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptxEmployablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptx
 

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