# EE390 - Lab - Graphs

1. Represent the graph using Adjacency matrix. 2. Represent the graph using Adjacency list. 3. Implement the BFS to print all elements. 4. Implement the DFS to print all elements. 5. Print the radius, diameter and circumeference of the graph.
Nikitha2309
c_cpp
2 years ago
6.0 kB
3
Indexable
Never
```#include <bits/stdc++.h>
using namespace std;

{
}

{
int i, j;

for(i = 1; i <= V; i++)
{
for(j = 1; j <= V; j++)
{
}
cout<<endl;
}
cout<<endl;
}

{
}

{
for (int v = 1; v <= V; ++v) {
cout << "Adjacency list of vertex " << v << " :";
cout << " " << x;
cout<<endl;
}
cout<<endl;
}

{
cout<<"DFS TRAVERSAL : ";
stack<int>stk;//stack in STL
stk.push(s);
vector<bool> visit(V+1,false);
visit[s]=true;
while(!stk.empty()){
int u=stk.top();
cout<<u<<" ";
stk.pop();
//loop for traverse
}
}
}
cout<<endl<<endl;
}

{
cout<<"BFS TRAVERSAL : ";
queue<int>q;//queue in STL
q.push(s);
vector<bool> visit(V+1,false);
visit[s]=true;
while(!q.empty()){
int u=q.front();
cout<<u<<" ";
q.pop();
//loop for traverse
}
}
}
cout<<endl<<endl;
}

void compute_Distances(vector<int> adj[],int V, vector<vector<int>> &D)
{
for(int i = 1; i<=V; i++)
{
D[i][i] = 0;
}
for(int i = 1; i<=V; i++)
{
{
D[i][j] = 1;
D[j][i] = 1;
}
}
for(int k = 1; k<=V; k++)
{
for(int i = 1; i<=V; i++)
{
for(int j = 1; j<=V; j++)
{
D[i][j] = min(D[i][j],D[i][k]+D[k][j]);
}
}
}
}

void print_DistanceMatrix(vector<vector<int>> D, int V)
{
cout<<"DISTANCES MATRIX :\n";
for(int i = 1; i<=V; i++)
{
for(int j = 1; j<=V; j++)
{
cout<<D[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
}

void compute_Eccentricity( vector<vector<int>> D,int V, vector<int> &E)
{
for(int i = 1; i<=V; i++)
{
int mx = D[i][1];
for(int j = 1; j<=V; j++)
mx = max(mx,D[i][j]);
E[i] = mx;
}
return;
}

void print_Eccentricity(vector<int> E, int V)
{
cout<<"ECCENTRICITIES : ";
for(int i = 1; i<=V; i++)
{
cout<<E[i]<<" ";
}
cout<<endl;
cout<<endl;
}

{
for(int i = 2; i<=V; i++)
}

int compute_Diameter(vector<int> E, int V)
{
int diameter = E[1];
for(int i = 2; i<=V; i++)
diameter = max(diameter,E[i]);
return diameter;
}

void cycleDfs(vector<int> adj[], vector<bool> &vis, int currLen,int &maxLen,int node, int parent)
{
{
if(u==parent)
{
maxLen = max(maxLen,currLen+1);
}
else if(!vis[u])
{
vis[u] = true;
vis[u] = false;
}
}
}

int compute_Circumference(vector<int> adj[],int V, int node)
{
int circumference = -1;
for(int i = 1; i<=V; i++)
{
int maxLen = -1;
vector<bool> vis(V+1,false);
vis[node] = true;
circumference = max(circumference,maxLen);
}
return circumference;
}

int main()
{
// Number of Vertices
int V = 6;

// 1. Represent the graph using Adjacency matrix.

// 2. Represent the graph using Adjacency list.

// 3. Implement the BFS to print all elements.

// 4. Implement the DFS to print all elements.

// 5. Print the radius, diameter and circumeference of the graph.
vector<vector<int>> D(V+1,vector<int>(V+1,100000));
vector<int> E(V+1,-1);