Friday, 20 February 2026

kahn's algo of topological sort

TOPOLOGICAL SORING IS DONE ON DIRECTED ACYCLIC GRAPH (DAG) 


void kahnsalgo(){

       queue<int>q;

       vector<int>count=Count_indegree();

       for(int i=0;i<v;i++)if(count[i]==0)q.push(i);

       while(!q.empty()){

           int x=q.front();

           cout<<x<<" ";

           q.pop();

           for(int y:adj[x]){

               count[y]--;

               if(count[y]==0)q.push(y);

           }

           

       }

   }

No comments:

Post a Comment

SDE floyd-warshall algorithm

 // User function template for C++ class Solution {   public:     void floydWarshall(vector<vector<int>> &dist) {         //...