Challenge for Running Time and Big-O
Challenge
Here's some code which prints the multiplication table for a given array of numbers. Which is the dominant part of the running time?
static void printMultiTable(int[] ar){
for(int i=0; i<ar.length; i++){ // A
System.out.print("- "); // A
}
System.out.println(); // B
for(int i=0; i<ar.length; i++){
for(int j=0; j<ar.length; j++){ // C
System.out.print(ar[i] * ar[j] + " "); // C
}
System.out.println(); // D
}
}
Please sign in or sign up to submit answers.
Alternatively, you can try out Learneroo before signing up.