Quick Sort
Binary Search
Binary Tree Traversal
Prim's Algorithm
Strassen's Matrix Multiplication
Dijkstra's Algorithm
Knapsack Problem
Subset Sum Problem
Travelling Salesman Problem
Warshall's Algorithm
1 2 3 4 5 6 7 8 9 10
SOURCE CODE
#include”iostream.h”
#include”stdio.h”
#include”conio.h”
#include”iomanip.h”
#define INFINITY 32767
class graph
{
char vertex[15],path[15];
int visited[15],w[15][15],dist[15],i,j,k,d;
public:
graph(int);
void create(int);
void spantree(int);
};
graph::graph(int n)
{
for(i=1;i < =n;i++) { path[i]=0; dist[i]=INFINITY; } } void graph::create(int v) { int n; char m; for(i=1;i < =v;i++) { cin > > vertex[i];
visited[i]=0;
for(j=1;j < =v;j++) w[i][j]=0; } for(i=1;i < =v;i++) { cout < < "\n No Of Adjecency For " < <> > n;
for(j=1;j < =n;j++) { cout < < "Adjecency " < <> > m;
cout < < "Distance Is : "; cin > > d;
for(k=1;k < =v;k++) { if(vertex[k]==m) w[i][k]=d; } } } for(i=1;i < =v;i++) { for(j=1;j < =v;j++) cout < < count="0;"> > source;
for(i=1;i < =n&&vertex[i]!=source;i++) if(i < i="1;i" dec="i;" i="1;i" min="INFINITY;" i="1;i" min="dist[i];" dec="i;" i="1;i" j="1;j" i="1;i"> > ch;
if(ch=='y'ch=='Y')
{
for(i=1;i < =n;i++) { visited[i]=0; dist[i]=INFINITY; path[i]=0; } count=0; goto source; } } void main() { int n; clrscr(); cout < < "\n Enter The Number Of Nodes: "; cin > > n;
graph x(n);
cout < < "\n Enter The Vertex' One By One: \n"; x.create(n); x.spantree(n); getch(); }
SOURCE CODE
#include”iostream.h”
#include”conio.h”
class smm{
int a[2][2],b[2][2],c[2][2];
public:
void smm1();
void strmatmul();
};
void smm::smm1()
{
int i,j;
cout < < "Enter The Values Of A Matrix \n"; for(i=0;i < j="0;j"> > a[i][j];
cout < < "Enter The Values For B Matrix \n"; for(i=0;i < j="0;j"> > b[i][j];
}
void smm::strmatmul()
{
int m[25]={0},i,j;
m[1]=(a[0][0]+a[1][1])*(b[0][0]+b[1][1]);
m[2]=(a[1][0]+a[1][1])*b[0][0];
m[3]=a[0][0]*(b[0][1]-b[1][1]);
m[4]=a[1][1]*(b[1][0]-b[0][0]);
m[5]=(a[0][0]+a[0][1])*b[1][1];
m[6]=(a[1][0]-a[0][0])*(b[0][0]+b[0][1]);
m[7]=(a[0][1]-a[1][1])*(b[1][0]+b[1][1]);
c[0][0]=m[1]+m[4]-m[5]+m[7];
c[0][1]=m[3]+m[5];
c[1][0]=m[2]+m[4];
c[1][1]=m[1]+m[3]-m[2]+m[6];
cout < < "\n STRASSEN'S MATRIX MULTIPLICATION \n"; for(i=0;i < j="0;j">
#include”iostream.h”
#include”stdio.h”
#include”conio.h”
void knapsack(int n,int w);
int n,i,w,W;
int weight[50],v[50],item[10];
int C[50][50];
void main()
{
clrscr();
cout < < "Enter The Number Of Items: ";
cin > > n;
cout < < "Enter capacity : ";
cin > > W;
cout < < "Enter Weights: ";
for(i=1;i < =n;i++)
cin > > weight[i];
cout < < "Enter Values \n";
for(i=1;i < =n;i++)
{
item[i]=0;
cin > > v[i];
}
knapsack(n,w);
getch();
}
void knapsack(int n,int w)
{
for(int c=0;c < =W;c++)
C[0][c]=0;
for(i=0;i < =n;i++)
C[i][0]=0;
for(i=1;i < =n;i++)
{
for(w=1;w < =n+1;w++)
if(weight[i] < =w)
if(v[i]+C[i-1][w-weight[i]] > C[i-1][w])
{
C[i][w]=v[i]+C[i-1][w-weight[i]];
item[i]=1;
}
else
C[i][w]=C[i-1][w];
else
C[i][w]=C[i-1][w];
}
for(i=0;i < =n;i++)
{
cout < < "\n";
for(w=0;w < =W;w++)
cout < < C[i][w] < < "\t";
}
cout < < "\n";
}
SOURCE CODE
#include”iostream.h”
#include”conio.h”
#include <>
#define MAX 10
class subset
{
private:
int n,exsetsum,set[MAX],selected[MAX];
public:
void readset();
void setsum();
};
void subset::readset()
{
int i;
cout < < "Enter the Number Of Elements In The Set : "; cin > > n;
cout < < "\n Enter The Elements Of The Set \n"; for(i=1;i < =n;i++) cin > > set[i];
cout < < "\n Enter The Expected Sum Of Subset : "; cin > > exsetsum;
}
void subset::setsum()
{
int i,j,no,sum,k,s;
no=pow(2,n);
cout < < "\n All Possible Subsets Whose Sums Is Equal Is " < < i="1;i" s="i;" sum="0;" j="1;j" k="1;"> 0)
{
if(s%2)
{
sum+=set[k];
selected[k]=1;
}
s=s/2;
k++;
}
if(sum==exsetsum)
{
for(j=1;j < =n;j++) if(selected[j]) cout < <>