What is the complexity of this code whose nested for loop repeatedly doubles its counter?

前端 未结 3 380
半阙折子戏
半阙折子戏 2021-01-02 10:49

In the book Programming Interviews Exposed it says that the complexity of the program below is O(N), but I don\'t understand how this is possible. Can someone expla

3条回答
  •  难免孤独
    2021-01-02 11:17

    @Daniel Fischer's answer is correct.

    I would like to add the fact that this algorithm's exact running time is as follows:

    enter image description here

    Which means:

    enter image description here

提交回复
热议问题