> 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 < k; ++i) {
int data = rand(); // Let's assume this is O(1)
tree.insert(data); // O(log(n))
}
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 total time is O(k
log(n))Now, if you wanted to do this for m trees:
for(int j = 0; j < m; ++j) {
for(int i = 0; i < k; ++i) {
int data = rand();
tree[j].insert(data);
}
}
We already know that the inner loop runs in O(klog(n)). Since we've just added a loop around that, it's easy to see that the whole thing runs in O(m
klog(n)) time.