SlideShare une entreprise Scribd logo
1  sur  20
Graphs  Data Structures and Algorithms
Graphs: Term definition Graphs are natural models that are used to represent arbitrary relationships among data objects.
Graphs are of 2 types Directed Undirected
Basic terms involved in graphs: Incident edge Degree of vertex Directed edge Undirected edge Path Simple path Maximum number of edges Subgraph Connected graph Completely connected graph
Basic Term Incident edge: (vi,vj) is an edge, then edge(vi,vj) is said to be incident to vertices vi and vj
Degree of vertex The number of edges incident onto the vertex 	 For a directed graph Indegree of a vertex vi is the number of edges incident onto vi, with vi as the head.  Outdegree of vertex vi is the number of edges incident onto vi, with vi as the tail.
Edges are of 2 types Directed edge: A directed edge between the vertices vi and vj is an ordered pair. It is denoted by <vi,vj>. Undirected edge: An undirected edge between the vertices vi and vj is an unordered pair. It is denoted by (vi,vj). Maximum number of edges: The maximum number of edges in an undirected graph with n vertices is n(n−1)/2. In a directed graph, it is n(n−1).
Paths Path: A path between vertices vp and vq is a sequence of vertices vp, vi1, vi2,…, vin,vq such that there exists a sequence of edges (vp, vi1), (vi1, vi2), …, ( vin, vq). Simple path: A simple path is a path given by a sequence of vertices in which all vertices are distinct except the first and the last vertices. If the first and the last vertices are same, the path will be a cycle.
Different Types of Graphs Subgraph Connected graph Completely connected graph
1. Subgraphs A subgraph of a graph G = (V,E) is a graph G where V(G) is a subset of V(G). E(G) consists of edges (v1,v2) in E(G), such that both v1 and v2 are in V(G). [Note: If G = (V,E) is a graph, then V(G) is a set of vertices of G and E(G) is a set of edges of G.]
2. Connected Graph A graph G is said to be connected if for every pair of distinct vertices (vi,vj), there is a path from vi to vj
3. Completely connected graph A graph G is completely connected if, for every pair of distinct vertices (vi,vj), there exists an edge.
Representation of graphs Graphs can be represented in 2 ways Array representation Linked list representation
1. Array Representation
2. Linked List representation
Graph traversal Traversal of graph implies visiting the nodes of the graph. A graph can be traversed in 2 ways Depth first traversal Breadth first traversal
1. Depth First traversal When a graph is traversed by visiting the nodes in the forward (deeper) direction as long as possible, the traversal is called depth-first traversal. For example, for the graph shown in Figure, the depth-first traversal starting at the vertex 0 visits the node in the orders: 0 1 2 6 7 8 5 3 4 0 4 3 5 8 6 7 2 1
2. Breadth first traversal When a graph is traversed by visiting all the adjacent nodes/vertices of a node/vertex first, the traversal is called breadth-first traversal. For example, for a graph in which the breadth-first traversal starts at vertex v1, visits to the nodes take place in the order shown in Figure
Minimum Cost spanning tree When the edges of the graph have weights representing the cost in some suitable terms, we can obtain that spanning tree of a graph whose cost is minimum in terms of the weights of the edges. For this, we start with the edge with the minimum-cost/weight, add it to set T, and mark it as visited. We next consider the edge with minimum-cost that is not yet visited, add it to T, and mark it as visited. While adding an edge to the set T, we first check whether both the vertices of the edge are visited; if they are, we do not add to the set T, because it will form a cycle. The minimum-cost spanning tree of the graph is as shown
Thank You Find more at http://amitbiswal.blogspot.com

Contenu connexe

Tendances

Surveying assignment solutions 22.2.2015
Surveying assignment solutions 22.2.2015Surveying assignment solutions 22.2.2015
Surveying assignment solutions 22.2.2015V Vinayaka Ram
 
Data structure graphs
Data structure  graphsData structure  graphs
Data structure graphsUma mohan
 
