I'm trying to assign running times to loops of code to roughly get the upper asymptotic ($O$) running time.
while (j < n2) { # executes n2-1 times
int k = 0;
while ((k < n1) && (seq[k] < seq2[j])) { # executes (n2-1)*n1times
k = k + 1;
}
// we want to insert seq2[j] at seq[k]
// so we move seq[k] through seq[n1 - 1] to the right
for (int i = n1; i > k; i = i - 1) { # some n-k times
seq[i] = seq[i - 1];
}
seq[k] = seq2[j];
j = j + 1;
n1 = n1 + 1;
}
I know this is bad but would this algorithm worst running time be something in O(n^2) because there is one main loop and then two separate nested loops inside the main loop?
Thanks
I know this is badwhat do you know to bebad, and by what criterion? – greybeard Mar 03 '18 at 08:45