Category: Analysis of Algorithms

Analysis of algorithm and design programs such as searching, sorting ,knapsack

prim’s algorithm program in java

prim’s algorithm program in java

import java.io.*; class prim { public static void main(String args[])throws IOException { int size=20; int nodes,v1,v2,length,i,j,n; int g[][]=new int[size][size]; DataInputStream in=new DataInputStream(System.in); System.out.println(“Enter number of nodes in graph”); nodes=Integer.parseInt(in.readLine()); System.out.println(“Enter number of edges in...

optimal binary search tree program in java

optimal binary search tree program in java

import java.io.*; import java.util.*; class Optimal { public int p[]; // Probabilities with which we search for an element public int q[]; // Probabilities that an element is not found public int a[]; //...

Merge Sort in java

Merge Sort in java

import java.io.*; class MergeSort { public static void main(String args[ ]) { int i,n=0; int increments[]={5,3,1}; int x[]=new int[25]; DataInputStream in = new DataInputStream(System.in); try { System.out.print(“Enter how many numbers to be sorted :...

kruskal algorithm program in java

kruskal algorithm program in java

import java.io.*; class kruskal { public static void main(String args[])throws IOException { int size=20; int nodes,v1,v2,length,i,j,n; int g[][]=new int[size][size]; DataInputStream in=new DataInputStream(System.in); System.out.println(“Enter number of nodes in graph”); nodes=Integer.parseInt(in.readLine()); System.out.println(“Enter number of edges in...