PGL (Persamaan Garis Dari Gambar Garis Lurus & Dari Dua Titik) - Pertemuan 1
PGL (Persamaan Garis Dari Gambar Garis Lurus & Dari Dua Titik) - Pertemuan 1PGL (Persamaan Garis Dari Gambar Garis Lurus & Dari Dua Titik) - Pertemuan 1
PGL (Persamaan Garis Dari Gambar Garis Lurus & Dari Dua Titik) - Pertemuan 1Shinta Novianti
 
Graphs of x3 function
Graphs of x3 function Graphs of x3 function
Graphs of x3 function cvcvvc
 
Geometry terms (1)
Geometry terms (1)Geometry terms (1)
Geometry terms (1)CarolinaDay3
 
4.6 quick graphs using slope intercept form
4.6 quick graphs using slope intercept form4.6 quick graphs using slope intercept form
4.6 quick graphs using slope intercept formAnibal Aguilar Barahona
 
Hermit curves &amp; beizer curves
Hermit curves &amp; beizer curvesHermit curves &amp; beizer curves
Hermit curves &amp; beizer curvesKKARUNKARTHIK
 
Quaternion to axis
Quaternion to axisQuaternion to axis
Quaternion to axisArric Tan
 
Graph Basic In Data structure
Graph Basic In Data structureGraph Basic In Data structure
Graph Basic In Data structureIkhlas Rahman
 
Tutorials--Line from Two Points
Tutorials--Line from Two PointsTutorials--Line from Two Points
Tutorials--Line from Two PointsMedia4math
 
IRJET- On the Generalization of Lami’s Theorem
IRJET- On the Generalization of Lami’s TheoremIRJET- On the Generalization of Lami’s Theorem
IRJET- On the Generalization of Lami’s TheoremIRJET Journal
 
Graphs in datastructures
Graphs in datastructuresGraphs in datastructures
Graphs in datastructuresLikhithaGunturi
 
Tutorials --Parallel and Perpendicular Lines
Tutorials --Parallel and Perpendicular LinesTutorials --Parallel and Perpendicular Lines
Tutorials --Parallel and Perpendicular LinesMedia4math
 
Graph theory02
Graph theory02Graph theory02
Graph theory02Sumit Nema
 

Tendances (20)

Surveying assignment solutions 22.2.2015
Surveying assignment solutions 22.2.2015Surveying assignment solutions 22.2.2015
Surveying assignment solutions 22.2.2015
 
Data structure graphs
Data structure  graphsData structure  graphs
Data structure graphs
 
PGL (Persamaan Garis Dari Gambar Garis Lurus & Dari Dua Titik) - Pertemuan 1
PGL (Persamaan Garis Dari Gambar Garis Lurus & Dari Dua Titik) - Pertemuan 1PGL (Persamaan Garis Dari Gambar Garis Lurus & Dari Dua Titik) - Pertemuan 1
PGL (Persamaan Garis Dari Gambar Garis Lurus & Dari Dua Titik) - Pertemuan 1
 
Graphs of x3 function
Graphs of x3 function Graphs of x3 function
Graphs of x3 function
 
Geometry terms (1)
Geometry terms (1)Geometry terms (1)
Geometry terms (1)
 
Bezier Curves
Bezier CurvesBezier Curves
Bezier Curves
 
4.6 quick graphs using slope intercept form
4.6 quick graphs using slope intercept form4.6 quick graphs using slope intercept form
4.6 quick graphs using slope intercept form
 
Posulate and theoroem
Posulate and theoroemPosulate and theoroem
Posulate and theoroem
 
Hermit curves &amp; beizer curves
Hermit curves &amp; beizer curvesHermit curves &amp; beizer curves
Hermit curves &amp; beizer curves
 
Freddy Meza
Freddy Meza Freddy Meza
Freddy Meza
 
Types of graphs
Types of graphsTypes of graphs
Types of graphs
 
una01
una01una01
una01
 
Quaternion to axis
Quaternion to axisQuaternion to axis
Quaternion to axis
 
Graph Basic In Data structure
Graph Basic In Data structureGraph Basic In Data structure
Graph Basic In Data structure
 
Bezier curve computer graphics
Bezier curve computer graphics Bezier curve computer graphics
Bezier curve computer graphics
 
