Space complexity of recursive algorithm

前端 未结 2 997
耶瑟儿~
耶瑟儿~ 2021-02-04 13:17

I was asked at an interview, the efficient way to solve a problem checking for pallindrome.

Now i can do two things:

  1. starting from i = 0 to i = n/2 and co
2条回答
  •  梦谈多话
    2021-02-04 13:58

    In theory they have the same space complexity; it largely depends on whether tail recursion can be optimized.

    If so, the stack gets replaced at every recursion so it doesn't incur a penalty.

提交回复
热议问题