Time Complexity in Reversing a C++ String -
i have problem on homework reverse words in c++ string, in place, o(1) additional memory. i'm confused means o(1) additional memory. understand o(1) means, no matter how big input is, time compute constant i'm guessing should add 1 piece of memory keep track of words in reverse. suggestions?
o(1) additional memory means "using @ constant additional memory." example, couldn't store copy of string, since take o(n) space, store constant number of int
s, char
s, etc.
more generally- statements "o(1)" or "o(n)" don't refer runtimes. big-o notation way of describing functions. algorithm can't o(n), runtime can o(n). algorithm's space usage can o(1), o(n), o(2n), etc.
hope helps!
Comments
Post a Comment