Tutorials--Line from Two Points
Tutorials--Line from Two PointsTutorials--Line from Two Points
Tutorials--Line from Two Points
 
IRJET- On the Generalization of Lami’s Theorem
IRJET- On the Generalization of Lami’s TheoremIRJET- On the Generalization of Lami’s Theorem
IRJET- On the Generalization of Lami’s Theorem
 
Graphs in datastructures
Graphs in datastructuresGraphs in datastructures
Graphs in datastructures
 
Tutorials --Parallel and Perpendicular Lines
Tutorials --Parallel and Perpendicular LinesTutorials --Parallel and Perpendicular Lines
Tutorials --Parallel and Perpendicular Lines
 
Graph theory02
Graph theory02Graph theory02
Graph theory02
 

En vedette

Role of IT in environment
Role of IT in environmentRole of IT in environment
Role of IT in environmentMasoomTulsiani
 
Role of information technology in environment
Role of information technology in environmentRole of information technology in environment
Role of information technology in environmentRohit Sunkari
 
Role of IT in environment & Human Health
Role of IT in environment & Human HealthRole of IT in environment & Human Health
Role of IT in environment & Human HealthTanvi Potluri
 
Child welfare
Child welfareChild welfare
Child welfareStudent
 
Role of information technology on environment and human health
Role of information technology on environment and human healthRole of information technology on environment and human health
Role of information technology on environment and human healthRoger Gomes
 
Women and child welfare
Women and child welfareWomen and child welfare
Women and child welfareNitika Saini
 
Ppt on women and child welfare
Ppt on women and child welfarePpt on women and child welfare
Ppt on women and child welfareKomal Bhatia
 

En vedette (11)

Trees
TreesTrees
Trees
 
Role of it
Role of itRole of it
Role of it
 
Role of IT in environment
Role of IT in environmentRole of IT in environment
Role of IT in environment
 
Women & child welfare
Women & child welfareWomen & child welfare
Women & child welfare
 
Role of information technology in environment
Role of information technology in environmentRole of information technology in environment
Role of information technology in environment
 
Women's Welfare
Women's WelfareWomen's Welfare
Women's Welfare
 
Role of IT in environment & Human Health
Role of IT in environment & Human HealthRole of IT in environment & Human Health
Role of IT in environment & Human Health
 
Child welfare
Child welfareChild welfare
Child welfare
 
Role of information technology on environment and human health
Role of information technology on environment and human healthRole of information technology on environment and human health
Role of information technology on environment and human health
 
Women and child welfare
Women and child welfareWomen and child welfare
Women and child welfare
 
Ppt on women and child welfare
Ppt on women and child welfarePpt on women and child welfare
Ppt on women and child welfare
 

Similaire à Graphs

Similaire à Graphs (20)

Ass. (3)graph d.m
Ass. (3)graph d.mAss. (3)graph d.m
Ass. (3)graph d.m
 
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
 
graph ASS (1).ppt
graph ASS (1).pptgraph ASS (1).ppt
graph ASS (1).ppt
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
 
Graph ASS DBATU.pptx
Graph ASS DBATU.pptxGraph ASS DBATU.pptx
Graph ASS DBATU.pptx
 
09_DS_MCA_Graphs.pdf
09_DS_MCA_Graphs.pdf09_DS_MCA_Graphs.pdf
09_DS_MCA_Graphs.pdf
 
Graphs.pdf
Graphs.pdfGraphs.pdf
Graphs.pdf
 
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdfClass01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
 
Graphs
GraphsGraphs
Graphs
 
Graph theory
Graph theoryGraph theory
Graph theory
 
Graph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptxGraph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptx
 
graph.ppt
graph.pptgraph.ppt
graph.ppt
 
Graph-theory.ppt
Graph-theory.pptGraph-theory.ppt
Graph-theory.ppt
 
Graph.ppt
Graph.pptGraph.ppt
Graph.ppt
 
graph.ppt
graph.pptgraph.ppt
graph.ppt
 
graph theory
graph theorygraph theory
graph theory
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Elements of Graph Theory for IS.pptx
Elements of Graph Theory for IS.pptxElements of Graph Theory for IS.pptx
Elements of Graph Theory for IS.pptx
 
