0% found this document useful (0 votes)
16 views3 pages

Algorithm

nothing to say

Uploaded by

Bhaskor Roy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

Algorithm

nothing to say

Uploaded by

Bhaskor Roy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Problem 01: Graph coloring with fixed

number of color.

#include<bits/stdc++.h>
using namespace std; }
bool G[100][100]={0};
int x[100]={0}; int main(){
int c=0,m=3; cout<<"Enter the number of vertex"<<endl;
int n=5; int n;
void nextvalue(int k){ cin>>n;
x[k]=(x[k]+1)%(m+1); while(n--){
if(x[k]==0) int x,y;
return ; cin>>x>>y;
int j; G[x][y]=G[y][x]=1;
for(j=1;j<=n;j++){ }

if(G[k][j]!=0 && x[k]==x[j]) clock_t st,et;


break; st=clock();
mColoring(1);
} et=clock();
if(j==n+1) double ex=et-st;
return ; cout<<ex<<endl;
return 0;
nextvalue(k); }

} }
Problem 02: Sum of subset finding
void mColoring(int k){ from an Array.
nextvalue(k); #include<bits/stdc++.h>
if(x[k]==0)
using namespace std;
return ;
int x[1000]={0};
if(k==n) void sumofsub(int s,int k,int r,int w[],int m){
{
//k=k-1;
for(int i=1;i<=n;i++){
x[k]=1;
cout<<x[i]<<" "; if(s+w[k]==m)
}
{
cout<<endl;
for(int i=0;i<=k;i++){
} cout<<x[i]<<" ";
else
}
mColoring(k+1);
cout<<endl;
mColoring(k); }
else if(s+w[k]+w[k+1]<=m) while(true){
sumofsub(s+w[k],k+1,r-w[k],w,m); x[k]=(x[k]+1)%(n+1);
if((s+r-w[k]>=m) && (s+w[k+1]<=m)){ if(x[k]==0)
x[k]=0; return ;
sumofsub(s,k+1,r-w[k],w,m); if(G[x[k-1]][x[k]]!=0){
} int j;
} for(j=1;j<=k-1;j++){
if(x[j]==x[k])
int main(){ break;
int n,m; }
cin>>n>>m; if(j==k){
int w[n]; if(k<n || (k==n && G[x[n]][x[1]]!=0)){
int s=0,k=0,r=0; return ;
}
for(int i=0;i<n;i++){ }
w[i]=rand()%10+1;
r+=w[i]; }
}
} }
void hamiltonian(int k){
for(int i=0;i<n;i++){ while(true){
cout<<w[i]<<" "; nextvalue(k);
if(x[k]==0)
} return ;
cout<<endl; if(k==n){
for(int i=1;i<=n;i++){
clock_t st,et; cout<<x[i]<<" ";
st=clock(); }
sumofsub(s,k,r,w,m); cout<<endl;
et=clock(); }
double ex=et-st; else{
cout<<ex<<endl; hamiltonian(k+1);
return 0; }
} }
Problem 03: Finding how many cycle by using }
Hamiltonian cycle algorithm. int main(){
#include<bits/stdc++.h> cout<<"Enter the number of vertex : "<<endl;
using namespace std; cin>>n;
int x[100]={0}; cout<<"Enter the number of edges: "<<endl;
bool G[100][100]={0}; int e;
int n; cin>>e;
void nextvalue(int k){ while(e--){
Problem 02 execution time analysis graph:

int x,y;
cin>>x>>y;
G[x][y]=G[y][x]=1;
}
x[1]=1;
hamiltonian(2);

return 0;
}

Problem 03 execution time analysis Graph:

You might also like