{"id":83175,"date":"2021-08-02T09:00:09","date_gmt":"2021-08-02T03:30:09","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=83175"},"modified":"2021-08-02T09:00:09","modified_gmt":"2021-08-02T03:30:09","slug":"graph-in-data-structure","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/graph-in-data-structure\/","title":{"rendered":"Graphs in Data Structure"},"content":{"rendered":"<p>In this article, we will learn about the graphs in data structure.<\/p>\n<p>There are mainly 2 types of data structures: Linear and Non-linear. Linear data structures include arrays, linked lists, stacks, queues, etc. whereas the non-linear data structures include trees and graphs.<\/p>\n<p>Thus, a graph is a non-linear data structure and it consists of edges and vertices. Graphs are one of the most important topics of data structures.<\/p>\n<h3>What are Graphs in data structure?<\/h3>\n<p>A graph is a collection of two sets:<br \/>\n1. A set of vertices, and<br \/>\n2. A set of edges<\/p>\n<p>We can represent every edge by two elements of the set. A graph is represented by G(V, E) where V= set of vertices and E= set of edges. Vertices are also known as nodes.<\/p>\n<p>For example, the following diagram depicts a graph:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image01.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83258\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image01.jpg\" alt=\"Graphs in Data Structure\" width=\"390\" height=\"237\" \/><\/a><\/p>\n<p>Here, V = {a, b, c, d, e} and E = {e1, e2, e3, e4, e5, e6} or E = {ab, bc, bd, ad, de, ce}.<\/p>\n<h3>Graphs in data structure<\/h3>\n<p><strong>1. Undirected graph:<\/strong> An undirected graph is the one in which there is no direction associated with the edges. In an undirected graph, traversal from A\u2192B is the same as that of B\u2192A. the following graph is undirected:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image02.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83259\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image02.jpg\" alt=\"Undirected graph\" width=\"328\" height=\"190\" \/><\/a><\/p>\n<p><strong>2. Directed graph:<\/strong> a directed graph is the one in which we have ordered pairs and the direction matters. Thus, in a directed graph, A\u2192B is <strong>not<\/strong> the same as B\u2192A. The following graph is a directed graph.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image03.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83260\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image03.jpg\" alt=\"Directed Graph\" width=\"328\" height=\"190\" \/><\/a><\/p>\n<p>Here, the edge is from A to B. Thus, A is called the<strong> initial node<\/strong> and B is called the <strong>terminal node.<\/strong><\/p>\n<h3>Graph Terminologies:<\/h3>\n<p>Consider the following graph:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image04.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83261\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image04.jpg\" alt=\"Graph in data structure\" width=\"328\" height=\"228\" \/><\/a><\/p>\n<p><strong>1. Vertex:<\/strong> A vertex represents each node of a graph. For example, in the above graph, A, B, C, D, E are the vertices.<\/p>\n<p><strong>2. Edge:<\/strong> It is the path between two nodes\/vertices.<\/p>\n<p><strong>3. Path:<\/strong> It is the sequence\/order of vertices to reach from one node to another. For example, suppose we wish to reach from node A to node E. the possible paths are: A\u2192C\u2192E or A\u2192B\u2192C\u2192E.<\/p>\n<p><strong>4. Closed path:<\/strong> If the initial and the final nodes are the same, then the path is a closed path.<\/p>\n<p><strong>5. Simple path:<\/strong> A simple path is a path in which all the nodes are distinct.<\/p>\n<p><strong>6. Adjacency:<\/strong> Two vertices are adjacent if there exists an edge that connects those two vertices. For example, the nodes A-B, B-C, A-C, C-D, C-E are all adjacent nodes.<\/p>\n<p><strong>7. Degree of a node:<\/strong> For each node in a graph, its degree is the number of edges connected to that node. Here, the degree of all nodes except node F is 2 and the degree of node F is 0.<\/p>\n<p><strong>8. Isolated node:<\/strong> A node having degree = 0. Thus, an isolated node is not connected to any other node. Here, node F is the isolated node.<\/p>\n<h3>Types of Graphs:<\/h3>\n<p><strong>1. Simple graph:<\/strong> A graph in which neither loops nor parallel edges exist is a simple graph. The following diagram is an example of a simple graph.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image05.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83262\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image05.jpg\" alt=\"Simple Graph in DS\" width=\"492\" height=\"252\" \/><\/a><\/p>\n<p><strong>2. Connected graph:<\/strong> If there is a path between every pair of vertices, then the graph is called a connected graph. Any graph containing an isolated edge can never be a connected graph. The first graph In the following example is connected whereas the second one is not a connected graph.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image06.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83263\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image06.jpg\" alt=\"Connected graph in Data Structure\" width=\"656\" height=\"239\" \/><\/a><\/p>\n<p><strong>3. Complete graph:<\/strong> A complete graph is a simple graph in which every node is adjacent to every other node. A complete graph has nC2 = n(n-1)\/2 edges.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image07.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83264\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image07.jpg\" alt=\"Complete graph in Data Structure\" width=\"492\" height=\"252\" \/><\/a><\/p>\n<p><strong>4. Weighted graph:<\/strong> A weighted graph is the one in which we associate some weight with every edge. For example, the following graph is a weighted graph:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image08.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83265\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image08.jpg\" alt=\"Weighted graph in Data Structure\" width=\"656\" height=\"239\" \/><\/a><\/p>\n<p><strong>5. Digraph:<\/strong> It is a kind of directed graph in which each edge of the graph has a specified direction and we can traverse through the graph only in that direction.<\/p>\n<h3>Graphs Representation in data structure:<\/h3>\n<p>The complexity of any graph-based algorithm depends upon how we are implementing the graphs. That is why the graph representation becomes important.<\/p>\n<p>There are many ways to represent graphs. However, two of them are most popular: Adjacency matrix representation and linked list representation<\/p>\n<h4>1. Adjacency matrix representation<\/h4>\n<p>In adjacency matrix representation, we have a matrix of order n*n where n is the number of nodes in the graph. The matrix represents the mapping between various edges and vertices.<\/p>\n<p>In the matrix, each row and column represents a vertex. The values determine the presence of edges.<\/p>\n<p>Let Aij represents each element of the adjacency matrix. Then,<\/p>\n<p>For an undirected graph, the value of Aij is 1 if there exists an edge between i and j. Otherwise, the value of Aij is 0.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image09.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83266\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image09.jpg\" alt=\"Adjacency Matrix Representation\" width=\"590\" height=\"277\" \/><\/a><\/p>\n<p>For a directed graph, the value of Aij is 1 only if there is an edge from i to j i.e. <strong>i<\/strong> is the initial node and <strong>j<\/strong> is the terminal node.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image10.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83267\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image10.jpg\" alt=\"Adjacency matrix\" width=\"590\" height=\"277\" \/><\/a><\/p>\n<p>The time complexity of the adjacency matrix is O(n<sup>2<\/sup>).<\/p>\n<h4>2. Adjacency list representation<\/h4>\n<p>The adjacency list is an array of linked lists where the array denotes the total vertices and each linked list denotes the vertices connected to a particular node.<\/p>\n<p>In a linked list, the most important component is the pointer named \u2018Head\u2019 because this single pointer maintains the whole linked list. For linked list representation, we will have total pointers equal to the number of nodes in the graph.<\/p>\n<p>For an undirected graph, we will link all the edges in the list that are connected to a node as shown:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image11.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83268\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image11.jpg\" alt=\"Adjacency List Representation\" width=\"826\" height=\"291\" \/><\/a><\/p>\n<p>In a directed graph, we will link only the initial nodes in the list as shown:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image12.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83269\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/TV-DS-Graph-normal-image12.jpg\" alt=\"Adjacency List for directed graph\" width=\"667\" height=\"291\" \/><\/a><\/p>\n<h3>Adjacency Matrix Implementation in C:<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\n#define S 4\n\nvoid init(int Array[][S]) \n{\n  int i, j;\n  for (i = 0; i &lt; S; i++)\n    for (j = 0; j &lt; S; j++)\n      Array[i][j] = 0;\n}\n\nvoid addEdge(int Array[][S], int i, int j) \n{\n  Array[i][j] = 1;\n  Array[j][i] = 1;\n}\n\nint main() \n{\n    int adjacency_matrix[S][S];\n    init(adjacency_matrix);\n    addEdge(adjacency_matrix, 1, 2);\n    addEdge(adjacency_matrix, 0, 2);\n    addEdge(adjacency_matrix, 3, 0);\n    addEdge(adjacency_matrix, 2, 3);\n\n    int i, j;\n    for (i = 0; i &lt; S; i++) \n    {\n        printf(\"%d: \", i);\n        for (j = 0; j &lt; S; j++) \n            printf(\"%d \", adjacency_matrix[i][j]);\n        printf(\"\\n\");\n    }\n    return 0;\n}\n<\/pre>\n<h3>Adjacency Matrix Implementation in C++<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;bits\/stdc++.h&gt;\nusing namespace std;\n#define S 4\n\nvoid init(int Array[][S]) \n{\n  int i, j;\n  for (i = 0; i &lt; S; i++)\n    for (j = 0; j &lt; S; j++)\n      Array[i][j] = 0;\n}\n\nvoid addEdge(int Array[][S], int i, int j) \n{\n  Array[i][j] = 1;\n  Array[j][i] = 1;\n}\n\nint main() \n{\n    int adjacency_matrix[S][S];\n    init(adjacency_matrix);\n    addEdge(adjacency_matrix, 1, 2);\n    addEdge(adjacency_matrix, 0, 2);\n    addEdge(adjacency_matrix, 3, 0);\n    addEdge(adjacency_matrix, 2, 3);\n\n    int i, j;\n    for (i = 0; i &lt; S; i++) \n    {\n        cout &lt;&lt;  i &lt;&lt; \":\";\n        for (j = 0; j &lt; S; j++) \n            cout &lt;&lt; \" \" &lt;&lt;adjacency_matrix[i][j];\n        cout &lt;&lt; \"\\n\";\n    }\n    return 0;\n}\n<\/pre>\n<h3>Implementation of Adjacency Matrix in Java:<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">public class DS_Graph \n{\n    private boolean adjacent_matrix[][];\n    private int Vertices;\n    \n    public DS_Graph(int Vertices) \n    {\n        this.Vertices = Vertices;\n        adjacent_matrix = new boolean[Vertices][Vertices];\n    }\n    public void addEdge(int i, int j) \n    {\n        adjacent_matrix[i][j] = true;\n        adjacent_matrix[j][i] = true;\n    }\n\n    public void deleteEdge(int i, int j) \n    {\n        adjacent_matrix[i][j] = false;\n        adjacent_matrix[j][i] = false;\n    }\n\n    public String toString() \n    {\n        StringBuilder s = new StringBuilder();\n        for (int i = 0; i &lt; Vertices; i++) \n        {\n            s.append(i + \": \");\n            for (boolean j : adjacent_matrix[i]) \n            {\n                s.append((j ? 1 : 0) + \" \");\n            }\n            s.append(\"\\n\");\n        }\n        return s.toString();\n    }\n\n    public static void main(String args[]) \n    {\n        DS_Graph g = new DS_Graph(4);\n        g.addEdge(1, 2);\n        g.addEdge(0, 2);\n        g.addEdge(3, 0);\n        g.addEdge(2, 3);\n        System.out.print(g.toString());\n    }\n}\n<\/pre>\n<h3>Adjacency Matrix Implementation in Python:<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class DS_Graph(object):\n    \n    def __init__(self, size):\n        self.adjacent_matrix = []\n        for i in range(size):\n            self.adjacent_matrix.append([0 for i in range(size)])\n        self.size = size\n\n    def addEdge(self, x, y):\n        self.adjacent_matrix[x][y] = 1\n        self.adjacent_matrix[x][y] = 1\n\n    def deleteEdge(self, v1, v2):\n        self.adjacent_matrix[x][y] = 0\n        self.adjacent_matrix[x][y] = 0\n\n    def __len__(self):\n        return self.size\n\n    def Dispay_matrix(self):\n        for row in self.adjacent_matrix:\n            for val in row:\n                print('{:4}'.format(val), end=\"\")\n            print()\n    \nif __name__ == '__main__':\n    g = DS_Graph(5)\n    g.addEdge(0, 2)\n    g.addEdge(1, 2)\n    g.addEdge(3, 0)\n    g.addEdge(2, 3)\n    g.Dispay_matrix()\n<\/pre>\n<h3>Advantages of Adjacency Matrix:<\/h3>\n<ul>\n<li>Performing operations on a matrix are easier as compared to performing them on the list or other data structure. Operations like adding and removing edges, checking if the edges are present in the graph or not are easily performable.<\/li>\n<li>We can perform heavy matrix operations easily on modern GPUs.<\/li>\n<li>Using the adjacency matrix method proves to be very efficient whenever the graph is dense and when the number of edges present in the graph is large.<\/li>\n<\/ul>\n<h3>Disadvantages of Adjacency Matrix:<\/h3>\n<ul>\n<li>In the adjacency matrix method, operations such as inEdges and outEdges are costly.<\/li>\n<li>Matrix representation requires a large amount of additional memory even if the number of edges in a graph is less. This sometimes leads to a huge wastage of memory.<\/li>\n<\/ul>\n<h3>Operations performed on Graphs in Data Structures:<\/h3>\n<p>The most common operations on a graph are:<\/p>\n<p><strong>1. Graph traversal:<\/strong> It includes traversing all the edges of a graph.<\/p>\n<p><strong>2. Display vertex:<\/strong> It helps to display one or more vertices of the graph.<\/p>\n<p><strong>3. Add vertex:<\/strong> This operation adds a new vertex to the graph.<\/p>\n<p><strong>4. Add edge:<\/strong> It helps to add an edge between a given pair of vertices.<\/p>\n<p>5. Checking if the element is present in the graph or not.<\/p>\n<p>6. Finding the path from one edge to another.<\/p>\n<h3>Practical Applications of Graph:<\/h3>\n<p><strong>1. Facebook connections:<\/strong> Almost every one of us uses Facebook for connecting with friends. Everything is a node on Facebook. Thus, our profile and our friends\u2019 profiles are also nodes. All of them are interconnected. Facebook makes use of graphs to give us friend suggestions.<\/p>\n<p><strong>2. WWW:<\/strong> World Wide Web is the biggest graph. All the links and hyperlinks are the nodes and their interconnection is the edges. This is why we can open one webpage from the other.<\/p>\n<p><strong>3. Google maps:<\/strong> Google maps is also based on graphs. All the cities\/towns\/places are the nodes and we have different paths between different places.<\/p>\n<h3>Conclusion:<\/h3>\n<p>Looking at the wide variety of applications that graphs in data structure offer, we can say that graphs are one of the most important topics in computer science.<\/p>\n<p>Without graphs, there would have been no fast searching, no connecting with friends on the internet and no locating of places through online applications.<\/p>\n<p>In this article, we have gone through the definition of graphs, their types, their representation methods and the operations performed on the graphs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will learn about the graphs in data structure. There are mainly 2 types of data structures: Linear and Non-linear. Linear data structures include arrays, linked lists, stacks, queues, etc. whereas&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":83257,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3555],"tags":[3919,3920,3921,3922],"class_list":["post-83175","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-structure","tag-directed-graphs-in-data-structure","tag-graphs-in-data-structure","tag-types-of-graphs-in-data-structure","tag-undirected-graphs-in-data-structure"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Graphs in Data Structure - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn what are graphs in data structure, their types, representation methods, implementation and the operations performed on the graphs.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/graph-in-data-structure\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Graphs in Data Structure - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn what are graphs in data structure, their types, representation methods, implementation and the operations performed on the graphs.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/graph-in-data-structure\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-02T03:30:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/TV-DS-Graph.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Graphs in Data Structure - TechVidvan","description":"Learn what are graphs in data structure, their types, representation methods, implementation and the operations performed on the graphs.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/graph-in-data-structure\/","og_locale":"en_US","og_type":"article","og_title":"Graphs in Data Structure - TechVidvan","og_description":"Learn what are graphs in data structure, their types, representation methods, implementation and the operations performed on the graphs.","og_url":"https:\/\/techvidvan.com\/tutorials\/graph-in-data-structure\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-08-02T03:30:09+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/TV-DS-Graph.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/graph-in-data-structure\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/graph-in-data-structure\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Graphs in Data Structure","datePublished":"2021-08-02T03:30:09+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/graph-in-data-structure\/"},"wordCount":1324,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/graph-in-data-structure\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/TV-DS-Graph.jpg","keywords":["Directed Graphs in data structure","Graphs in data structure","types of Graphs in data structure","Undirected Graphs in data structure"],"articleSection":["Data Structure Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/graph-in-data-structure\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/graph-in-data-structure\/","url":"https:\/\/techvidvan.com\/tutorials\/graph-in-data-structure\/","name":"Graphs in Data Structure - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/graph-in-data-structure\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/graph-in-data-structure\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/TV-DS-Graph.jpg","datePublished":"2021-08-02T03:30:09+00:00","description":"Learn what are graphs in data structure, their types, representation methods, implementation and the operations performed on the graphs.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/graph-in-data-structure\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/graph-in-data-structure\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/graph-in-data-structure\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/TV-DS-Graph.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/TV-DS-Graph.jpg","width":1200,"height":628,"caption":"Graphs in Data Structure"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/graph-in-data-structure\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Graphs in Data Structure"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/83175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=83175"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/83175\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/83257"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=83175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=83175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=83175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}