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

Unleashing my inner Disney Princess ✩₊˚.⋆☾⋆⁺₊✧ at the 2024 Disney Princesses Half Marathon

The 20-something types of Computer Science majors

The Evenstar