Earlier quoted context omitted.
Sorry, I should have been more specific: I understand the rules of Big O complexity, which you aptly summarized; the part I'm really curious about is " From there, you can pretty much combine these rules to analyze many algorithms. " It's not that the concepts are mysterious to me, but that making them a part of my learning habits has not come naturally.
> the part I'm really curious about is "From there, you can pretty much combine these rules to analyze many algorithms." I'm not sure if I'm still misunderstanding you, but here's an example of what I meant. Say, for whatever reason, you want to populate a binary tree with k items of random data: for(int i = 0; i The inside of the loop runs in O(log(n)) time because O(log(n)) > O(1). We're doing it k times, so the to…
This is not necessarily true for all cases. (It is for yours.) It's possible for interaction to exist between a loop and its contents, such that the total time is not m times the running time of the interior of the loop.
for (int i = 0; i
That's a trivial case but sufficient to prove the point. Bubble sort runs in O(n^2), and it looks like we're doing that n times, so the whole thing runs in O(n^3). But that's not true, since bubble sort runs in O(n) when the array is already sorted, so the whole thing is still O(n^2). In other words, the first iteration of the loop induces a side effect that affects all later iterations.