Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

AOA Lab

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 29

12/18/23, 5:07 PM AOALAB

AOA LAB
2021pceitashish012@poornima.org Switch accounts

Not shared

3.
a. Obtain the Topological ordering of vertices in a given digraph.
b. Computethe transitive closure of a given directed graph using
Warshall's algorithm.

Your answer

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 1/29
12/18/23, 5:07 PM AOALAB

3.A. PART ONE

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 2/29
12/18/23, 5:07 PM AOALAB

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 3/29
12/18/23, 5:07 PM AOALAB

3.A. PART TWO

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 4/29
12/18/23, 5:07 PM AOALAB

3.8.PART ONE

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 5/29
12/18/23, 5:07 PM AOALAB

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 6/29
12/18/23, 5:07 PM AOALAB

3..B.PART TWO

5.From a given vertex in a weighted connected graph, find shortest paths


toother
vertices using Dijkstra's algorithm

Your answer

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 7/29
12/18/23, 5:07 PM AOALAB

CODE part 1

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 8/29
12/18/23, 5:07 PM AOALAB

#include<stdio.h>
#include<conio.h>
#define HEFIN ITY 9999
1

#d.ef"ine MAX 10

void dijkstra(illlt G[MAX][MAXLint n,,irllt startnode);,

int main()
{
int G[MAX] [MAX],,i.,.j, n,.u;,
printf( "Enter no. of vertices:");.
scanf( "%d" ,&n) ;.
prirrtf(''\nEllter the adjacency matrix: \n");
for(i:iO;.i<n;.i++)
for(j=O_;.j <n_;.j++)
scanf( "%d" ,&G[i] [ j]) ;.
prirrtf(''\nEllter the st,;wting· node:");,
scanf ("%d", &u) ;,
dij kstra (G, n, u) ;,
return 0;.
}

void dijkstra(illlt G[MAX][MAXL int n.,,fot startnode)


{

int cost.[MAX] [MAX], di.stance [MAX], pred[MAX];


int visited [MAX]_,count..1mindistance..1nextnode, i,.j ;.
//pred [] stores the pred.ecessor of each nod.e
/ /count ,gives the number of nodes seen so f,w
//create the cost matrix
for(i=O_;,i<n;,i++)
for(j=H;.j<n;.j++)
if(G[i][j]==O)
cost.[i] [j ]=I IFINITY;,
else
cost[i] [j ] =G[i] [ j L
/ /initialize pred [ L distance [] and visited[]
for(i:iO;.i<n;.i++)
{

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 9/29
12/18/23, 5:07 PM AOALAB
LIJLLi:lllU= L..L,J=Lo:,, LL. Li:lr"UlUli..l .J L..LJ'
pred [ i] =st:cirtnode;.
vi.sited [ i] =0;.
}

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 10/29
12/18/23, 5:07 PM AOALAB

CODE part 2

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 11/29
12/18/23, 5:07 PM AOALAB

di.stance [ st.artnode
J=:O; visited [startnode]
=1; co1.mt=i;
while(count<n-1)
{
mi11dista11ce=INIFINITY;
/ /nextnode gives the Ro,cle at minimum dist.a
He for(i=O;i<n;i++)
if( di.stance [ i] <min distance&&!vi.sit.ed[ i])
{
mindistBnce=distBnce[i];
nextnode=i;
}
//check if a better p,ath exists through nextnode
visited [ nextnode] =1.;.
for(i=O;i<n;i++)
if(!vi.sited[i])
if(mindistance+cost[nex:tnode][i]<distance[i])
{
distance [ i] =mindist.ance+cost[ nextnode] [ i];
pred[i]=nextnode;
}
COi.Hilt++;
}

//print the path and distance of each node


for( i =0;.i <A;.i ++)
if( i !=startnode)
{
printf ("\nDistance of 11ode%d=%d".JiJ distance [ i]) ;.
printf( "\RPath=%d".Ji);
j=i;
do
{
j=pred[j l;
printf("<-%d"Jj);
}wilil.e(j ! =st.artnode);
}
}I

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 12/29
12/18/23, 5:07 PM AOALAB

q. Implement All-Pairs Shortest Paths Problem using Floyd's algorithm.

Your answer

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 13/29
12/18/23, 5:07 PM AOALAB

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 14/29
12/18/23, 5:07 PM AOALAB

Q. Implement N Queen's problem using Back Tracking.

Your answer

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 15/29
12/18/23, 5:07 PM AOALAB

Queens problem 1

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 16/29
12/18/23, 5:07 PM AOALAB

Queens problem 2

Q.Check whether a given graph is connected or not using DFS


method.

Your answer

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 17/29
12/18/23, 5:07 PM AOALAB

DFS1

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 18/29
12/18/23, 5:07 PM AOALAB

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 19/29
12/18/23, 5:07 PM AOALAB

DFS2

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 20/29
12/18/23, 5:07 PM AOALAB

1. Print all the nodes reachable from a given starting node in a digraph using
BFS
method

Your answer

BFS code1

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 21/29
12/18/23, 5:07 PM AOALAB

BFS code2

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 22/29
12/18/23, 5:07 PM AOALAB

BFS code 3

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 23/29
12/18/23, 5:07 PM AOALAB

BFS code4

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 24/29
12/18/23, 5:07 PM AOALAB

BFS code5

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 25/29
12/18/23, 5:07 PM AOALAB

BFS CODES

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 26/29
12/18/23, 5:07 PM AOALAB

BFS code6

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 27/29
12/18/23, 5:07 PM AOALAB

BFS code7

mit Clear form

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 28/29
12/18/23, 5:07 PM AOALAB

https://docs.google.com/forms/d/e/1FAlpQLSdbd-QdMzpwKO9RjHrKqizKGX2Mo-Oh3e2_WIStw2O1KVzAIQ/viewform?pli=1 29/29

You might also like