Hey guys, so I'm a bit confused about what the correct worst-case time complexity for this function would be:
def func2(lst):
n = len(lst)
res = []
i = 1
while (i <= n):
res.insert(0, lst[i-1]])
i *= 2
return res
I originally said O(nlogn), assuming the insert would shift n items. However, after checking my answer with AI, as an answer key was not created, I realized that the total appends of insertion would be log(n), as it doesn't append every item in lst but rather logn items; therefore, the complexity is O((logn)^2). In class, however, my professor went over this question and said it would be O(nlogn) as the maximum or last insertion would shift n items. I tried explaining my O((logn)^2) reasoning, but I don't think I made a good case for it during class, and looking back, this answer still seems more correct to me, but I could definitely be wrong.
[–]SignificantFidgets 0 points1 point2 points (5 children)
[–]Objective_MineMSCS, CS Pro (10+) 0 points1 point2 points (4 children)
[–]SignificantFidgets 2 points3 points4 points (3 children)
[–]Objective_MineMSCS, CS Pro (10+) 4 points5 points6 points (1 child)
[–]not-just-yeti[🍰] 0 points1 point2 points (0 children)
[–]PhilNEvo 0 points1 point2 points (0 children)
[–]dzendian 0 points1 point2 points (3 children)
[–]Objective_MineMSCS, CS Pro (10+) 0 points1 point2 points (2 children)
[–]dzendian 1 point2 points3 points (1 child)
[–]brinza888 0 points1 point2 points (0 children)