Sunday, 15 July 2012

algorithm - What does it mean when it is stipulated that extra allowed space is O(1)? -



algorithm - What does it mean when it is stipulated that extra allowed space is O(1)? -

if above status in programming question given , solving using recursion violating constraints? because recursion uses stack? right?

if depth of stack (recursion) constant , not alter respect size of input, recursive solution can o(1) space.

some compilers may tail phone call optimization (tco) , remove recursive calls if lastly statement executed in given code path through function. tco, there no call-stack related memory overhead.

however, maintain in mind o(1) constraint may beingness imposed forcefulness take particular (probably non-recursive) algorithm, relying on tail phone call optimisation may unwise if know compiler using has made relevant transformation code. @ least, if rely on it, should explicitly , justify expectation tco occur reference language specifications, compiler documentation and/or disassembly appropriate.

algorithm recursion complexity-theory asymptotic-complexity

No comments:

Post a Comment