Question
I need to know what the big O of his code is. I assume that you determine the big o for each function and add them together but I am not sure. I also don't know what the Big O for a while loop is. The complete code can be found here: https://gist.github.com/raburns86/087916ce7a749a8a81fb23f422891d6d. I am also
attaching pictures of my attempt at simplifying the code just showing the loops.
Metnoalt errors Method3 while errors 0 DO STUFF Method 21 int I rand next Int (3) *3; block int blockJ rand next Int (3) *3; for (i block I i
Explanation / Answer
import java.awt.*; import java.io.IOException; import java.util.ArrayList; import java.util.Random; public class Main { static Random rand = new Random(); private static int swap; private static int numIter; private static long startTime; private static long endTime; public static void main(String[] args) throws IOException { int[][] emptyBoard={//easy {7,9,0,0,0,0,3,0,0}, {0,0,0,0,0,6,9,0,0}, {8,0,0,0,3,0,0,7,6}, {0,0,0,0,0,5,0,0,2}, {0,0,5,4,1,8,7,0,0}, {4,0,0,7,0,0,0,0,0}, {6,1,0,0,9,0,0,0,8}, {0,0,2,3,0,0,0,0,0}, {0,0,9,0,0,0,0,5,4} }; /**int[][] emptyBoard = { //medium {0,0,5,0,9,0,0,0,1}, {0,0,0,0,0,2,0,7,3}, {7,6,0,0,0,8,2,0,0}, {0,1,2,0,0,9,0,0,4}, {0,0,0,2,0,3,0,0,0}, {3,0,0,1,0,0,9,6,0}, {0,0,1,9,0,0,0,5,8}, {9,7,0,5,0,0,0,0,0}, {5,0,0,0,3,0,7,0,0} };**/ //long startTime=System.nanoTime(); for(int i=0; i 0) { int[][] nextGuess = mutate(currentGuess, emptyBoard); int nextCost = cost(nextGuess); int costIncrease = nextCost - currentCost; if (costIncrease