public static Asymptotic f3_notation = Asymptotic.BIG_THETA;
public static Runtime f3_runtime = Runtime.LINEAR;
/* When f3 is first called, start will be 0 and end will be the length of the array - 1 */
public int f3(char[] array, int start, int end) {
if (array.length <= 1 || end <= start){
return 1;
}
int mid = start + ((end - start)/2);
return f3(array, start, mid) + f3(array, mid + 1, end);
}
public static Asymptotic f4_notation = Asymptotic.BIG_THETA;
public static Runtime f4_runtime = Runtime.LINEARITHMIC;
/* When f4 is first called, start will be 0 and end will be the length of the array - 1 */
public int f4(char[] array, int start, int end) {
if (array.length <= 1 || end <= start) return 1;
int counter = 0;
for (int i = start; i < end; i++) {
if (array[i] == 'a') counter++;
}
int mid = start + ((end - start)/2);
return counter + f4(array, start, mid) + f4(array, mid + 1, end);
}
So habe ich diese beiden Methoden. Was ich nicht verstehe ist, dass beide Rekursionen haben, aber warum ist der erste linear und die zweite Methode linear? Mir wurde gesagt, dass, wenn es Division oder Multiplikation gibt, normalerweise seine Laufzeit log-n ist. Obwohl die erste Methode die Division hat, wird sie immer noch als linear betrachtet, die zweite jedoch nicht.Verwirrt über diese asymptotische Notation und ihre Laufzeit
Je mehr ich verstehe, desto mehr verwirrt es mich und lässt mich fühlen, dass ich nichts weiß.