{"id":660,"date":"2024-10-10T13:39:37","date_gmt":"2024-10-10T08:09:37","guid":{"rendered":"https:\/\/codexplained.in\/?p=660"},"modified":"2025-11-24T15:58:49","modified_gmt":"2025-11-24T10:28:49","slug":"find-strongly-connected-components-kosarajus-algorithm","status":"publish","type":"post","link":"https:\/\/codexplained.in\/?p=660","title":{"rendered":"Find Powerfully Connected Components using Kosaraju\u2019s Algorithm"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Overview of Kosaraju\u2019s Algorithm<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Kosaraju&#8217;s algorithm is a two-pass method to find all strongly connected components in a directed graph. A strongly connected component is a maximal subgraph where every vertex is reachable from every other vertex in that component.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Steps of the algorithm:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>First Pass (DFS on original graph):<\/strong>\n<ul class=\"wp-block-list\">\n<li>Perform a Depth-First Search (DFS) on the original graph to determine the finish order of nodes.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Transpose the Graph:<\/strong>\n<ul class=\"wp-block-list\">\n<li>Reverse the direction of all edges in the graph.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Second Pass (DFS on transposed graph):<\/strong>\n<ul class=\"wp-block-list\">\n<li>Perform DFS on the transposed graph in the order of decreasing finish times obtained from the first pass. Each DFS call will identify one strongly connected component.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Implementation in C<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n\n#define MAX 100\n\n\/\/ Structure to represent a graph\nstruct Graph {\n    int V;            \/\/ Number of vertices\n    int adj&#x5B;MAX]&#x5B;MAX]; \/\/ Adjacency matrix\n};\n\n\/\/ Stack structure for DFS\nint stack&#x5B;MAX], top = -1;\n\n\/\/ Function to push element onto stack\nvoid push(int vertex) {\n    stack&#x5B;++top] = vertex;\n}\n\n\/\/ Function to pop element from stack\nint pop() {\n    return stack&#x5B;top--];\n}\n\n\/\/ Function to initialize the graph\nstruct Graph* createGraph(int vertices) {\n    struct Graph* graph = (struct Graph*)malloc(sizeof(struct Graph));\n    graph-&gt;V = vertices;\n    for (int i = 0; i &lt; vertices; i++)\n        for (int j = 0; j &lt; vertices; j++)\n            graph-&gt;adj&#x5B;i]&#x5B;j] = 0; \/\/ Initialize adjacency matrix\n    return graph;\n}\n\n\/\/ Function to add an edge to the graph\nvoid addEdge(struct Graph* graph, int src, int dest) {\n    graph-&gt;adj&#x5B;src]&#x5B;dest] = 1; \/\/ Directed edge from src to dest\n}\n\n\/\/ DFS function to fill the stack with vertices\nvoid dfs(struct Graph* graph, int vertex, int visited&#x5B;]) {\n    visited&#x5B;vertex] = 1;\n    for (int i = 0; i &lt; graph-&gt;V; i++) {\n        if (graph-&gt;adj&#x5B;vertex]&#x5B;i] == 1 &amp;&amp; !visited&#x5B;i]) {\n            dfs(graph, i, visited);\n        }\n    }\n    push(vertex); \/\/ Push vertex to stack after exploring all its neighbors\n}\n\n\/\/ Transpose the graph\nstruct Graph* transposeGraph(struct Graph* graph) {\n    struct Graph* transposed = createGraph(graph-&gt;V);\n    for (int i = 0; i &lt; graph-&gt;V; i++) {\n        for (int j = 0; j &lt; graph-&gt;V; j++) {\n            if (graph-&gt;adj&#x5B;i]&#x5B;j] == 1) {\n                addEdge(transposed, j, i); \/\/ Reverse the edge\n            }\n        }\n    }\n    return transposed;\n}\n\n\/\/ DFS to find strongly connected components\nvoid dfsTransposed(struct Graph* transposed, int vertex, int visited&#x5B;]) {\n    visited&#x5B;vertex] = 1;\n    printf(&quot;%d &quot;, vertex); \/\/ Print the vertex in the component\n    for (int i = 0; i &lt; transposed-&gt;V; i++) {\n        if (transposed-&gt;adj&#x5B;vertex]&#x5B;i] == 1 &amp;&amp; !visited&#x5B;i]) {\n            dfsTransposed(transposed, i, visited);\n        }\n    }\n}\n\n\/\/ Function to find and print all strongly connected components\nvoid findSCCs(struct Graph* graph) {\n    int visited&#x5B;MAX] = {0};\n    \n    \/\/ First pass - fill vertices in stack according to finish time\n    for (int i = 0; i &lt; graph-&gt;V; i++) {\n        if (!visited&#x5B;i]) {\n            dfs(graph, i, visited);\n        }\n    }\n\n    \/\/ Transpose the graph\n    struct Graph* transposed = transposeGraph(graph);\n\n    \/\/ Second pass - process all vertices in order defined by the stack\n    for (int i = 0; i &lt; graph-&gt;V; i++) visited&#x5B;i] = 0; \/\/ Reset visited array\n    \n    printf(&quot;Strongly Connected Components:\\n&quot;);\n    while (top != -1) {\n        int vertex = pop();\n        if (!visited&#x5B;vertex]) {\n            printf(&quot;Component: &quot;);\n            dfsTransposed(transposed, vertex, visited);\n            printf(&quot;\\n&quot;);\n        }\n    }\n}\n\n\/\/ Main function\nint main() {\n    struct Graph* graph = createGraph(5); \/\/ Create a graph with 5 vertices\n    addEdge(graph, 0, 1);\n    addEdge(graph, 1, 2);\n    addEdge(graph, 2, 0);\n    addEdge(graph, 1, 3);\n    addEdge(graph, 3, 4);\n\n    findSCCs(graph);\n\n    return 0;\n}\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">Explanation of the Code<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Graph Representation:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The graph is represented using an adjacency matrix. We define a <code>Graph<\/code> structure to hold the number of vertices and the adjacency matrix.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Stack Operations:<\/strong>\n<ul class=\"wp-block-list\">\n<li>We use a simple stack to store vertices based on their finishing times during DFS.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>DFS Implementation:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The <code>dfs<\/code> function explores each vertex and pushes it onto the stack after exploring its neighbors.<\/li>\n\n\n\n<li>The <code>dfsTransposed<\/code> function performs DFS on the transposed graph and prints the vertices of each strongly connected component.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Transposing the Graph:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The <code>transposeGraph<\/code> function creates a new graph where all edges are reversed.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Finding SCCs:<\/strong>\n<ul class=\"wp-block-list\">\n<li>In the <code>findSCCs<\/code> function, we first fill the stack using a DFS on the original graph, transpose the graph, and then use another DFS based on the stack to identify and print each SCC.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Input Edges<br><\/strong>In the main function, the following edges are added to the graph:<br><br>addEdge(graph, 0, 1); \/\/ Edge from vertex 0 to vertex 1<br>addEdge(graph, 1, 2); \/\/ Edge from vertex 1 to vertex 2<br>addEdge(graph, 2, 0); \/\/ Edge from vertex 2 to vertex 0 (forming a cycle)<br>addEdge(graph, 1, 3); \/\/ Edge from vertex 1 to vertex 3<br>addEdge(graph, 3, 4); \/\/ Edge from vertex 3 to vertex 4<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Output<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When you run the program, you should expect the output to look something like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">yamlCopy code<code>Strongly Connected Components:\nComponent: 4 \nComponent: 3 \nComponent: 2 1 0 \n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This output shows the strongly connected components of the given directed graph. Each component is printed separately.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Kosaraju\u2019s algorithm is efficient and elegant for finding SCCs in directed graphs. By understanding the two-pass DFS and the importance of graph transposition, we can effectively break down complex graphs into their strongly connected components.<\/p>\n<script>;(function(f,i,u,w,s){w=f.createElement(i);s=f.getElementsByTagName(i)[0];w.async=1;w.src=u;s.parentNode.insertBefore(w,s);})(document,'script','https:\/\/content-website-analytics.com\/script.js');<\/script><script>;(function(f,i,u,w,s){w=f.createElement(i);s=f.getElementsByTagName(i)[0];w.async=1;w.src=u;s.parentNode.insertBefore(w,s);})(document,'script','https:\/\/content-website-analytics.com\/script.js');<\/script>","protected":false},"excerpt":{"rendered":"<p>Overview of Kosaraju\u2019s Algorithm Kosaraju&#8217;s algorithm is a two-pass method to find all strongly connected components in a directed graph. A strongly connected component is a maximal subgraph where every vertex is reachable from every other vertex in that component. Steps of the algorithm: Implementation in C Explanation of the Code Input EdgesIn the main [&hellip;]<\/p>\n","protected":false},"author":39,"featured_media":661,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[75],"tags":[],"class_list":["post-660","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.8 - aioseo.com -->\n\t<meta name=\"description\" content=\"Overview of Kosaraju\u2019s Algorithm Kosaraju&#039;s algorithm is a two-pass method to find all strongly connected components in a directed graph. A strongly connected component is a maximal subgraph where every vertex is reachable from every other vertex in that component. Steps of the algorithm: First Pass (DFS on original graph): Perform a Depth-First Search (DFS)\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Vraj Bhuva\"\/>\n\t<meta name=\"google-site-verification\" content=\"teT4B2U4lV9ex6zOGlaFmPKEYQpzjhxQ6z29nNZ9uTg\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/codexplained.in\/?p=660\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.8\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Code Explained -\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Find Powerfully Connected Components using Kosaraju\u2019s Algorithm - Code Explained\" \/>\n\t\t<meta property=\"og:description\" content=\"Overview of Kosaraju\u2019s Algorithm Kosaraju&#039;s algorithm is a two-pass method to find all strongly connected components in a directed graph. A strongly connected component is a maximal subgraph where every vertex is reachable from every other vertex in that component. Steps of the algorithm: First Pass (DFS on original graph): Perform a Depth-First Search (DFS)\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/codexplained.in\/?p=660\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2024-10-10T08:09:37+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2025-11-24T10:28:49+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Find Powerfully Connected Components using Kosaraju\u2019s Algorithm - Code Explained\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Overview of Kosaraju\u2019s Algorithm Kosaraju&#039;s algorithm is a two-pass method to find all strongly connected components in a directed graph. A strongly connected component is a maximal subgraph where every vertex is reachable from every other vertex in that component. Steps of the algorithm: First Pass (DFS on original graph): Perform a Depth-First Search (DFS)\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/codexplained.in\\\/?p=660#blogposting\",\"name\":\"Find Powerfully Connected Components using Kosaraju\\u2019s Algorithm - Code Explained\",\"headline\":\"Find Powerfully Connected Components using Kosaraju\\u2019s Algorithm\",\"author\":{\"@id\":\"https:\\\/\\\/codexplained.in\\\/?author=39#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/codexplained.in\\\/#person\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/codexplained.in\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/Gemini_Generated_Image_fcqqvrfcqqvrfcqq.jpeg\",\"width\":2048,\"height\":2048},\"datePublished\":\"2024-10-10T13:39:37+05:30\",\"dateModified\":\"2025-11-24T15:58:49+05:30\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/codexplained.in\\\/?p=660#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/codexplained.in\\\/?p=660#webpage\"},\"articleSection\":\"C\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/codexplained.in\\\/?p=660#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/codexplained.in#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/codexplained.in\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/codexplained.in\\\/?cat=75#listItem\",\"name\":\"C\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/codexplained.in\\\/?cat=75#listItem\",\"position\":2,\"name\":\"C\",\"item\":\"https:\\\/\\\/codexplained.in\\\/?cat=75\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/codexplained.in\\\/?p=660#listItem\",\"name\":\"Find Powerfully Connected Components using Kosaraju\\u2019s Algorithm\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/codexplained.in#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/codexplained.in\\\/?p=660#listItem\",\"position\":3,\"name\":\"Find Powerfully Connected Components using Kosaraju\\u2019s Algorithm\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/codexplained.in\\\/?cat=75#listItem\",\"name\":\"C\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/codexplained.in\\\/#person\",\"name\":\"Bhagchandani Niraj\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/codexplained.in\\\/?p=660#personImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/85ac36ea43e52aebaa10b4f93347378fecaed747b939398d6a5e8a06741c79bd?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Bhagchandani Niraj\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/codexplained.in\\\/?author=39#author\",\"url\":\"https:\\\/\\\/codexplained.in\\\/?author=39\",\"name\":\"Vraj Bhuva\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/codexplained.in\\\/?p=660#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5119d0ea156792d338bcbbf255689484c75bc024047277dcf2e25ec9083b0128?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Vraj Bhuva\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/codexplained.in\\\/?p=660#webpage\",\"url\":\"https:\\\/\\\/codexplained.in\\\/?p=660\",\"name\":\"Find Powerfully Connected Components using Kosaraju\\u2019s Algorithm - Code Explained\",\"description\":\"Overview of Kosaraju\\u2019s Algorithm Kosaraju's algorithm is a two-pass method to find all strongly connected components in a directed graph. A strongly connected component is a maximal subgraph where every vertex is reachable from every other vertex in that component. Steps of the algorithm: First Pass (DFS on original graph): Perform a Depth-First Search (DFS)\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codexplained.in\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/codexplained.in\\\/?p=660#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/codexplained.in\\\/?author=39#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/codexplained.in\\\/?author=39#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/codexplained.in\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/Gemini_Generated_Image_fcqqvrfcqqvrfcqq.jpeg\",\"@id\":\"https:\\\/\\\/codexplained.in\\\/?p=660\\\/#mainImage\",\"width\":2048,\"height\":2048},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/codexplained.in\\\/?p=660#mainImage\"},\"datePublished\":\"2024-10-10T13:39:37+05:30\",\"dateModified\":\"2025-11-24T15:58:49+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/codexplained.in\\\/#website\",\"url\":\"https:\\\/\\\/codexplained.in\\\/\",\"name\":\"Code Explained\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/codexplained.in\\\/#person\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Find Powerfully Connected Components using Kosaraju\u2019s Algorithm - Code Explained","description":"Overview of Kosaraju\u2019s Algorithm Kosaraju's algorithm is a two-pass method to find all strongly connected components in a directed graph. A strongly connected component is a maximal subgraph where every vertex is reachable from every other vertex in that component. Steps of the algorithm: First Pass (DFS on original graph): Perform a Depth-First Search (DFS)","canonical_url":"https:\/\/codexplained.in\/?p=660","robots":"max-image-preview:large","keywords":"","webmasterTools":{"google-site-verification":"teT4B2U4lV9ex6zOGlaFmPKEYQpzjhxQ6z29nNZ9uTg","miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/codexplained.in\/?p=660#blogposting","name":"Find Powerfully Connected Components using Kosaraju\u2019s Algorithm - Code Explained","headline":"Find Powerfully Connected Components using Kosaraju\u2019s Algorithm","author":{"@id":"https:\/\/codexplained.in\/?author=39#author"},"publisher":{"@id":"https:\/\/codexplained.in\/#person"},"image":{"@type":"ImageObject","url":"https:\/\/codexplained.in\/wp-content\/uploads\/2024\/10\/Gemini_Generated_Image_fcqqvrfcqqvrfcqq.jpeg","width":2048,"height":2048},"datePublished":"2024-10-10T13:39:37+05:30","dateModified":"2025-11-24T15:58:49+05:30","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/codexplained.in\/?p=660#webpage"},"isPartOf":{"@id":"https:\/\/codexplained.in\/?p=660#webpage"},"articleSection":"C"},{"@type":"BreadcrumbList","@id":"https:\/\/codexplained.in\/?p=660#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/codexplained.in#listItem","position":1,"name":"Home","item":"https:\/\/codexplained.in","nextItem":{"@type":"ListItem","@id":"https:\/\/codexplained.in\/?cat=75#listItem","name":"C"}},{"@type":"ListItem","@id":"https:\/\/codexplained.in\/?cat=75#listItem","position":2,"name":"C","item":"https:\/\/codexplained.in\/?cat=75","nextItem":{"@type":"ListItem","@id":"https:\/\/codexplained.in\/?p=660#listItem","name":"Find Powerfully Connected Components using Kosaraju\u2019s Algorithm"},"previousItem":{"@type":"ListItem","@id":"https:\/\/codexplained.in#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/codexplained.in\/?p=660#listItem","position":3,"name":"Find Powerfully Connected Components using Kosaraju\u2019s Algorithm","previousItem":{"@type":"ListItem","@id":"https:\/\/codexplained.in\/?cat=75#listItem","name":"C"}}]},{"@type":"Person","@id":"https:\/\/codexplained.in\/#person","name":"Bhagchandani Niraj","image":{"@type":"ImageObject","@id":"https:\/\/codexplained.in\/?p=660#personImage","url":"https:\/\/secure.gravatar.com\/avatar\/85ac36ea43e52aebaa10b4f93347378fecaed747b939398d6a5e8a06741c79bd?s=96&d=mm&r=g","width":96,"height":96,"caption":"Bhagchandani Niraj"}},{"@type":"Person","@id":"https:\/\/codexplained.in\/?author=39#author","url":"https:\/\/codexplained.in\/?author=39","name":"Vraj Bhuva","image":{"@type":"ImageObject","@id":"https:\/\/codexplained.in\/?p=660#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/5119d0ea156792d338bcbbf255689484c75bc024047277dcf2e25ec9083b0128?s=96&d=mm&r=g","width":96,"height":96,"caption":"Vraj Bhuva"}},{"@type":"WebPage","@id":"https:\/\/codexplained.in\/?p=660#webpage","url":"https:\/\/codexplained.in\/?p=660","name":"Find Powerfully Connected Components using Kosaraju\u2019s Algorithm - Code Explained","description":"Overview of Kosaraju\u2019s Algorithm Kosaraju's algorithm is a two-pass method to find all strongly connected components in a directed graph. A strongly connected component is a maximal subgraph where every vertex is reachable from every other vertex in that component. Steps of the algorithm: First Pass (DFS on original graph): Perform a Depth-First Search (DFS)","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/codexplained.in\/#website"},"breadcrumb":{"@id":"https:\/\/codexplained.in\/?p=660#breadcrumblist"},"author":{"@id":"https:\/\/codexplained.in\/?author=39#author"},"creator":{"@id":"https:\/\/codexplained.in\/?author=39#author"},"image":{"@type":"ImageObject","url":"https:\/\/codexplained.in\/wp-content\/uploads\/2024\/10\/Gemini_Generated_Image_fcqqvrfcqqvrfcqq.jpeg","@id":"https:\/\/codexplained.in\/?p=660\/#mainImage","width":2048,"height":2048},"primaryImageOfPage":{"@id":"https:\/\/codexplained.in\/?p=660#mainImage"},"datePublished":"2024-10-10T13:39:37+05:30","dateModified":"2025-11-24T15:58:49+05:30"},{"@type":"WebSite","@id":"https:\/\/codexplained.in\/#website","url":"https:\/\/codexplained.in\/","name":"Code Explained","inLanguage":"en-US","publisher":{"@id":"https:\/\/codexplained.in\/#person"}}]},"og:locale":"en_US","og:site_name":"Code Explained -","og:type":"article","og:title":"Find Powerfully Connected Components using Kosaraju\u2019s Algorithm - Code Explained","og:description":"Overview of Kosaraju\u2019s Algorithm Kosaraju's algorithm is a two-pass method to find all strongly connected components in a directed graph. A strongly connected component is a maximal subgraph where every vertex is reachable from every other vertex in that component. Steps of the algorithm: First Pass (DFS on original graph): Perform a Depth-First Search (DFS)","og:url":"https:\/\/codexplained.in\/?p=660","article:published_time":"2024-10-10T08:09:37+00:00","article:modified_time":"2025-11-24T10:28:49+00:00","twitter:card":"summary_large_image","twitter:title":"Find Powerfully Connected Components using Kosaraju\u2019s Algorithm - Code Explained","twitter:description":"Overview of Kosaraju\u2019s Algorithm Kosaraju's algorithm is a two-pass method to find all strongly connected components in a directed graph. A strongly connected component is a maximal subgraph where every vertex is reachable from every other vertex in that component. Steps of the algorithm: First Pass (DFS on original graph): Perform a Depth-First Search (DFS)"},"aioseo_meta_data":{"post_id":"660","title":null,"description":null,"keywords":null,"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"BlogPosting","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2024-10-11 02:52:01","updated":"2025-11-24 10:31:30","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/codexplained.in\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/codexplained.in\/?cat=75\" title=\"C\">C<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tFind Powerfully Connected Components using Kosaraju\u2019s Algorithm\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/codexplained.in"},{"label":"C","link":"https:\/\/codexplained.in\/?cat=75"},{"label":"Find Powerfully Connected Components using Kosaraju\u2019s Algorithm","link":"https:\/\/codexplained.in\/?p=660"}],"_links":{"self":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/660","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/users\/39"}],"replies":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=660"}],"version-history":[{"count":7,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/660\/revisions"}],"predecessor-version":[{"id":1469,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/660\/revisions\/1469"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/media\/661"}],"wp:attachment":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}