diff --git a/Algorithms/scc.cpp b/Algorithms/scc.cpp new file mode 100644 index 0000000..079c825 --- /dev/null +++ b/Algorithms/scc.cpp @@ -0,0 +1,54 @@ +//SCC: Strongly Connected Components +/*We can find all strongly connected components in O(V+E) time using Kosaraju’s algorithm. +A directed graph is strongly connected if there is a path between all pairs of vertices in the graph +can also be done by johnson algorithm and tarzan algorithm*/ + +#include +using namespace std; +#define ll long long +#define pb push_back +stack s,s1; +vector adj[1000],tadj[1000]; +int visit[1000]={0},done[1000]={0}; +int cur; +int rdfs(ll x) +{ + visit[x]=1; + for(int j=0;j>n>>m; + for(int i=1;i<=m;i++) + { + cin>>x>>y; + adj[x].pb(y); + tadj[y].pb(x); + } + for(int i=1;i<=n;i++) + if(visit[i]==0) + rdfs(i); + + while(!s.empty()) + { + int t=s.top(); + s.pop(); + while(!s1.empty()) s1.pop();//doubt full line + if(!done[t]) dfs(t); + cout<0 and alist[position-1]>currentvalue: - alist[position]=alist[position-1] - position = position-1 - - alist[position]=currentvalue - -alist = [54,26,93,17,77,31,44,55,20] -insertionSort(alist) -print(alist) +def insertionSort(alist): + for index in range(1,len(alist)): + + currentvalue = alist[index] + position = index + + while position>0 and alist[position-1]>currentvalue: + alist[position]=alist[position-1] + position = position-1 + + alist[position]=currentvalue + +alist = [54,26,93,17,77,31,44,55,20] +insertionSort(alist) +print(alist)