Daily algorithm practice: More Big O!

Cracking the Coding Interview: VI.2

Oh look, recursion, lmao. 




One mistake I used to make was assuming that recursion automatically means a super complicated runtime. That's just not always going to be the case, and I understand this much better now. 

If I pick a few arbitrary values of b and trace through the execution...


...we see that the value of b decreases each time. If b is 5, the recursion will iterate with 4, 3, 2, and 1 before unwinding. So it just iterates b times. Thus, the Big O runtime of this power function is O(b). Not bad, eh? Not bad at all. 

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