Ada Lab Manual
Ada Lab Manual
For
Analysis and Design of Algorithms
(3150703)
Branch: Computer
Engineering Academic Year:
2021 – 2022 Prepared By:
Monali Panchal
PRACTICAL – 1
AIM: Implementation & Time analysis of sorting algorithms.
(Bubble sort, Selection sort, Insertion sort, Merge sort, Quick sort)
1) Bubble Sort
Code:
#include<stdio.h>
#include<conio.h
> #define SIZE 20
void bubblesort(int A[SIZE],int );
void main()
{
int A[SIZE], i, n;
clrscr();
printf("\n******************* Bubble Sort *******************\n");
printf("\nEnter the number of elements you want to enter: ");
scanf("%d",&n);
for (i=0; i<n;i++)
{
printf("\nEnter %d Element: ",i+1);
scanf("%d",&A[i]);
}
bubblesort(A,n);
getch();
}
void bubblesort(int A[SIZE],int n)
{
int i, j, m, temp;
for (i=0;i<n-1;i++)
{
for (j=0;j<n;j++)
{
if(A[j] > A[j+1])
{
BAIT, Page 1
ADA [3150703]
temp = A[j];
A[j] = A[j+1];
A[j+1] = temp;
}
}
}
printf("\nSorted Array is: \n");
for (i=0;i<n;i++)
{
printf("\t%d",A[i]);
}
}
Output:
BAIT, Page 2
ADA [3150703]
2) Selection Sort
Code:
#include<stdio.h>
#include<conio.h
> #define SIZE 20
void selection(int A[SIZE], int);
void main()
{
int A[SIZE], n, i;
clrscr();
printf("\n********************* Selection Sort *********************\n");
printf("Enter the number you want to inseart: ");
scanf("%d",&n);
for (i=0;i<n;i++)
{
printf("\nEnter %d Element: ",i+1);
scanf("%d",&A[i]);
}
selection(A, n);
getch();
}
void selection(int A[SIZE], int n)
{
int min, j, i, temp;
for (i=0; i<n-2; i++)
{
min = i;
for(j=i+1; j<=n-1; j++)
{
if(A[j]< A[min])
{
min = j;
}
BAIT, Page 3
ADA [3150703]
}
temp = A[i];
A[i] = A[min];
A[min] = temp;
}
printf("Sorted Array is : \n");
for(i=0; i<n; i++)
{
printf("\t%d",A[i]);
}
}
Output:
BAIT, Page 4
ADA [3150703]
3) Insertion Sort
Code:
#include<stdio.h>
#include<conio.h
> #define SIZE 20
void insertion(int A[SIZE], int n);
void main()
{
int A[SIZE],n,i;
clrscr();
printf("\n***************** Insertion Sort
*****************"); printf("\nNumber of elements you want in
Array: "); scanf("%d",&n);
for(i=0; i<n; i++)
{
printf("Enter the %d element: ",i+1);
scanf("%d",&A[i]);
}
insertion(A, n);
getch();
}
void insertion(int A[SIZE],int n)
{
int i,j,temp;
for(i=1;i<=n-1;i++)
{
temp = A[i];
j=i-1;
while((j>=0) && (A[j]>temp))
{
A[j+1]=A[j];
j--;
BAIT, Page 5
ADA [3150703]
}
A[j+1] = temp;
}
printf("\nSorted Array is: \n");
for (i=0; i<n; i++)
{
printf("\t%d",A[i]);
}
}
Output:
BAIT, Page 6
ADA [3150703]
4) Merge Sort
Code:
#include<stdio.h>
#include<conio.h
> #define SIZE 20
void MergeSort(int A[SIZE], int, int);
void Display(int A[SIZE], int);
void Combine(int A[SIZE], int, int, int);
void main()
{
int i,low, high, n, A[SIZE];
clrscr();
printf("\n***************** Merge Sort ******************\n");
printf("Number of Elements you want in Array: ");
scanf("%d",&n);
for (i=0; i<n; i++)
{
printf("\nEnter %d Element: ",i+1);
scanf("%d",&A[i]);
}
low = 0;
high = n-1;
MergeSort(A, low, high);
Display(A, n);
getch();
}
void MergeSort(int A[SIZE], int low, int high)
{
int mid;
if(low < high)
{
mid = (low + high)/2;
MergeSort(A, low, mid);
BAIT, Page 7
ADA [3150703]
BAIT, Page 8
ADA [3150703]
}
for (k = low; k <= high; k++)
{
A[k] = temp[k];
}
}
void Display(int A[SIZE], int n)
{
int i;
printf("\n\nSorted Array is \n");
for (i = 0; i<n; i++)
printf("\t%d",A[i]);
}
Output:
BAIT, Page 9
ADA [3150703]
5) Quick Sort
Code:
#include<stdio.h>
#include<conio.h
> #define SIZE 20
void Quick(int A[SIZE],int,int);
int Partition(int A[SIZE],int,int);
void swap(int A[SIZE], int*, int*);
int n;
int main()
{
int i;
int A[SIZE];
clrscr();
printf("\n**************Quick Sort Method****************\n");
printf("\n Enter Total Numbet to Insert into Array: ");
scanf("%d",&n);
for (i=0; i<n; i++)
{
printf("\n Enter %d Number: ",i+1);
scanf("%d",&A[i]);
}
Quick(A,0,n - 1); printf("\n\
tSorted Array is: \n");
BAIT, Page
ADA [3150703]
while (i<=j)
{
while (A[i] <= pivot)
{
i = i + 1;
}
while(A[j] >pivot){
j = j - 1;
}
if(i<j){
swap(A, &i, &j);
}
}
swap(A, &low, &j);
return j;
}
BAIT, Page
ADA [3150703]
Output:
BAIT, Page
ADA [3150703]
PRACTICAL – 2
AIM: Implementation & Time analysis of linear and binary search
algorithm.
1) Linear Search
Code:
#include<stdio.h>
#include<conio.h
> #define SIZE 25
int search(int A[SIZE], int, int);
void main()
{
int A[SIZE], key, st=0, n, i;
clrscr();
printf("\n**************** Linear Search ****************\n");
printf("\nNumber of elements in Array: ");
scanf("%d",&n);
for(i=0; i< n; i++)
{
printf("\nEnter %d Element: ", i+1);
scanf("%d",&A[i]);
}
printf("\nEnter the Element Which You Wish to Search: ");
scanf("%d",&key);
st = search(A, key, n);
if(st == 0)
{
printf("\nElement is Not Found");
}else
{
printf("\nElement is Present at A[%d] ",st);
}
getch();
}
BAIT, Page
ADA [3150703]
Output:
BAIT, Page
ADA [3150703]
2) Binary Search
Code:
#include<stdio.h>
#include<conio.h
> #define SIZE 25
int BinSearch(int A[SIZE], int, int, int);
void main()
{
int A[SIZE], key, st=0, n, i, low, high;
clrscr();
printf("\n**************** Binary Search ****************\n");
printf("\nNumber of elements in Array: ");
scanf("%d",&n);
for(i=0; i< n; i++)
{
printf("\nEnter %d Element: ", i+1);
scanf("%d",&A[i]);
}
printf("\nEnter the Element Which You Wish to Search: ");
scanf("%d",&key);
low = 0;
high = n-1;
st = BinSearch(A, key, low, high);
if(st == 0)
{
printf("\nElement is Not Found");
}else
{
printf("\nElement is Present at A[%d] ",st);
}
getch();
}
int BinSearch(int A[SIZE], int key, int low, int high)
{
BAIT, Page
ADA [3150703]
int mid;
mid = (low+high)/2;
if(key == A[mid])
return mid;
else if(A[mid] > key)
BinSearch(A, key, low, mid - 1);
else
Output:
BAIT, Page
ADA [3150703]
PRACTICAL – 3
AIM:Implementation of max-heap sort algorithm.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define MAX 10
int main(){
int i,n;
int arr[MAX];
void makeHeap(int arr[MAX], int n);
void heapSort(int arr[MAX], int n);
void display(int arr[MAX], int n);
for ( i = 0; i< MAX; i++)
{
arr[i] = 0;
}
printf("\n How many element you want to insert ? \n ");
scanf("%d",&n);
printf("\n Enter the element : \n ");
for ( i = 0; i< n; i++)
{
scanf("%d",&arr[i]);
}
printf("\n The elements are : ");
display(arr,n);
makeHeap(arr,n);
printf("\n Heapified ");
display(arr,n);
heapSort(arr,n);
printf("\n Element sorted by heap sort");
display(arr,n);
getch();
BAIT, Page
ADA [3150703]
return 0;
}
void makeHeap(int arr[MAX], int n){
int i,val,j,father;
for ( i = 1; i< n; i++){
val = arr[i];
j = i;
father = (j-1)/2;
while (j>0 &&arr[father]<val){
arr[j] = arr[father];
j = father;
father = (j-1)/2;
}
arr[j] = val;
}
}
void heapSort(int arr[MAX], int n){
int i,k,temp,j;
for ( i = n-1; i> 0; i--){
temp = arr[i];
arr[i] = arr[0];
k = 0;
if (i == 1){
j = -1;
}
else{
j = 1;
}
if (i>2 &&arr[2] >arr[1]){
j = 2;
}
while (j >= 0 && temp <arr[j]){
arr[k] = arr[j];
k = j;
BAIT, Page
ADA [3150703]
j = 2*k+1;
if (j+1 <= i-1 &&arr[j]<arr[j+1]){
j++;
}
else{
j = -1;
}
}
arr[k] = temp;
}
}
void display(int arr[MAX], int n){
int i;
for ( i = 0; i< n; i++) {
printf("\n %d",arr[i]);
}
printf("\n");
}
Output:
BAIT, Page
ADA [3150703]
BAIT, Page
ADA [3150703]
PRACTICAL – 4
AIM:Implementation & Time analysis of factorial program using iterative
and recursive method.
1) Iterative Method
Code:
#include<stdio.h>
#include<conio.h
void main()
{
int n;
long f;
long fact(int n);
clrscr();
printf("Enter a number: ");
scanf("%d", n);
if(n<0)
{
printf("Negative Integers are not allowed");
}else{
f = fact(n);
printf("Factorial of %n is %ld ", n, f);
}
getch();
}
long fact(int n)
{
int i;
long f = 1;
for (i=1; i<=n; i++)
{
f = f*i;
}
return f;
BAIT, Page
ADA [3150703]
}
Output:
2) Recursive Method
Code:
#include<stdio.h>
#include<conio.h
> void main()
{
int n;
long f;
long fact(int n);
printf("Enter a Number: ");
scanf("%d", &n);
if (n<0)
{
printf("Negative integers are not allowed.");
}
else{
f = fact(n);
printf("Factorial of %d is %ld.", n, f);
}
getch();
}
long fact(int
n)
{
if (n == 0)
{
return 1;
BAIT, Page
ADA [3150703]
BAIT, Page
ADA [3150703]
}
else {
return (n*fact(n-1));
}
}
Output:
BAIT, Page
ADA [3150703]
PRACTICAL – 5
AIM:Implementation of a knapsack problem using dynamic programming.
Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int table[5][6];
int max(int, int);
void main()
{
int w[]={0,2,3,4,5};
int v[]={0,23,4,15,19};
int W=5;
int n=4;
int i,j;
void DKP(int n,intW,int w[],int v[]);
clrscr();
printf("\n\t\t Knapscak problem using dynamic programming:");
printf("\n given data...\n");
printf("\n w[i] v[i]");
printf("\n _");
for(i=1;i<=n;i++)
printf("\n %d %d", w[i], v[i]);
printf("\n\n Capacity = %d",W);
printf("\n\n");
for(i=0;i<=n;i++)
{
for(j=0;j<=W;j++)
{
table[i][j]=0;
}
BAIT, Page
ADA [3150703]
}
DKP(n,W,w,v);
}
void DKP(int n,intW,int w[5],int v[5])
{
int i,j;
int val1,val2;
void find_item(int, int, int[]);
for(i=0;i<=n;i++)
{
for(j=0;j<=W;j++)
{
table[i][0]=0;
table[0][j]=0;
}
}
for(i=1;i<=W;i++)
{
for(j=1;j<=W;j++)
{
if(j < w[i])
table[i][j] = table[i-1][j];
else if(j >= w[i])
{
val1 = table[i-1][j];
val2 = v[i] + table[i-1][j-w[i]];
table[i][j] = max(val1,val2);
}
}
}
printf("\n Table constructed using dynamic programing id...\n");
for(i=0;i<=n;i++)
{
for(j=0; j<=W; j++)
BAIT, Page
ADA [3150703]
return a;
}
else
{
return b;
}
}
void find_item(int i,intk,int w[5])
{
printf("\n Solution for the knapsack...");
while(i>0 && k>0)
{
if(table[i][k] != table[i-1][k])
{
printf("\n Item %d is selected",i);
i=i-1;
k = k-w[i];
}
else
i=i-1;
}
}
BAIT, Page
ADA [3150703]
Output:
BAIT, Page
ADA [3150703]
PRACTICAL – 6
AIM: Implementation of chain matrix multiplication using dynamic
programming.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int n, i, cost, p[100], s[20][20];
int Matrix_chain(int s[20][20], int p[], int, int);
void display_matrix_order(int s[20][20], int i, int j);
clrscr();
printf("\n\t\tChain Matrix Multiplication Using Dynamic Programming\n");
printf("\n Enter the number of matrices: ");
scanf("%d", &n);
for(i=0; i<n+1; i++)
{
printf("\n Enter the Dimension of the matrix: ");
scanf("%d", &p[i]);
}
cost = Matrix_chain(s, p, 1, n);
printf("\n The Optimal Cost: %d\n", cost);
printf("\n The Optimal Order: ");
display_matrix_order(s, 1, n);
getch();
}
BAIT, Page
ADA [3150703]
return 0;
for(k=i; k<j; k++)
{
count = Matrix_chain(s, p, i, k) + Matrix_chain(s, p, k+1, j) + p[i-1] *
p[k] *
p[j];
if (count < min)
{
min = count;
s[i][j]= k;
}
}
return min;
}
void display_matrix_order(int s[20][20], int i, int j)
{
if(i == j)
printf("A%d ", i);
else
{
printf("( ");
display_matrix_order(s, i, s[i][j]);
display_matrix_order(s, s[i][j] + 1, j);
printf(") ");
}
}
BAIT, Page
ADA [3150703]
BAIT, Page
ADA [3150703]
Output:
BAIT, Page
ADA [3150703]
PRACTICAL – 7
AIM: Implementation of making a change problem using dynamic
programming.
Code:
#include<stdio.h>
#include<conio.h>
#define MAX 20
int main()
{
int d[5];
int NumberofCoins(int [10], int, int);
int n,N,i;
BAIT, Page
ADA [3150703]
BAIT, Page
ADA [3150703]
return x;
else
return y;
}
Output:
BAIT, Page
ADA [3150703]
BAIT, Page
ADA [3150703]
PRACTICAL – 8
AIM:Implementation of a knapsack problem using greedy programming.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, n;
float p[15], w[15], c[15], temp, m;
clrscr();
printf("\n Enter Number of Objects: ");
scanf("%d", &n);
printf("\n Enter Weights: ");
for(i=0; i<n; i++)
scanf(" %f", &w[i]);
flushall();
printf("\n Enter Profit: ");
for(i = 0;i<n;i++)
scanf(" %f", &p[i]);
printf("\n Enter knapsack size: ");
scanf(" %f", &m);
for(i=0; i<n;i++)
{
for(j=0; j<n-1; j++)
{
BAIT, Page
ADA [3150703]
temp = w[i];
w[i] = w[i+1];
w[i+1] = temp;
temp = p[j];
p[j] = p[j+1];
p[j+1] = temp;
}
}
}
printf("\n The items are arranged as....\n");
printf("\n\n\tItems\tWeight\tProfit");
for(i=0;i<n; i++)
printf("\n\tx[%i]\t%.0f\t%.0f", i, w[i], p[i]);
knapsack(n, m, w, p);
getch();
}
for(i=0; i<n;i++)
x[i] = 0.0;
for (i=0; i<n; i++)
BAIT, Page
ADA [3150703]
if(w[i] >U)
break;
x[i] = 1.0;
U= U-w[i];
}
if(i<n
)
x[i] = U/w[i];
BAIT, Page
ADA [3150703]
Output:
BAIT, Page
ADA [3150703]
PRACTICAL – 9
AIM:Implementation of Graph and Searching (DFS and BFS).
1) Depth First
Search Code:
#include<stdio.h>
#include<conio.h
> #define MAX
20
#define TRUE 1
#define FALSE 0
int g[MAX][MAX];
int v[MAX];
int n;
void main()
{
int v1, v2;
char ans;
void
create();
void DFS(int);
clrscr();
create();
printf("The Adjacency Matrix For The Graph is\n");
for (v1 = 0; v1<n; v1++)
{
for(v2=0; v2<n; v2++)
{
printf("%d ", g[v1][v2]);
}
printf("\n");
}
BAIT, Page
ADA [3150703]
getch();
BAIT, Page
ADA [3150703]
do{
for(v1=0;v1<n; v1++)
v[v1] = FALSE;
printf("Enter the Vertex from yo want to traverse: ");
scanf("%d", &v1);
if(v1 >= MAX)
printf("Invaild Vertex\n");
else
{
void create()
{
int ch, v1, v2, flag;
char ans = 'y';
printf("\n\t\t This is Program to Create Graph");
printf("\n\t\t The Display is in Depth First Manner");
getch();
flushall();
for (v1=0; v1<n; v1++)
for(v2=0; v2<n; v2++)
g[v1][v2] = FALSE;
printf("\n Enter no. Nodes");
scanf("%d", &n);
printf("\n Enter the Vertices no. starting from 0");
do{
printf("\nEnter the vertices v1 and v2 ");
BAIT, Page
ADA [3150703]
g[v1][v2] = TRUE;
g[v2][v1] = TRUE;
}
printf("\n\n Add more edges(y or n)");
ans= getch();
}while(ans == 'y');
}
BAIT, Page
ADA [3150703]
Output:
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#define size 20
#define TRUE 1
#define FALSE 0
int g[size][size];
int visit[size];
BAIT, Page
ADA [3150703]
int Q[size];
int front,rear;
int n;
void main()
{
int v1,v2;
char ans= 'y';
void create(),bfs(int);
clrscr();
create();
printf("The adjacency for the graph is \n");
for(v1=1;v1<n;v1++)
{
for(v2=0;v2<n;v2++)
printf("%d ",g[v1][v2]);
printf("\n");
}
do
{
for(v1=0;v1<n;v1++)
visit[v1]=FALSE;
}while(ans=='y');
getch();
}
void create()
{
int v1,v2;
char ans='y';
printf("\n\t\t This is a program to create a graph:");
printf("\n\t\t The Display is in Breadth First manner:");
printf("\n Enter no.of nodes:");
scanf("%d",&n);
for(v1=0;v1<n;v1++)
for(v2=0;v2<n;v2++)
g[v1][v2]=FALSE;
printf("\n Enter the vertices no. staring from 0:");
do
{
printf("\n Enter the vertices v1&v2:");
scanf("%d%d",&v1,&v2); if(v1>=n||
v2>=n)
printf("invalid vertex value: \n");
else
{
g[v1][v2]=TRUE;
g[v2][v1]=TRUE;
}
printf("\n\n Add more edges??(Y/N):");
ans=getche();
}while(ans=='y');
}
void bfs(int v1)
{
int v2;
BAIT, Page
ADA [3150703]
visit[v1]=TRUE;
front=rear=-1;
Q[++rear]=v1;
while(front!
=rear)
{
v1 = Q[++front];
printf("%d\n",v1);
for(v2=0;v2<n;v2++)
{
if(g[v1][v2]==TRUE && visit[v2]==FALSE)
{
Q[++rear]=v2;
visit[v2]=TRUE;
}
}
}
}
Output:
BAIT, Page
ADA [3150703]
BAIT, Page
ADA [3150703]
BAIT, Page
ADA [3150703]
PRACTICAL – 10
AIM:Implement Prim’s algorithm.
Code:
#include<stdio.h>
#include<conio.h
> #define SIZE 20
#define INFINITY 999
void main()
{
int G[SIZE][SIZE], nodes;
int v1, v2, length, i, j, n;
void prims(int G[SIZE][SIZE], int nodes);
clrscr();
printf("\n\t Prim's Algorithm \n");
printf("\n Enter Number of Nodes in The Graph: ");
scanf("%d", &nodes);
printf("\n Enter Number of Edges in The Graph: ");
scanf("%d", &n);
BAIT, Page
ADA [3150703]
getch(); printf("\
n\t"); prims(G,
nodes); getch();
}
void prims(int G[SIZE][SIZE], int nodes)
{
int tree[SIZE], i, j, k;
int min_disk, v1, v2, total = 0;
for (i=0; i<nodes; i++)
tree[i] = 0;
printf("\nThe Minimal Spaning Tree is: ");
tree[0] = 1;
for(k = 1; k<=nodes-1;k++)
{
min_disk = INFINITY;
for (i=0; i<=nodes-1; i++)
{
for(j=0; j<=nodes-1; j++)
{
if(G[i][j] && ((tree[i] && !tree[j]) || (!tree[i] &&
tree[j])))
{
if(G[i][j] <min_disk)
{
min_disk = G[i][j];
v1 = i;
v2 = j;
}
}
}
}
printf("\n Edge (%d %d) and Weight = %d", v1, v2, min_disk);
tree[v1] = tree[v2] = 1;
BAIT, Page
ADA [3150703]
Output:
BAIT, Page
ADA [3150703]
PRACTICAL – 11
AIM:Implement Kruskal’s algorithm.
Code:
#include<stdio.h>
#include<conio.h>
int v1;
int v2;
int cost;
}GR;
GR G[20];
void create();
void spanning_tree();
int minimum(int);
void main()
clrscr();
create();
spanning_tree();
getch();
void create()
BAIT, Page
ADA [3150703]
int k;
scanf("%d", &tot_nodes);
scanf("%d", &tot_edges);
scanf("%d", &G[k].cost);
void spanning_tree()
int sum, i, j;
count = 0;
k = 0;
sum = 0;
parent[i] = i;
BAIT, Page
ADA [3150703]
while(count!=tot_nodes-1)
pos = minimum(tot_edges);
if (pos == -1)
break;
v1 = G[pos].v1;
v2 = G[pos].v2;
i = find(v1, parent);
j = find(v2, parent);
if (i!=j)
tree[k][0] = v1;
tree[k][1] = v2;
k++;
count++;
sum += G[pos].cost;
Union(i, j, parent);
G[pos].cost = INFINITY;
if(count == tot_nodes-1)
BAIT, Page
ADA [3150703]
printf("[%d", tree[i][0]);
printf("-");
printf("%d", tree[i][1]);
printf("]");
}else{
int minimum(int n)
small = INFINITY;
pos = -1;
if(G[i].cost< small)
small = G[i].cost;
pos = i;
return pos;
BAIT, Page
ADA [3150703]
while(parent[v2] != v2)
v2 = parent[v2];
return v2;
if(i<j)
parent[j] = i;
else
parent[i] = j;
BAIT, Page
ADA [3150703]
Output:
BAIT, Page
ADA [3150703]
PRACTICAL – 12
AIM:Implement LCS problem.
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define SIZE 20
void compute_LCS(char A[SIZE], char B[SIZE]);
void main()
{
char A[SIZE],B[SIZE];
clrscr();
printf("\n Enter first sequence:");
scanf("%s",A);
printf("Enter second sequence:");
scanf("%s",B);
compute_LCS(A,B);
getch();
}
void compute_LCS(char A[],char B[])
{
int m,n,i,j;
int c[SIZE][SIZE];
char d[SIZE][SIZE];
void display(char[][SIZE],char[],int,int);
m = strlen(A);
n = strlen(B);
for(i=0;i<=m;i++)
c[i][0]=0;
for(i=0;i<=n;i++)
BAIT, Page
ADA [3150703]
c[0][i]=0;
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
if(A[i-1]==B[j-1])
{
c[i][j]=c[i-1][j-1]+1;
d[i][j]='\ ';
}
else if(c[i-1][j] >= c[i][j-1])
{
c[i][j] = c[i-1][j];
d[i][j] = '^';
}
else
{
c[i][j]=c[i][j-1];
d[i][j]='<-';
}
}
}
printf("\n Table is...\n");
for(i=0;i<=m;i++)
{
for(j=0; j<=n;j++)
{
printf("%3d",c[i][j]);
}
printf("\n");
}
printf("\n The longest common subsequence is...\n");
display(d,A,m,n);
BAIT, Page
ADA [3150703]
}
void display(char d[][SIZE],char A[],int i,int j)
{
if(i==0||j==0)
return;
if(d[i][j]=='\ ')
{
display(d,A,i-1,j-1);
printf("%c",A[i-1]);
}
else if(d[i][j]=='^')
display(d,A,i-1,j);
else
display(d,A,i,j-1);
}
Output:
BAIT, Page