n/2times. Using the simplification rules, we can extract the constant
1/2to simply get
stacksToLootis a user input, we're only concerned about finding the runtime for
stacksToLootcan be treated like a constant! Therefore, we now have
s = stacksToLootwhich simplifies into
nlayers. Each layer you go down, the number of calls multiplies by 4!
nlayers. Each layer you go down, the number of calls multiplies by
n!is not dependent on
iit can be factored out of the sum to produce this:
eis a constant, it simply reduces to
n = items.length).
whileloop will only run a small number of times, so the only loop left is the for loop.
whileloop to run on the order of
O(n)times, resulting in a nested loop.
explodeTNT(n)? What are their runtimes?