ݺߣ

ݺߣShare a Scribd company logo
Graphs Data Structures and Algorithms
Graphs: Term definitionGraphs are natural models that are used to represent arbitrary relationships among data objects.
Graphs are of 2 typesDirectedUndirected
Basic terms involved in graphs:Incident edgeDegree of vertexDirected edgeUndirected edgePathSimple pathMaximum number of edgesSubgraphConnected graphCompletely connected graph
Basic TermIncident edge: (vi,vj) is an edge, then edge(vi,vj) is said to be incident to vertices vi and vj
Degree of vertexThe number of edges incident onto the vertex 	For a directed graphIndegree 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 typesDirected 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).
PathsPath: 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 GraphsSubgraphConnected graphCompletely connected graph
1. SubgraphsA 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 GraphA 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 graphA graph G is completely connected if, for every pair of distinct vertices (vi,vj), there exists an edge.
Representation of graphsGraphs can be represented in 2 waysArray representationLinked list representation
1. Array Representation
2. Linked List representation
Graph traversalTraversal of graph implies visiting the nodes of the graph.A graph can be traversed in 2 waysDepth first traversalBreadth first traversal
1. Depth First traversalWhen 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 40 4 3 5 8 6 7 2 1
2. Breadth first traversalWhen 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 treeWhen 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 YouFind more at http://amitbiswal.blogspot.com

More Related Content

Graphs

  • 1. Graphs Data Structures and Algorithms
  • 2. Graphs: Term definitionGraphs are natural models that are used to represent arbitrary relationships among data objects.
  • 3. Graphs are of 2 typesDirectedUndirected
  • 4. Basic terms involved in graphs:Incident edgeDegree of vertexDirected edgeUndirected edgePathSimple pathMaximum number of edgesSubgraphConnected graphCompletely connected graph
  • 5. Basic TermIncident edge: (vi,vj) is an edge, then edge(vi,vj) is said to be incident to vertices vi and vj
  • 6. Degree of vertexThe number of edges incident onto the vertex For a directed graphIndegree 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 typesDirected 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. PathsPath: 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 GraphsSubgraphConnected graphCompletely connected graph
  • 10. 1. SubgraphsA 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 GraphA 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 graphA graph G is completely connected if, for every pair of distinct vertices (vi,vj), there exists an edge.
  • 13. Representation of graphsGraphs can be represented in 2 waysArray representationLinked list representation
  • 15. 2. Linked List representation
  • 16. Graph traversalTraversal of graph implies visiting the nodes of the graph.A graph can be traversed in 2 waysDepth first traversalBreadth first traversal
  • 17. 1. Depth First traversalWhen 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 40 4 3 5 8 6 7 2 1
  • 18. 2. Breadth first traversalWhen 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 treeWhen 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 YouFind more at http://amitbiswal.blogspot.com