{"id":475,"date":"2018-07-19T08:42:08","date_gmt":"2018-07-19T08:42:08","guid":{"rendered":"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=475"},"modified":"2018-12-12T12:10:47","modified_gmt":"2018-12-12T12:10:47","slug":"introduction-to-graphs","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/csp01\/chapter\/introduction-to-graphs\/","title":{"rendered":"Introduction to Graphs"},"content":{"raw":"<div><span style=\"float: right\"><a href=\"https:\/\/youtu.be\/WxyEnizeXjg\" target=\"_blank\" rel=\"noopener\"><img src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a>\r\n<\/span><\/div>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Welcome to the e-PG Pathshala Lecture Series on Data Structures. In this module we will discuss the fundamentals of another important data structure \u2013the graphs.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: left\"><strong>Learning Objectives<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: left\">The learning objectives of the module are as follows:<\/p>\r\n&nbsp;\r\n<p style=\"text-align: left\">\u2022 To understand the components of Graphs<\/p>\r\n<p style=\"text-align: left\">\u2022 To describe the Graph ADT<\/p>\r\n<p style=\"text-align: left\">\u2022 To discuss the different representations of Graphs<\/p>\r\n<p style=\"text-align: left\">\u2022 To analyse the different representations of Graphs<\/p>\r\n&nbsp;\r\n<p style=\"text-align: left\"><strong>32.1\u00a0 Introduction<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: left\">Graph is a data structure that consists of a set of vertices (nodes) and a set of edges between the vertices. The set of edges describes relationships among vertices. Graphs are similar to trees except they do not have as many restrictions.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">\u2022 Graphs represent relationships among data items.<\/p>\r\n<p style=\"text-align: justify\">\u2022 A <strong>graph G= (V, E)<\/strong> consists a set of <strong>vertices<\/strong>, V, and a set of <strong>edges<\/strong>, E.<\/p>\r\n<p style=\"text-align: justify\">\u2022 Each edge is a pair of vertices <em>(v, w)<\/em>, where both v, w belong to V<\/p>\r\n<p style=\"text-align: justify\">\u2022 A sub graph consists of a non-empty subset of a graph\u2019s vertices V and a subset of (possibly empty) of its <strong><em>edges<\/em><\/strong> E where each edge is between vertices that form a subset of <em>V<\/em> with cardinality 2 (an unordered pair).<\/p>\r\n&nbsp;\r\n<p style=\"text-align: left\">A graph with six vertices and seven edges is shown in Figure 32.1.<\/p>\r\n&nbsp;\r\n\r\n<img class=\"alignnone size-full wp-image-478 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-304.png\" alt=\"\" width=\"492\" height=\"182\" \/>\r\n\r\n<\/div>\r\n<div>\r\n\r\n<strong>32.2 Terminology<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">A graph is called a <strong>dense<\/strong> graph when |E| \u00bb |V| <sup>2<\/sup> and a <strong>sparse<\/strong> graph when |E| \u00bb |V|. An <strong><em>undirected graph<\/em><\/strong> is a graph where the pair of vertices are unordered and any Edge (u,v) = Edge (v,u). A graph is called a <strong><em>directed<\/em><\/strong> <strong>graph<\/strong> when each edge connects two vertices, called the source (u) and destination (v); the edge connects the source to the destination (the order is significant). A directed edge (u,v) goes from vertex u to vertex v, notated u\u00aev. A <strong><em>weighted graph<\/em><\/strong> associates weights with either the edges or the vertices. The <strong>complete graph<\/strong> is a graph in which every vertex is directly connected to every other vertex. A complete directed graph is shown in Fig 32.2. The number of edges in a complete directed graph with N vertices is given by <em>N * (N-1) is of the order of O(N<\/em><em>2<\/em><em>)<\/em> (Figure 32.2). A path is a sequence of vertices that connect two nodes in a graph. The <strong>length of a<\/strong> <strong>path <\/strong>is the number of edges on it. A Path is called<strong> simple <\/strong>if vertices in the sequence are distinct.<\/p>\r\n&nbsp;\r\n\r\n<img class=\"alignnone size-full wp-image-479 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-305.png\" alt=\"\" width=\"402\" height=\"232\" \/>\r\n<p style=\"text-align: justify\">Two nodes of an undirected graph are <strong>called adjacent nodes<\/strong> if they are connected by an edge. If (v0, v1) is an edge in an undirected graph, then vertices v0 and v1 are said to be adjacent. The edge (v0, v1) is incident on vertices v0 and v1. If &lt;v0, v1&gt; is an edge in a directed graph where v0 is the source node and v1 is the destination node then v0 is said to be <strong>adjacent to v1<\/strong>, and v1 is said to be <strong>adjacent from v0<\/strong>. The edge &lt;v0, v1&gt; is incident on v0 and v1. <strong>A<\/strong> <strong><em>forest<\/em><\/strong> is an acyclic graph, and a <em>tree<\/em> is a connected acyclic graph. <strong>A subgraph<\/strong> of G is a graph G\u2019 such that vertices V(G\u2019) is a subset of veritices V(G) and edges E(G\u2019) is a subset of edges E(G) between vertices that are from the subset V(G\u2019). In other words a subgraph of <em>G<\/em> is a graph <em>G<\/em>\u2019 such that V(<em>G<\/em>\u2019) \u00cd V(<em>G<\/em>) and E(<em>G<\/em>\u2019) \u00cd E(<em>G<\/em>).<\/p>\r\n&nbsp;\r\n\r\nExamples of subgraphs are shown in Fig 32.3\r\n\r\n&nbsp;\r\n\r\n<img class=\"alignnone size-full wp-image-480 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-306.png\" alt=\"\" width=\"509\" height=\"204\" \/>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">32.2.1 Connected Component<\/strong>\r\n\r\n&nbsp;\r\n\r\n<span style=\"text-align: justify;font-size: 1em\">In an undirected graph G, two vertices, <\/span><em style=\"text-align: justify;font-size: 1em\">v<\/em><span style=\"text-align: justify;font-size: 1em\">0 and <\/span><em style=\"text-align: justify;font-size: 1em\">v<\/em><span style=\"text-align: justify;font-size: 1em\">1, are connected if there is a path in <\/span><em style=\"text-align: justify;font-size: 1em\">G <\/em><span style=\"text-align: justify;font-size: 1em\">from<\/span><em style=\"text-align: justify;font-size: 1em\"> v<\/em><span style=\"text-align: justify;font-size: 1em\">0 to<\/span><em style=\"text-align: justify;font-size: 1em\"> v<\/em><span style=\"text-align: justify;font-size: 1em\">1. An undirected graph is connected if, for every pair of distinct vertices<\/span><em style=\"text-align: justify;font-size: 1em\"> v<\/em><span style=\"text-align: justify;font-size: 1em\">i,<\/span><em style=\"text-align: justify;font-size: 1em\"> v<\/em><span style=\"text-align: justify;font-size: 1em\">j, there is a path from<\/span><em style=\"text-align: justify;font-size: 1em\"> v<\/em><span style=\"text-align: justify;font-size: 1em\">i to<\/span><em style=\"text-align: justify;font-size: 1em\"> v<\/em><span style=\"text-align: justify;font-size: 1em\">j A connected component of an undirected graph is a maximal sub-graph that is connected . A completely connected graph has exactly 1 component. Example of connected components and not a component are shown in Fig 32.4.<\/span>\r\n\r\n&nbsp;\r\n\r\n<span style=\"text-align: justify;font-size: 1em\">A directed graph is strongly connected if there is a directed path from <\/span><em style=\"text-align: justify;font-size: 1em\">vi<\/em><span style=\"text-align: justify;font-size: 1em\"> to <\/span><em style=\"text-align: justify;font-size: 1em\">vj<\/em><span style=\"text-align: justify;font-size: 1em\"> and also from <\/span><em style=\"text-align: justify;font-size: 1em\">vj<\/em><span style=\"text-align: justify;font-size: 1em\"> to <\/span><em style=\"text-align: justify;font-size: 1em\">vi.<\/em><span style=\"text-align: justify;font-size: 1em\"> A strongly connected component is a maximal subgraph that is strongly connected.<\/span>\r\n\r\n<\/div>\r\n<div>\r\n\r\n<img class=\"alignnone size-full wp-image-481 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-307.png\" alt=\"\" width=\"629\" height=\"255\" \/>\r\n\r\n&nbsp;\r\n\r\n<strong>32.2.2 Degree<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The degree of a vertex in an undirected graph is the number of edges incident to that vertex. If <em>d<\/em><em>i<\/em> is the degree of a vertex <em>i<\/em> in an undirected graph <em>G<\/em> with <em>n<\/em> vertices and <em>e<\/em> edges, the number of edges is<\/p>\r\n&nbsp;\r\n\r\n<img class=\"alignnone size-full wp-image-482 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-308.png\" alt=\"\" width=\"594\" height=\"379\" \/>\r\n\r\n<\/div>\r\n<div>\r\n<p style=\"text-align: justify\">For a directed graph, the in-degree of a vertex <em>v<\/em> is the number of incoming edges that have <em>v<\/em> as the head and the out-degree of a vertex <em>v<\/em> is the number of outgoing edges that have <em>v<\/em> as the tail. For a complete directed graph the number of edges = n(n-1) edges<\/p>\r\n&nbsp;\r\n\r\n<strong>32.3 Trees as Graphs<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Every tree is a connected acyclic graph that is a graph with some restrictions as shown in Fig 32.6. The restrictions are that the tree is rooted, <em>directed,<\/em> there are <em>no<\/em> <em>cycles <\/em>and there is a<em> directed path from the <\/em>root<em> to every node.<\/em><\/p>\r\n<img class=\"alignnone size-full wp-image-483 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-309.png\" alt=\"\" width=\"330\" height=\"269\" \/>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Each of the red areas breaks one of these constraints. In the tree the direction of the edge is assumed to be from a node to another node that is at a lower level though the direction is not explicitly shown. In the figure 32.6, 1 shows the direction is from lower level node to higher level and is not allowed in a tree. 2 shows the presence of a cycle while 3 violates the condition that there must be a directed path from the root to every node.<\/p>\r\n&nbsp;\r\n\r\n<strong>32.4\u00a0 Why Use Graphs?<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Graphs can be used to model a wide range of applications. When we design the model we need to decide on what components of the application represent the vertices and what connections between these components represent the edges. Examples of such applications include the following:<\/p>\r\n&nbsp;\r\n\r\n\u2022 Intersections and streets within a city\r\n\r\n\u2022 Roads\/trains\/airline routes connecting cities\/countries\r\n\r\n\u2022 Computer networks\r\n\r\n\u2022 Electronic circuits\r\n\r\n\u2022 A layout of an adventure game world\r\n\r\n\u2022 A schematic of the computers and connections that make up the Internet\r\n\r\n\u2022 The links between pages on the Web\r\n\r\n\u2022 The relationship between students and courses\r\n\r\n\u2022\u00a0 A diagram of the flow capacities in a communications or transportation network\r\n\r\n<\/div>\r\n&nbsp;\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">32.4.1 Application1 \u2013Air Flight System (Fig 32.8)<\/strong>\r\n<div>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">In this application, each vertex of the graph represents a city and each edge represents a direct flight between two cities. In this case a query on direct flights is equivalent to a query on whether an edge exists. A query on how to get to a location is equivalent to finding whether a path exists from A to B. We can even associate costs to edges (weighted graphs), then ask \u201cwhat is the cheapest path from A to B\u201d .<\/p>\r\n&nbsp;\r\n\r\n<img class=\"alignnone size-full wp-image-484 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-310.png\" alt=\"\" width=\"599\" height=\"515\" \/>\r\n<p style=\"text-align: justify\">This application can be represented by a weighted complete graph (every two vertices are connected by an edge) (Figure32.9). Each path represents the Euclidean distance between two stations . Each station uses a certain power i to transmit messages. Given this power i, only a few nodes can be reached (bold edges). A station reachable by i then uses its own power to relay the message to other stations not reachable by i. A typical wireless communication problem is: how to broadcast between <em>all<\/em> stations such that they are all connected and the power consumption is minimized. This is essentially the shortest path finding problem.<\/p>\r\n&nbsp;\r\n\r\n<strong>32.5<\/strong>\u00a0<strong>Representation of Graphs<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Three popular computer representations of a graph represent the vertex set and the edge set, but in different ways.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">32.5.1 Adjacency Matrix<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"font-size: 1em\">This representation uses a 2D matrix to represent the graph. That is it is represented as a square grid of Boolean values. Therefore if the graph contains N vertices, then the grid contains N rows and N columns. For two vertices numbered I and J, the element at row I and column J is true if there is an edge from I to J, otherwise it is false.<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">The Matrix of will be of size |V| x |V|<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n<ul>\r\n \t<li>One row and one column of the grid or matrix for each vertex In the case of a directed graph<\/li>\r\n \t<li style=\"text-align: justify\">a cell in the matrix (row i and column j) contains a 1 if an edge exists from i to j, 0 if the edge does not exist.<\/li>\r\n \t<li style=\"text-align: justify\">two cells in the matrix (row i and column j and row j and column i) both will contains a 1 if an edge between i and j, 0 if the edge does not exist.<\/li>\r\n<\/ul>\r\n<p style=\"text-align: justify\">The adjacency matrix for a directed graph is shown in Figure 32.10. <strong>Space<\/strong> <strong>requirements: <\/strong>For a graph with <em>n<\/em> nodes, adjacency matrices take <em>\u0398(n<\/em><sup><em>2<\/em><\/sup><em>)<\/em> space.<\/p>\r\n&nbsp;\r\n\r\n<img class=\"alignnone size-full wp-image-485 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-311.png\" alt=\"\" width=\"636\" height=\"558\" \/>\r\n\r\n<\/div>\r\n<strong>\u00a0<\/strong><span style=\"text-align: justify;font-size: 1em\">The adjacency matrix representation of a weighted graph is now discussed. The edges of a graph have weights assigned to them. These weights may represent the distance from one vertex to another or the cost of going from one vertex to another adjacent vertex. In the case of a weighted graph, matrix can contain the weight instead of 1. Now the adjacency matrix: <\/span><em style=\"text-align: justify;font-size: 1em\">adj_mat<\/em><span style=\"text-align: justify;font-size: 1em\">[<\/span><em style=\"text-align: justify;font-size: 1em\">i<\/em><span style=\"text-align: justify;font-size: 1em\">][<\/span><em style=\"text-align: justify;font-size: 1em\">j<\/em><span style=\"text-align: justify;font-size: 1em\">] would keep the weights. Now we add a <\/span><em style=\"text-align: justify;font-size: 1em\">weight<\/em><span style=\"text-align: justify;font-size: 1em\"> field to the node structure. A graph with weighted edges is called a <\/span><em style=\"text-align: justify;font-size: 1em\">netwo<strong>rk.<\/strong><\/em>\r\n<div>\r\n\r\n<img class=\"alignnone size-full wp-image-486 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-312.png\" alt=\"\" width=\"607\" height=\"312\" \/>\r\n<p style=\"text-align: justify\">For an undirected graph, the degree of any vertex, <em>i<\/em>, is its row sum. For a directed graph, the row sum is the out-degree, while the column sum is the in-degree. The time complexity of checking edge number or examining if <em>G<\/em> is a connected graph is of the order of O(<em>n<\/em>2\/2) if G is undirected and of the order of O(<em>n<\/em>2) if G is directed.<\/p>\r\n&nbsp;\r\n\r\n<strong>32.5.2 Adjacency List<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">In this representation we use a 1D array of linked lists. There is one list for each vertex in <em>G<\/em>. The nodes in list <em>i<\/em> represent the vertices that are adjacent to vertex <em>i.<\/em> For an undirected graph with <em>n<\/em> vertices and <em>e<\/em> edges, this representation requires <em>n<\/em> head nodes and n lists and 2<em>e<\/em> list nodes. A |V|-ary list (array) in which each entry stores a list (linked list) of all adjacent vertices. The <em>adjacency list<\/em> representation of a graph <em>G = (V,E)<\/em> consists of an array <em>Adj[1..|V|] <\/em>of lists. Each list<em> Adj[v] <\/em>is a list of all vertices adjacent to<em> v<\/em>. Figure 32. 13 shows the adjacency list for a simple directed graph. Figures 32.14 shows the adjacency list for a undirected graph while Figure 32.15 shows the adjacency list representation for the same graph but now directed.<\/p>\r\n\r\n<\/div>\r\n<img class=\"alignnone size-full wp-image-487 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-313.png\" alt=\"\" width=\"548\" height=\"424\" \/>\r\n<div>\r\n\r\n<img class=\"size-full wp-image-488 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-314.png\" alt=\"\" width=\"465\" height=\"304\" \/>\r\n\r\n<\/div>\r\n&nbsp;\r\n\r\n<strong>32.5.2.1 Adjacency List- Operations<\/strong>\r\n\r\n&nbsp;\r\n\r\n<span style=\"text-align: justify;font-size: 1em\">The following are the graph operations associated with the adjacency list representation. The degree of a vertex in an undirected graph is the number of nodes in the adjacency list. The number of edges in a graph is determined in time of the order O(<\/span><em style=\"text-align: justify;font-size: 1em\">n<\/em><span style=\"text-align: justify;font-size: 1em\">+<\/span><em style=\"text-align: justify;font-size: 1em\">e<\/em><span style=\"text-align: justify;font-size: 1em\">). The out-degree of a vertex in a directed graph is the number of nodes in its adjacency list. However to find the in-degree of a vertex in a directed graph we need to traverse the whole data structure.<\/span>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n<strong>32.5.2.2 Sequential Representation of Adjacency Lists<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">We will now discuss the sequential representation of adjacency lists. Here we sequentially pack the nodes on the adjacency lists (Fig 32.16). Here <em>node<\/em>[1] ~ <em>node<\/em>[<em>n<\/em>+2<em>e<\/em>+1] may be used. The vertices adjacent from vertex<em> i <\/em>are stored in\u00a0\u00a0<em style=\"text-align: initial;font-size: 1em\">node<\/em><span style=\"text-align: initial;font-size: 1em\">[<\/span><em style=\"text-align: initial;font-size: 1em\">node<\/em><span style=\"text-align: initial;font-size: 1em\">[<\/span><em style=\"text-align: initial;font-size: 1em\">i<\/em><span style=\"text-align: initial;font-size: 1em\">]], \u2026 ,<\/span><em style=\"text-align: initial;font-size: 1em\"> node<\/em><span style=\"text-align: initial;font-size: 1em\">[<\/span><em style=\"text-align: initial;font-size: 1em\">node<\/em><span style=\"text-align: initial;font-size: 1em\">[<\/span><em style=\"text-align: initial;font-size: 1em\">i<\/em><span style=\"text-align: initial;font-size: 1em\">+1]-1], 0\u2266<\/span><em style=\"text-align: initial;font-size: 1em\">i<\/em><span style=\"text-align: initial;font-size: 1em\">&lt;<\/span><em style=\"text-align: initial;font-size: 1em\">n. <\/em><span style=\"text-align: initial;font-size: 1em\">The number of edges in<\/span><em style=\"text-align: initial;font-size: 1em\"> G <\/em><span style=\"text-align: initial;font-size: 1em\">may be determined in O(<\/span><em style=\"text-align: initial;font-size: 1em\">n<\/em><span style=\"text-align: initial;font-size: 1em\">+<\/span><em style=\"text-align: initial;font-size: 1em\">e<\/em><span style=\"text-align: initial;font-size: 1em\">)<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n<span style=\"background-color: #ff99cc\">node[0] \u2026 node[n-1]: starting point for vertices<\/span>\r\n\r\n<span style=\"background-color: #ff99cc\">node[n]: n+2e+1<\/span>\r\n\r\n<span style=\"background-color: #ff99cc\">node[n+1] \u2026 node[n+2e]: head node of edge<\/span>\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n<img class=\"alignnone size-full wp-image-489 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-315.png\" alt=\"\" width=\"616\" height=\"386\" \/>\r\n\r\n&nbsp;\r\n\r\nHere we use the node 0 to n+2e i.e 8+2*7= 22\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Node 0 shows the location of the node where edges for vertex 0 starts (in our example 9), node 1 shows where the edges for 1 starts (in our example 11) and son on. In node 9 we have the edge with 0 (0-1) as edge while in node 10 we the next edge of 0 (0-2). Similarly in node 11 we have the edge with 1 (1 -0) as edge while in node 12 we the next edge of 1 (0-3) and so on.<\/p>\r\n&nbsp;\r\n\r\n<strong>32.5.3 Adjacency Multi-list<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">An edge in an undirected graph is represented by two nodes in adjacency list representation. Lists in which nodes may be shared among several lists that is a vertex shared by two different paths is called as adjacency multi-lists. There is exactly one node for each edge. This node is on the adjacency list for each of the two vertices it is incident to. Each node in the list is represented as given in Figure 32.17. An example of adjacency multi-list for an undirected graph is shown in Fig 32.18.<\/p>\r\n&nbsp;\r\n\r\n<img class=\"alignnone size-full wp-image-490 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-316.png\" alt=\"\" width=\"464\" height=\"75\" \/>\r\n\r\n<\/div>\r\n<div>\r\n<p style=\"text-align: center\"><strong>Figure 32.17 Node in an Adjacency Multi-list<\/strong><\/p>\r\n&nbsp;\r\n\r\n<img class=\"alignnone size-full wp-image-491 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-317.png\" alt=\"\" width=\"624\" height=\"333\" \/>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">In Figure 32.18, the number of nodes is 4, the number of edges is 6. The Multi -list shows the structure where N1 shows the path with vertices 0 and 1 corresponding to edges (0-1) as well as (1-0) (since the example is an undirected graph). The first different path N2 containing first vertex 0 is shown next and the first different path N4 with vertex 1 is shown next. Next we go to N2 corresponding to path with vertices 0 and 2. Now N3 is the next path with 0 while N4 is the next path with 2. Next is N3 corresponding to path with vertices 0 and 3. Now there is no other path with 0 while N5 is the next path with 3. Next is N4 corresponding to path with vertices 1 and 2. Now N5 is the next path with 1 while N6 is the next path with 2. Next is N5 corresponding to path with vertices 1 and 3. Now there is no other path with 2 while N6 is the next path with 3. Finally we see N6 corresponding to path with vertices 2 and 3. Now we have processed all paths and there are no more paths to consider.<\/p>\r\n&nbsp;\r\n\r\n<strong>Analysis (Adjacency Matrix vs Adjacency List)<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Now we will discuss the time complexity of graph operations when using adjacency matrix or adjacency list is used. For adding or removing edges in case of adjacency matrix the time needed will be a small constant but for adjacency list it will be of the order O(N) where N is the number of vertices in the graph. Checking if an edge is present for the adjacency matrix representation time taken will be a small constant, however in the case of adjacency list the time taken is of the order O(N) where the linked adjacency list has linear running time with the length of this list, on the average. Now for iterating through a vertex\u2019s edges the adjacency matrix takes time of the order of O(N) while for the adjacency list it is of the order O(E) where E is the number of edges in the graph. For finding all of the vertices adjacent to a given vertex, the adjacency list tends to support this operation more efficiently than the adjacency matrix. Both take of the order of O(<em>N<\/em>) in worst case (i.e., when we are dealing with a complete graph). Now regarding the memory requirement, the adjacency matrix always requires <em>N<\/em>2 cells while adjacency list requires an array of <em>N\u00a0<\/em><span style=\"text-align: initial;font-size: 1em\">pointers and a number of nodes equal to twice the number of edges in the case of an undirected graph.<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">32.5.4 Choice of Implementation<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"font-size: 1em\">The choice which representation to use is normally based on which operations are more frequent and whether a good set ADT is available. It also depends on the average number of edges per vertex, since the adjacency matrix is wasteful for sparse graphs, since we need W(n<\/span><sup>2<\/sup><span style=\"font-size: 1em\">) space.<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">Summary<\/strong><\/p>\r\n\r\n<\/div>\r\n<ul>\r\n \t<li>Explained the components of Graphs<\/li>\r\n \t<li>Described the Graph ADT<\/li>\r\n \t<li>Discussed the different representations of Graphs<\/li>\r\n \t<li>Analysed the different representations of Graphs<\/li>\r\n<\/ul>\r\n<table>\r\n<tbody>\r\n<tr>\r\n<td><strong>you can view video on Introduction to Graphs<\/strong><\/td>\r\n<td><a href=\"https:\/\/youtu.be\/WxyEnizeXjg\" target=\"_blank\" rel=\"noopener\"><img class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n\r\n<img class=\"size-full wp-image-492 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-318.png\" alt=\"\" width=\"609\" height=\"161\" \/>","rendered":"<div><span style=\"float: right\"><a href=\"https:\/\/youtu.be\/WxyEnizeXjg\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a><br \/>\n<\/span><\/div>\n<div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Welcome to the e-PG Pathshala Lecture Series on Data Structures. In this module we will discuss the fundamentals of another important data structure \u2013the graphs.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: left\"><strong>Learning Objectives<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: left\">The learning objectives of the module are as follows:<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: left\">\u2022 To understand the components of Graphs<\/p>\n<p style=\"text-align: left\">\u2022 To describe the Graph ADT<\/p>\n<p style=\"text-align: left\">\u2022 To discuss the different representations of Graphs<\/p>\n<p style=\"text-align: left\">\u2022 To analyse the different representations of Graphs<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: left\"><strong>32.1\u00a0 Introduction<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: left\">Graph is a data structure that consists of a set of vertices (nodes) and a set of edges between the vertices. The set of edges describes relationships among vertices. Graphs are similar to trees except they do not have as many restrictions.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">\u2022 Graphs represent relationships among data items.<\/p>\n<p style=\"text-align: justify\">\u2022 A <strong>graph G= (V, E)<\/strong> consists a set of <strong>vertices<\/strong>, V, and a set of <strong>edges<\/strong>, E.<\/p>\n<p style=\"text-align: justify\">\u2022 Each edge is a pair of vertices <em>(v, w)<\/em>, where both v, w belong to V<\/p>\n<p style=\"text-align: justify\">\u2022 A sub graph consists of a non-empty subset of a graph\u2019s vertices V and a subset of (possibly empty) of its <strong><em>edges<\/em><\/strong> E where each edge is between vertices that form a subset of <em>V<\/em> with cardinality 2 (an unordered pair).<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: left\">A graph with six vertices and seven edges is shown in Figure 32.1.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-478 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-304.png\" alt=\"\" width=\"492\" height=\"182\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-304.png 492w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-304-300x111.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-304-65x24.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-304-225x83.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-304-350x129.png 350w\" sizes=\"auto, (max-width: 492px) 100vw, 492px\" \/><\/p>\n<\/div>\n<div>\n<p><strong>32.2 Terminology<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">A graph is called a <strong>dense<\/strong> graph when |E| \u00bb |V| <sup>2<\/sup> and a <strong>sparse<\/strong> graph when |E| \u00bb |V|. An <strong><em>undirected graph<\/em><\/strong> is a graph where the pair of vertices are unordered and any Edge (u,v) = Edge (v,u). A graph is called a <strong><em>directed<\/em><\/strong> <strong>graph<\/strong> when each edge connects two vertices, called the source (u) and destination (v); the edge connects the source to the destination (the order is significant). A directed edge (u,v) goes from vertex u to vertex v, notated u\u00aev. A <strong><em>weighted graph<\/em><\/strong> associates weights with either the edges or the vertices. The <strong>complete graph<\/strong> is a graph in which every vertex is directly connected to every other vertex. A complete directed graph is shown in Fig 32.2. The number of edges in a complete directed graph with N vertices is given by <em>N * (N-1) is of the order of O(N<\/em><em>2<\/em><em>)<\/em> (Figure 32.2). A path is a sequence of vertices that connect two nodes in a graph. The <strong>length of a<\/strong> <strong>path <\/strong>is the number of edges on it. A Path is called<strong> simple <\/strong>if vertices in the sequence are distinct.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-479 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-305.png\" alt=\"\" width=\"402\" height=\"232\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-305.png 402w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-305-300x173.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-305-65x38.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-305-225x130.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-305-350x202.png 350w\" sizes=\"auto, (max-width: 402px) 100vw, 402px\" \/><\/p>\n<p style=\"text-align: justify\">Two nodes of an undirected graph are <strong>called adjacent nodes<\/strong> if they are connected by an edge. If (v0, v1) is an edge in an undirected graph, then vertices v0 and v1 are said to be adjacent. The edge (v0, v1) is incident on vertices v0 and v1. If &lt;v0, v1&gt; is an edge in a directed graph where v0 is the source node and v1 is the destination node then v0 is said to be <strong>adjacent to v1<\/strong>, and v1 is said to be <strong>adjacent from v0<\/strong>. The edge &lt;v0, v1&gt; is incident on v0 and v1. <strong>A<\/strong> <strong><em>forest<\/em><\/strong> is an acyclic graph, and a <em>tree<\/em> is a connected acyclic graph. <strong>A subgraph<\/strong> of G is a graph G\u2019 such that vertices V(G\u2019) is a subset of veritices V(G) and edges E(G\u2019) is a subset of edges E(G) between vertices that are from the subset V(G\u2019). In other words a subgraph of <em>G<\/em> is a graph <em>G<\/em>\u2019 such that V(<em>G<\/em>\u2019) \u00cd V(<em>G<\/em>) and E(<em>G<\/em>\u2019) \u00cd E(<em>G<\/em>).<\/p>\n<p>&nbsp;<\/p>\n<p>Examples of subgraphs are shown in Fig 32.3<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-480 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-306.png\" alt=\"\" width=\"509\" height=\"204\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-306.png 509w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-306-300x120.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-306-65x26.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-306-225x90.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-306-350x140.png 350w\" sizes=\"auto, (max-width: 509px) 100vw, 509px\" \/><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">32.2.1 Connected Component<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"text-align: justify;font-size: 1em\">In an undirected graph G, two vertices, <\/span><em style=\"text-align: justify;font-size: 1em\">v<\/em><span style=\"text-align: justify;font-size: 1em\">0 and <\/span><em style=\"text-align: justify;font-size: 1em\">v<\/em><span style=\"text-align: justify;font-size: 1em\">1, are connected if there is a path in <\/span><em style=\"text-align: justify;font-size: 1em\">G <\/em><span style=\"text-align: justify;font-size: 1em\">from<\/span><em style=\"text-align: justify;font-size: 1em\"> v<\/em><span style=\"text-align: justify;font-size: 1em\">0 to<\/span><em style=\"text-align: justify;font-size: 1em\"> v<\/em><span style=\"text-align: justify;font-size: 1em\">1. An undirected graph is connected if, for every pair of distinct vertices<\/span><em style=\"text-align: justify;font-size: 1em\"> v<\/em><span style=\"text-align: justify;font-size: 1em\">i,<\/span><em style=\"text-align: justify;font-size: 1em\"> v<\/em><span style=\"text-align: justify;font-size: 1em\">j, there is a path from<\/span><em style=\"text-align: justify;font-size: 1em\"> v<\/em><span style=\"text-align: justify;font-size: 1em\">i to<\/span><em style=\"text-align: justify;font-size: 1em\"> v<\/em><span style=\"text-align: justify;font-size: 1em\">j A connected component of an undirected graph is a maximal sub-graph that is connected . A completely connected graph has exactly 1 component. Example of connected components and not a component are shown in Fig 32.4.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"text-align: justify;font-size: 1em\">A directed graph is strongly connected if there is a directed path from <\/span><em style=\"text-align: justify;font-size: 1em\">vi<\/em><span style=\"text-align: justify;font-size: 1em\"> to <\/span><em style=\"text-align: justify;font-size: 1em\">vj<\/em><span style=\"text-align: justify;font-size: 1em\"> and also from <\/span><em style=\"text-align: justify;font-size: 1em\">vj<\/em><span style=\"text-align: justify;font-size: 1em\"> to <\/span><em style=\"text-align: justify;font-size: 1em\">vi.<\/em><span style=\"text-align: justify;font-size: 1em\"> A strongly connected component is a maximal subgraph that is strongly connected.<\/span><\/p>\n<\/div>\n<div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-481 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-307.png\" alt=\"\" width=\"629\" height=\"255\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-307.png 629w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-307-300x122.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-307-65x26.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-307-225x91.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-307-350x142.png 350w\" sizes=\"auto, (max-width: 629px) 100vw, 629px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>32.2.2 Degree<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The degree of a vertex in an undirected graph is the number of edges incident to that vertex. If <em>d<\/em><em>i<\/em> is the degree of a vertex <em>i<\/em> in an undirected graph <em>G<\/em> with <em>n<\/em> vertices and <em>e<\/em> edges, the number of edges is<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-482 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-308.png\" alt=\"\" width=\"594\" height=\"379\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-308.png 594w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-308-300x191.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-308-65x41.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-308-225x144.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-308-350x223.png 350w\" sizes=\"auto, (max-width: 594px) 100vw, 594px\" \/><\/p>\n<\/div>\n<div>\n<p style=\"text-align: justify\">For a directed graph, the in-degree of a vertex <em>v<\/em> is the number of incoming edges that have <em>v<\/em> as the head and the out-degree of a vertex <em>v<\/em> is the number of outgoing edges that have <em>v<\/em> as the tail. For a complete directed graph the number of edges = n(n-1) edges<\/p>\n<p>&nbsp;<\/p>\n<p><strong>32.3 Trees as Graphs<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Every tree is a connected acyclic graph that is a graph with some restrictions as shown in Fig 32.6. The restrictions are that the tree is rooted, <em>directed,<\/em> there are <em>no<\/em> <em>cycles <\/em>and there is a<em> directed path from the <\/em>root<em> to every node.<\/em><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-483 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-309.png\" alt=\"\" width=\"330\" height=\"269\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-309.png 330w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-309-300x245.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-309-65x53.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-309-225x183.png 225w\" sizes=\"auto, (max-width: 330px) 100vw, 330px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Each of the red areas breaks one of these constraints. In the tree the direction of the edge is assumed to be from a node to another node that is at a lower level though the direction is not explicitly shown. In the figure 32.6, 1 shows the direction is from lower level node to higher level and is not allowed in a tree. 2 shows the presence of a cycle while 3 violates the condition that there must be a directed path from the root to every node.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>32.4\u00a0 Why Use Graphs?<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Graphs can be used to model a wide range of applications. When we design the model we need to decide on what components of the application represent the vertices and what connections between these components represent the edges. Examples of such applications include the following:<\/p>\n<p>&nbsp;<\/p>\n<p>\u2022 Intersections and streets within a city<\/p>\n<p>\u2022 Roads\/trains\/airline routes connecting cities\/countries<\/p>\n<p>\u2022 Computer networks<\/p>\n<p>\u2022 Electronic circuits<\/p>\n<p>\u2022 A layout of an adventure game world<\/p>\n<p>\u2022 A schematic of the computers and connections that make up the Internet<\/p>\n<p>\u2022 The links between pages on the Web<\/p>\n<p>\u2022 The relationship between students and courses<\/p>\n<p>\u2022\u00a0 A diagram of the flow capacities in a communications or transportation network<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">32.4.1 Application1 \u2013Air Flight System (Fig 32.8)<\/strong><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In this application, each vertex of the graph represents a city and each edge represents a direct flight between two cities. In this case a query on direct flights is equivalent to a query on whether an edge exists. A query on how to get to a location is equivalent to finding whether a path exists from A to B. We can even associate costs to edges (weighted graphs), then ask \u201cwhat is the cheapest path from A to B\u201d .<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-484 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-310.png\" alt=\"\" width=\"599\" height=\"515\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-310.png 599w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-310-300x258.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-310-65x56.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-310-225x193.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-310-350x301.png 350w\" sizes=\"auto, (max-width: 599px) 100vw, 599px\" \/><\/p>\n<p style=\"text-align: justify\">This application can be represented by a weighted complete graph (every two vertices are connected by an edge) (Figure32.9). Each path represents the Euclidean distance between two stations . Each station uses a certain power i to transmit messages. Given this power i, only a few nodes can be reached (bold edges). A station reachable by i then uses its own power to relay the message to other stations not reachable by i. A typical wireless communication problem is: how to broadcast between <em>all<\/em> stations such that they are all connected and the power consumption is minimized. This is essentially the shortest path finding problem.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>32.5<\/strong>\u00a0<strong>Representation of Graphs<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Three popular computer representations of a graph represent the vertex set and the edge set, but in different ways.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">32.5.1 Adjacency Matrix<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"font-size: 1em\">This representation uses a 2D matrix to represent the graph. That is it is represented as a square grid of Boolean values. Therefore if the graph contains N vertices, then the grid contains N rows and N columns. For two vertices numbered I and J, the element at row I and column J is true if there is an edge from I to J, otherwise it is false.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">The Matrix of will be of size |V| x |V|<\/span><\/p>\n<\/div>\n<div>\n<ul>\n<li>One row and one column of the grid or matrix for each vertex In the case of a directed graph<\/li>\n<li style=\"text-align: justify\">a cell in the matrix (row i and column j) contains a 1 if an edge exists from i to j, 0 if the edge does not exist.<\/li>\n<li style=\"text-align: justify\">two cells in the matrix (row i and column j and row j and column i) both will contains a 1 if an edge between i and j, 0 if the edge does not exist.<\/li>\n<\/ul>\n<p style=\"text-align: justify\">The adjacency matrix for a directed graph is shown in Figure 32.10. <strong>Space<\/strong> <strong>requirements: <\/strong>For a graph with <em>n<\/em> nodes, adjacency matrices take <em>\u0398(n<\/em><sup><em>2<\/em><\/sup><em>)<\/em> space.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-485 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-311.png\" alt=\"\" width=\"636\" height=\"558\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-311.png 636w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-311-300x263.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-311-65x57.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-311-225x197.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-311-350x307.png 350w\" sizes=\"auto, (max-width: 636px) 100vw, 636px\" \/><\/p>\n<\/div>\n<p><strong>\u00a0<\/strong><span style=\"text-align: justify;font-size: 1em\">The adjacency matrix representation of a weighted graph is now discussed. The edges of a graph have weights assigned to them. These weights may represent the distance from one vertex to another or the cost of going from one vertex to another adjacent vertex. In the case of a weighted graph, matrix can contain the weight instead of 1. Now the adjacency matrix: <\/span><em style=\"text-align: justify;font-size: 1em\">adj_mat<\/em><span style=\"text-align: justify;font-size: 1em\">[<\/span><em style=\"text-align: justify;font-size: 1em\">i<\/em><span style=\"text-align: justify;font-size: 1em\">][<\/span><em style=\"text-align: justify;font-size: 1em\">j<\/em><span style=\"text-align: justify;font-size: 1em\">] would keep the weights. Now we add a <\/span><em style=\"text-align: justify;font-size: 1em\">weight<\/em><span style=\"text-align: justify;font-size: 1em\"> field to the node structure. A graph with weighted edges is called a <\/span><em style=\"text-align: justify;font-size: 1em\">netwo<strong>rk.<\/strong><\/em><\/p>\n<div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-486 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-312.png\" alt=\"\" width=\"607\" height=\"312\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-312.png 607w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-312-300x154.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-312-65x33.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-312-225x116.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-312-350x180.png 350w\" sizes=\"auto, (max-width: 607px) 100vw, 607px\" \/><\/p>\n<p style=\"text-align: justify\">For an undirected graph, the degree of any vertex, <em>i<\/em>, is its row sum. For a directed graph, the row sum is the out-degree, while the column sum is the in-degree. The time complexity of checking edge number or examining if <em>G<\/em> is a connected graph is of the order of O(<em>n<\/em>2\/2) if G is undirected and of the order of O(<em>n<\/em>2) if G is directed.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>32.5.2 Adjacency List<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In this representation we use a 1D array of linked lists. There is one list for each vertex in <em>G<\/em>. The nodes in list <em>i<\/em> represent the vertices that are adjacent to vertex <em>i.<\/em> For an undirected graph with <em>n<\/em> vertices and <em>e<\/em> edges, this representation requires <em>n<\/em> head nodes and n lists and 2<em>e<\/em> list nodes. A |V|-ary list (array) in which each entry stores a list (linked list) of all adjacent vertices. The <em>adjacency list<\/em> representation of a graph <em>G = (V,E)<\/em> consists of an array <em>Adj[1..|V|] <\/em>of lists. Each list<em> Adj[v] <\/em>is a list of all vertices adjacent to<em> v<\/em>. Figure 32. 13 shows the adjacency list for a simple directed graph. Figures 32.14 shows the adjacency list for a undirected graph while Figure 32.15 shows the adjacency list representation for the same graph but now directed.<\/p>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-487 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-313.png\" alt=\"\" width=\"548\" height=\"424\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-313.png 548w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-313-300x232.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-313-65x50.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-313-225x174.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-313-350x271.png 350w\" sizes=\"auto, (max-width: 548px) 100vw, 548px\" \/><\/p>\n<div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-488 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-314.png\" alt=\"\" width=\"465\" height=\"304\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-314.png 465w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-314-300x196.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-314-65x42.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-314-225x147.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-314-350x229.png 350w\" sizes=\"auto, (max-width: 465px) 100vw, 465px\" \/><\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong>32.5.2.1 Adjacency List- Operations<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"text-align: justify;font-size: 1em\">The following are the graph operations associated with the adjacency list representation. The degree of a vertex in an undirected graph is the number of nodes in the adjacency list. The number of edges in a graph is determined in time of the order O(<\/span><em style=\"text-align: justify;font-size: 1em\">n<\/em><span style=\"text-align: justify;font-size: 1em\">+<\/span><em style=\"text-align: justify;font-size: 1em\">e<\/em><span style=\"text-align: justify;font-size: 1em\">). The out-degree of a vertex in a directed graph is the number of nodes in its adjacency list. However to find the in-degree of a vertex in a directed graph we need to traverse the whole data structure.<\/span><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p><strong>32.5.2.2 Sequential Representation of Adjacency Lists<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">We will now discuss the sequential representation of adjacency lists. Here we sequentially pack the nodes on the adjacency lists (Fig 32.16). Here <em>node<\/em>[1] ~ <em>node<\/em>[<em>n<\/em>+2<em>e<\/em>+1] may be used. The vertices adjacent from vertex<em> i <\/em>are stored in\u00a0\u00a0<em style=\"text-align: initial;font-size: 1em\">node<\/em><span style=\"text-align: initial;font-size: 1em\">[<\/span><em style=\"text-align: initial;font-size: 1em\">node<\/em><span style=\"text-align: initial;font-size: 1em\">[<\/span><em style=\"text-align: initial;font-size: 1em\">i<\/em><span style=\"text-align: initial;font-size: 1em\">]], \u2026 ,<\/span><em style=\"text-align: initial;font-size: 1em\"> node<\/em><span style=\"text-align: initial;font-size: 1em\">[<\/span><em style=\"text-align: initial;font-size: 1em\">node<\/em><span style=\"text-align: initial;font-size: 1em\">[<\/span><em style=\"text-align: initial;font-size: 1em\">i<\/em><span style=\"text-align: initial;font-size: 1em\">+1]-1], 0\u2266<\/span><em style=\"text-align: initial;font-size: 1em\">i<\/em><span style=\"text-align: initial;font-size: 1em\">&lt;<\/span><em style=\"text-align: initial;font-size: 1em\">n. <\/em><span style=\"text-align: initial;font-size: 1em\">The number of edges in<\/span><em style=\"text-align: initial;font-size: 1em\"> G <\/em><span style=\"text-align: initial;font-size: 1em\">may be determined in O(<\/span><em style=\"text-align: initial;font-size: 1em\">n<\/em><span style=\"text-align: initial;font-size: 1em\">+<\/span><em style=\"text-align: initial;font-size: 1em\">e<\/em><span style=\"text-align: initial;font-size: 1em\">)<\/span><\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p><span style=\"background-color: #ff99cc\">node[0] \u2026 node[n-1]: starting point for vertices<\/span><\/p>\n<p><span style=\"background-color: #ff99cc\">node[n]: n+2e+1<\/span><\/p>\n<p><span style=\"background-color: #ff99cc\">node[n+1] \u2026 node[n+2e]: head node of edge<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-489 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-315.png\" alt=\"\" width=\"616\" height=\"386\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-315.png 616w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-315-300x188.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-315-65x41.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-315-225x141.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-315-350x219.png 350w\" sizes=\"auto, (max-width: 616px) 100vw, 616px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Here we use the node 0 to n+2e i.e 8+2*7= 22<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Node 0 shows the location of the node where edges for vertex 0 starts (in our example 9), node 1 shows where the edges for 1 starts (in our example 11) and son on. In node 9 we have the edge with 0 (0-1) as edge while in node 10 we the next edge of 0 (0-2). Similarly in node 11 we have the edge with 1 (1 -0) as edge while in node 12 we the next edge of 1 (0-3) and so on.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>32.5.3 Adjacency Multi-list<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">An edge in an undirected graph is represented by two nodes in adjacency list representation. Lists in which nodes may be shared among several lists that is a vertex shared by two different paths is called as adjacency multi-lists. There is exactly one node for each edge. This node is on the adjacency list for each of the two vertices it is incident to. Each node in the list is represented as given in Figure 32.17. An example of adjacency multi-list for an undirected graph is shown in Fig 32.18.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-490 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-316.png\" alt=\"\" width=\"464\" height=\"75\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-316.png 464w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-316-300x48.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-316-65x11.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-316-225x36.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-316-350x57.png 350w\" sizes=\"auto, (max-width: 464px) 100vw, 464px\" \/><\/p>\n<\/div>\n<div>\n<p style=\"text-align: center\"><strong>Figure 32.17 Node in an Adjacency Multi-list<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-491 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-317.png\" alt=\"\" width=\"624\" height=\"333\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-317.png 624w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-317-300x160.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-317-65x35.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-317-225x120.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-317-350x187.png 350w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In Figure 32.18, the number of nodes is 4, the number of edges is 6. The Multi -list shows the structure where N1 shows the path with vertices 0 and 1 corresponding to edges (0-1) as well as (1-0) (since the example is an undirected graph). The first different path N2 containing first vertex 0 is shown next and the first different path N4 with vertex 1 is shown next. Next we go to N2 corresponding to path with vertices 0 and 2. Now N3 is the next path with 0 while N4 is the next path with 2. Next is N3 corresponding to path with vertices 0 and 3. Now there is no other path with 0 while N5 is the next path with 3. Next is N4 corresponding to path with vertices 1 and 2. Now N5 is the next path with 1 while N6 is the next path with 2. Next is N5 corresponding to path with vertices 1 and 3. Now there is no other path with 2 while N6 is the next path with 3. Finally we see N6 corresponding to path with vertices 2 and 3. Now we have processed all paths and there are no more paths to consider.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Analysis (Adjacency Matrix vs Adjacency List)<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Now we will discuss the time complexity of graph operations when using adjacency matrix or adjacency list is used. For adding or removing edges in case of adjacency matrix the time needed will be a small constant but for adjacency list it will be of the order O(N) where N is the number of vertices in the graph. Checking if an edge is present for the adjacency matrix representation time taken will be a small constant, however in the case of adjacency list the time taken is of the order O(N) where the linked adjacency list has linear running time with the length of this list, on the average. Now for iterating through a vertex\u2019s edges the adjacency matrix takes time of the order of O(N) while for the adjacency list it is of the order O(E) where E is the number of edges in the graph. For finding all of the vertices adjacent to a given vertex, the adjacency list tends to support this operation more efficiently than the adjacency matrix. Both take of the order of O(<em>N<\/em>) in worst case (i.e., when we are dealing with a complete graph). Now regarding the memory requirement, the adjacency matrix always requires <em>N<\/em>2 cells while adjacency list requires an array of <em>N\u00a0<\/em><span style=\"text-align: initial;font-size: 1em\">pointers and a number of nodes equal to twice the number of edges in the case of an undirected graph.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">32.5.4 Choice of Implementation<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"font-size: 1em\">The choice which representation to use is normally based on which operations are more frequent and whether a good set ADT is available. It also depends on the average number of edges per vertex, since the adjacency matrix is wasteful for sparse graphs, since we need W(n<\/span><sup>2<\/sup><span style=\"font-size: 1em\">) space.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">Summary<\/strong><\/p>\n<\/div>\n<ul>\n<li>Explained the components of Graphs<\/li>\n<li>Described the Graph ADT<\/li>\n<li>Discussed the different representations of Graphs<\/li>\n<li>Analysed the different representations of Graphs<\/li>\n<\/ul>\n<table>\n<tbody>\n<tr>\n<td><strong>you can view video on Introduction to Graphs<\/strong><\/td>\n<td><a href=\"https:\/\/youtu.be\/WxyEnizeXjg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-492 aligncenter\" src=\"http:\/\/csp01.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/45\/2018\/07\/1-318.png\" alt=\"\" width=\"609\" height=\"161\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-318.png 609w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-318-300x79.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-318-65x17.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-318-225x59.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-content\/uploads\/sites\/45\/2018\/07\/1-318-350x93.png 350w\" sizes=\"auto, (max-width: 609px) 100vw, 609px\" \/><\/p>\n","protected":false},"author":3,"menu_order":32,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["dr-t-v-geetha"],"pb_section_license":""},"chapter-type":[],"contributor":[59],"license":[],"class_list":["post-475","chapter","type-chapter","status-publish","hentry","contributor-dr-t-v-geetha"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-json\/pressbooks\/v2\/chapters\/475","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-json\/wp\/v2\/users\/3"}],"version-history":[{"count":8,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-json\/pressbooks\/v2\/chapters\/475\/revisions"}],"predecessor-version":[{"id":974,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-json\/pressbooks\/v2\/chapters\/475\/revisions\/974"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-json\/pressbooks\/v2\/chapters\/475\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-json\/wp\/v2\/media?parent=475"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-json\/pressbooks\/v2\/chapter-type?post=475"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-json\/wp\/v2\/contributor?post=475"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp01\/wp-json\/wp\/v2\/license?post=475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}