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

// Experiment 5

// Pratyush Warungase 22AM1031

#include <stdio.h>

#define MAX_VERTICES 100

#define INFINITY 999999

void main() {

int adj[MAX_VERTICES][MAX_VERTICES];

int distance[MAX_VERTICES];

int path[MAX_VERTICES];

int visited[MAX_VERTICES];

int v, e, source, dest;

for (int i = 1; i <= v; i++) {

distance[i] = INFINITY;

path[i] = 0;

visited[i] = 0;

distance[source] = 0;

int basicOperations = 0;

for (int nv = 1; nv <= v; nv++) {

int current = source;

visited[current] = 1;

int T = 0;

for (int i = 1; i <= v; i++) {

basicOperations++;

if (adj[current][i] != 0 && visited[i] != 1) {

basicOperations++;

if (distance[i] > adj[current][i] + T) {

basicOperations++;

distance[i] = adj[current][i] + T;
path[i] = current;

int min = INFINITY;

for (int i = 1; i <= v; i++) {

basicOperations++;

if (visited[i] != 1 && distance[i] < min) {

basicOperations++;

min = distance[i];

current = i;

visited[current] = 1;

nv++;

T = distance[current];

int y = dest;

do {

int x = path[y];

printf("Vertex %d is connected to Vertex %d\n", y, x);

y = x;

} while (y != source);

printf("Shortest distance from source to destination: %d\n", distance[dest]);

printf("Number of basic operations: %d\n", basicOperations);

You might also like