algorithm - Space Complexity and Modifying the Data Set -


what space complexity of following algorithm?

given array of n 32-bit signed integers, each value positive , less 2 power of 30, negate values in array, negate values in array second time.

the question arose me out of discussion in comment section here: rearrange array arr[i] becomes arr[arr[i]] o(1) space

i interested in different opinions , definitions. think subtle distinctions , definitions may missing in stackoverflow discussions on subject.

space complexity refers added space requirements algorithm, on , above original data set itself. in case, original data set n 32-bit signed integers, you're concerned storage above that.

in case, storage is nothing, translates constant o(1) space complexity.

if required create separate array (negated, negated again), o(n) since space required in proportion original data set.

but, since you're doing negations in-place, that's not case.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -