Java program to implement Travelling Sales Person problem using Dynamic programming

import java.util.Scanner; class TSPExp { int weight[][],n,tour[],finalCost; final int INF=1000; TSPExp() { Scanner s=new Scanner(System.in); System.out.println("Enter no. of nodes:=>"); n=s.nextInt(); weight=new int[n][n]; tour=new int[n-1]; for(int i=0;i { for(int j=0;j {…

Continue ReadingJava program to implement Travelling Sales Person problem using Dynamic programming

java program to Find Minimum Cost Spanning Tree of a given undirected graph using Kruskal’s algorithm

import java.util.Scanner; public class kruskal { int parent[]=new int[10]; int find(int m) { int p=m; while(parent[p]!=0) p=parent[p]; return p; } void union(int i,int j) { if(i parent[i]=j; else parent[j]=i; }…

Continue Readingjava program to Find Minimum Cost Spanning Tree of a given undirected graph using Kruskal’s algorithm

Java the program find shortest paths to other vertices using Dijkstra’s algorithm for weighted connected graph

import java.util.Scanner; public class Dijkstra { /** * @param args */ int d[]=new int[10]; int p[]=new int[10]; int visited[]=new int[10]; public void dijk(int[][]a, int s, int n) { int u=-1,v,i,j,min;…

Continue ReadingJava the program find shortest paths to other vertices using Dijkstra’s algorithm for weighted connected graph

Java program to Sort a given set of n integer elements using Merge Sort method and compute its time complexity

import java.util.Random; import java.util.Scanner; public class mergesort { static int max=10000; void merge( int[] array,int low, int mid,int high) { int i=low; int j=mid+1; int k=low; int[]resarray; resarray=new int[max]; while(i

Continue ReadingJava program to Sort a given set of n integer elements using Merge Sort method and compute its time complexity

Java program to Sort a given set of n integer elements using Quick Sort method and compute its time complexity

import java.util.Random; import java.util.Scanner; public class quicksort { static int max=2000; int partition (int[] a, int low,int high) { int p,i,j,temp; p=a[low]; i=low+1; j=high; while(low { while(a[i]p) j--; if(i {…

Continue ReadingJava program to Sort a given set of n integer elements using Quick Sort method and compute its time complexity

Java program that implements a multi-thread application that hash tree threads. First thread generates a random integer for every 1 second; second thread computes the square of the number and prints; third thread will print the value of cube of the number.

import java.util.*; class second implements Runnable { public int x; public second (int x) { this.x=x; } public void run() { System.out.println("Second thread:Square of the number is"+x*x); } } class…

Continue ReadingJava program that implements a multi-thread application that hash tree threads. First thread generates a random integer for every 1 second; second thread computes the square of the number and prints; third thread will print the value of cube of the number.