2021年4月4日星期日

Time complexity with for loop nested in while loop

What is the time complexity of this algorithm?

while len(array) > 0:     for item in array:        do stuff to determine which item to pop     array.pop(item_to_pop)  

My first instinct is O(N^2). However, if I were to reduce the array size by half each time the while condition executed it would be O(n). I'm guessing reducing my array size by 1 each iteration does not have the same effect?

https://stackoverflow.com/questions/66947198/time-complexity-with-for-loop-nested-in-while-loop April 05, 2021 at 09:07AM

没有评论:

发表评论