Sunday, June 24, 2012

40. KNAPSACK PROBLEM USING BACKTRACKING APPROACH



//KNAPSACK PROBLEM USING BACKTRACKING APPROACH
#include <stdio.h>
#include <conio.h>
#define max 10
int w[max],i,j,p[max];
int n,m;
float unit[max];
int y[max],x[max],fp=-1,fw;
void get()
{
printf(“\n Enter total number of items: “);
scanf(“%d”,&n);

39. CONVERSION OF COLOR MODELS


//CONVERSION OF COLOR MODELS
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float r,g,b,y,i,c,m,h,s,v;
int ch;
clrscr();
do
{

38. 2D REFLECTION & SHEAR IN C


//2D REFLECTION & SHEAR
#include<stdio.h>
#include<process.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void disp(int n,float c[][3])
{
float maxx,maxy;
int i;
maxx=getmaxx();
maxy=getmaxy();
maxx=maxx/2;
maxy=maxy/2;
i=0;
while(i<n-1)
{

37. 2D TRANSFORMATIONS IN C


//2D TRANSFORMATIONS
#include<stdio.h>
#include<process.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void disp(int n,float c[][3])
{
float maxx,maxy;
int i;
maxx=getmaxx();
maxy=getmaxy();
maxx=maxx/2;
maxy=maxy/2;
i=0;

36. MIDPOINT ELLIPSE DRAWING ALGORITHM

//MIDPOINT ELLIPSE DRAWING ALGORITHM
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
long d1,d2;
int i,gd,gm,x,y;
long rx, ry, rxsq,rysq,tworxsq,tworysq,dx,dy;
/* Read the radius x and y
---------------------------- */
printf("Enter the x radius of the ellipse :");
scanf("%ld",&rx);
printf("Enter the y radius of the ellipse :");
scanf("%ld",&ry);

35. OPTIMAL BINARY SEARCH TREE


//OPTIMAL BINARY SEARCH TREE
import java.io.*;
import java.util.*;
class Optimal
{
 public int p[];       
 public int q[];       
 public int a[];     
 public int w[][];
 public int c[][]; 
 public int r[][]; 
 public int n;             
 int front,rear,queue[];
 public Optimal(int SIZE)
 {
  p=new int[SIZE];
  q= new int[SIZE];
  a=new int[SIZE];
  w=new int[SIZE][SIZE];
  c=new int[SIZE][SIZE];
  r=new int[SIZE][SIZE];
  queue=new int[SIZE];
  front=rear=-1;
}

34. GRAPH COLORING PROBLEM


//GRAPH COLORING PROBLEM
import java.io.*;
import java.util.*;
class Gr_Color
{
 public int G[][],n,m,edges;
 int color_tab[];
 public Gr_Color(int MAX)
 {
System.out.println("\n\n\t Graph Coloring ");
G=new int[MAX][MAX];
  color_tab=new int[MAX];
for(int i=0;i<MAX;i++)
{
for(int j=0;j<MAX;j++)
{
 G[i][j]=0;
 color_tab[i]=0;
}
                }
}

Saturday, June 23, 2012

33. STRASSEN'S MATRIX MULTIPLICATION


//STRASSEN'S MATRIX MULTIPLICATION
import java.io.*;
public class Strassen
{
public static BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
public Strassen() throws IOException
{
int n;
int[][] a, b, c;
System.out.print("Enter the number or rows or colums: ");
n = Integer.parseInt(br.readLine());
a = new int[n][n];
b = new int[n][n];
c = new int[n][n];

32. PRIM'S ALGORITHM FOR MST


//PRIM’S ALGORITHM
import java.util.*;
class Prim
{
public static Scanner br =new Scanner(System.in);
static int [][] G;
static int [][] t;
static int [] near;
static int n;
static int mincost = 0;
static int k, l;

31. KRUSKAL ALGORITHM FOR MST


//KRUSKAL ALGORITHM
import java.util.*;
class Kruskal
{
public static Scanner sc =new Scanner(System.in);
static int [][] G;
static int [][] t;
static boolean [][] in;
static boolean [][] temp;
static int n;
static int mincost = 0;
static int k, l, num_ed=0;