Graphs.pptx
Graphs.pptxGraphs.pptx
Graphs.pptx
 
Slides Chapter10.1 10.2
Slides Chapter10.1 10.2Slides Chapter10.1 10.2
Slides Chapter10.1 10.2
 

Graphs

  • 1. Graphs Data Structures and Algorithms
  • 2. Graphs: Term definition Graphs are natural models that are used to represent arbitrary relationships among data objects.
  • 3. Graphs are of 2 types Directed Undirected
  • 4. Basic terms involved in graphs: Incident edge Degree of vertex Directed edge Undirected edge Path Simple path Maximum number of edges Subgraph Connected graph Completely connected graph
  • 5. Basic Term Incident edge: (vi,vj) is an edge, then edge(vi,vj) is said to be incident to vertices vi and vj
  • 6. Degree of vertex The number of edges incident onto the vertex For a directed graph Indegree of a vertex vi is the number of edges incident onto vi, with vi as the head. Outdegree of vertex vi is the number of edges incident onto vi, with vi as the tail.
  • 7. Edges are of 2 types Directed edge: A directed edge between the vertices vi and vj is an ordered pair. It is denoted by <vi,vj>. Undirected edge: An undirected edge between the vertices vi and vj is an unordered pair. It is denoted by (vi,vj). Maximum number of edges: The maximum number of edges in an undirected graph with n vertices is n(n−1)/2. In a directed graph, it is n(n−1).
  • 8. Paths Path: A path between vertices vp and vq is a sequence of vertices vp, vi1, vi2,…, vin,vq such that there exists a sequence of edges (vp, vi1), (vi1, vi2), …, ( vin, vq). Simple path: A simple path is a path given by a sequence of vertices in which all vertices are distinct except the first and the last vertices. If the first and the last vertices are same, the path will be a cycle.
  • 9. Different Types of Graphs Subgraph Connected graph Completely connected graph
  • 10. 1. Subgraphs A subgraph of a graph G = (V,E) is a graph G where V(G) is a subset of V(G). E(G) consists of edges (v1,v2) in E(G), such that both v1 and v2 are in V(G). [Note: If G = (V,E) is a graph, then V(G) is a set of vertices of G and E(G) is a set of edges of G.]
  • 11. 2. Connected Graph A graph G is said to be connected if for every pair of distinct vertices (vi,vj), there is a path from vi to vj
  • 12. 3. Completely connected graph A graph G is completely connected if, for every pair of distinct vertices (vi,vj), there exists an edge.
  • 13. Representation of graphs Graphs can be represented in 2 ways Array representation Linked list representation
  • 15. 2. Linked List representation
  • 16. Graph traversal Traversal of graph implies visiting the nodes of the graph. A graph can be traversed in 2 ways Depth first traversal Breadth first traversal
  • 17. 1. Depth First traversal When a graph is traversed by visiting the nodes in the forward (deeper) direction as long as possible, the traversal is called depth-first traversal. For example, for the graph shown in Figure, the depth-first traversal starting at the vertex 0 visits the node in the orders: 0 1 2 6 7 8 5 3 4 0 4 3 5 8 6 7 2 1
  • 18. 2. Breadth first traversal When a graph is traversed by visiting all the adjacent nodes/vertices of a node/vertex first, the traversal is called breadth-first traversal. For example, for a graph in which the breadth-first traversal starts at vertex v1, visits to the nodes take place in the order shown in Figure
  • 19. Minimum Cost spanning tree When the edges of the graph have weights representing the cost in some suitable terms, we can obtain that spanning tree of a graph whose cost is minimum in terms of the weights of the edges. For this, we start with the edge with the minimum-cost/weight, add it to set T, and mark it as visited. We next consider the edge with minimum-cost that is not yet visited, add it to T, and mark it as visited. While adding an edge to the set T, we first check whether both the vertices of the edge are visited; if they are, we do not add to the set T, because it will form a cycle. The minimum-cost spanning tree of the graph is as shown
  • 20. Thank You Find more at http://amitbiswal.blogspot.com