/* * testing to see how bad thsi algorithm is when is running on any given machine * This Big O test is at O(n 2^n) * when this value gets to around 30 to 40, it might take weeks to get an answer. * Compile: * Windose: javac Xbone.java & java Xbone * Linux : javac Xbone.java ; java Xbone */ import java.util.Scanner; import java.io.IOException; class Xbone { public Xbone() { } public static void main(String[] args) throws IOException { Scanner scan = new Scanner(System.in); Integer value; String mess; int power = 1; System.out.println("Enter in an integer number < 30 first then larger if possible. "); mess = scan.nextLine(); mess = mess.trim(); value = Integer.parseInt(mess); long startTime = System.currentTimeMillis(); for ( int j=1; j < value; j++ ) { power = power * 2; for ( int k=1; k < power; k++ ) { //System.out.println(k); } } System.out.println("Start Time: " + startTime); long endTime = System.currentTimeMillis(); long totalTime = endTime - startTime; System.out.println("Total Time for this Algorithm O(n2^n): " + totalTime + " Milliseconds" + "@ " + value + " ."); } }