Upload
kiran-wadeyar
View
237
Download
0
Embed Size (px)
DESCRIPTION
cse mtech ada lab programs
Citation preview
/*Program to Implement the Bellman-Ford algorithm */
ADVANCED ALGORITHMS
Laboratory Work
1. Design, develop, and run a program in any language to implement the Bellman-Ford algorithm and determine its performance.
2. Design, develop, and run a program in any language to implement Johnsons algorithm and determine its performance.
3. Design, develop, and run a program in any language to implement a Monte Carlo algorithm to test the primality of a given integer and determine its performance.
4. Design, develop, and run a program in any language to solve the string matching problem using nave approach and the KMP algorithm and compare their performances.
5. Design, develop, and run a program in any language to solve modular linear equations.
6. Design, develop, and run a program in any language to implement the FFT algorithm efficiently.
/*Program to Implement the Bellman-Ford algorithm */
#include
#include
#define INFINITY 1000
#define SIZE 100
#define TRUE 1
#define FALSE 0
typedef struct {
int u, v, w ;
} Edge;
Edge edges[SIZE];
int e,n,d[SIZE],pre[SIZE],temp[SIZE];
void initialise(int s)
{ int i;
for (i = 0; i < n; ++i)
{d[i] = INFINITY;
pre[i]=0;
}
d[s] = 0;
}
void relax()
{ int i,j ;
for (i = 1; i 1->1->5->1
DISTANCE and PATH to Node4:
Distance:-2
Path: 1->1->1->1->5->1
DISTANCE and PATH to Node5:
Distance:7
Path: 1->1->1->1->5 */
/* Program to Implement Johnson's Algorithm for Sparse Graph*/
#include
#include
#define INFINITY 1000
#define SIZE 100
#define TRUE 1
#define FALSE 0
typedef struct {
int inode, enode;
float weight,nweight ;
} Edge;
Edge edges[SIZE];
int e,eno,pre[SIZE],temp[SIZE],h[SIZE];
int numOfVertices,adjMatrix[10][10],source;
int predecessor[15],distance[15],dist[20][20];
int mark[20];
void johnson();
void initialise(int s)
{ int i;
for (i = 0; i < numOfVertices; ++i)
{distance[i] = INFINITY;
pre[i]=0;
}
distance[s] = 0;
}
void relax()
{ int i,j ;
for (i = 1; i