
See Our team
Wondering how we keep quality?
Got unsolved questions? Ask Questions
GATE
GMAT
CBSE
NCERT
Career
Interview
Railway
UPSC
NID
NIFT-UG
NIFT-PG
PHP
AJAX
JavaScript
Node Js
Shell Script
Research
Design and Analysis of Algorithms Subject Code : 10CSL47 Lab Manual PROGRAM-3
3. a. Obtain the Topological ordering of vertices in a given digraph.
#include<stdlib.h>
#include<stdio.h>
int a[10][10],n,indegree[10];
void find_indegree(int n,int a[][])
{
int j,i,sum;
for(j=0;j<n;j++)
{
for(i=0;i<n;i++)
{
if(a[i][j]==0)
{
sum=0;
for(i=0;i
sum+=a[i][j];
indegree[j]=sum;
}
}
void topology()
{
int i,u,v,t[10],s[10],top=-1,k=0;
find_indegree();
for(i=0;i
{
if(indegree[i]==0) s[++top]=i;
}
while(top!=-1)
{
u=s[top--];
t[k++]=u;
for(v=0;v
{
if(a[u][v]==1)
{
indegree[v]--;
if(indegree[v]==0) s[++top]=v;
}
}
}
printf("The topological Sequence is:\n");
for(i=0;i
printf("%d ",t[i]);
}
void main()
{
int i,j;
clrscr();
printf("Enter number of jobs:");
scanf("%d",&n);
printf("\nEnter the adjacency matrix:\n");
for(i=0;i
{
for(j=0;j
scanf("%d",&a[i][j]);
}
topology();
getch();
}