Show the derivation of the asymptotic run time, O(n), for each of the following methods. You may use the text highlighting technique shown in class, or list the individual Java statements along with the number of times each is executed as a function of the input size, n. public static void octaves(int n){ System.out.println("Center frequency: " + n); System.out.println("---=== Lower Octaves (Hz) ===---"); int frequency = n / 2; // One octave below while (frequency > 20){ System.out.println(frequency); frequency = frequency / 2; // half the frequency } System.out.println("---=== Higher Octaves (Hz) ===---"); frequency = n * 2; // One octave above while (frequency < 20000){ System.out.println(frequency); frequency = frequency * 2; // double the frequency } }
Show the derivation of the asymptotic run time, O(n), for each of the following methods. You may use the text highlighting technique shown in class, or list the individual Java statements along with the number of times each is executed as a function of the input size, n.
public static void octaves(int n){
System.out.println("Center frequency: " + n);
System.out.println("---=== Lower Octaves (Hz) ===---");
int frequency = n / 2; // One octave below
while (frequency > 20){
System.out.println(frequency);
frequency = frequency / 2; // half the frequency
}
System.out.println("---=== Higher Octaves (Hz) ===---");
frequency = n * 2; // One octave above
while (frequency < 20000){
System.out.println(frequency);
frequency = frequency * 2; // double the frequency
}
}
Step by step
Solved in 2 steps