Daily Algorithm Practice: Cracking the Coding Interview, VI.12

 


Merge sort by itself is O(n log n) so O(b log b) in this case. How do I know? I looked it up. :P Specifically, there are log n levels of the tree, and for each level, the tree performs an O(n) operation. more info

That for loop is O(a * log(b)). Because it does the O(log(b)) binary search for every iteration, and it iterates O(a) times. 

So O(b log b) + O(a log b). Neither of these terms can be dropped. Combined, we have O(b log b + a log b). 

Comments

Popular posts from this blog

6 hours and only 6 Lagoon rides?

Reflecting on major life goals yet again

Hobble Creek Half: The slow passage of time marches us towards our inevitable death