1.5.2 Time Complexity Example #2
Why Stack Overflow recommends it
Stack Overflow users link it when asking or answering how to derive Big O for loops, especially the nested-loop example that produces an O(log log n) result for the second loop.
Recommended by 0 people across 0 different months, 2020 to 2021.
What it is
A short algorithms lecture by Abdul Bari working through time complexity examples, including a pair of loops where the first loop doubles i up to n and the second loop runs over the resulting count. It is part of his data structures and algorithms series.
What people said
Cites David · 2020-04 · Stack Overflow · on “When and how should we add to time complexity when calculating the Big O Notation of a function”
Sorry for the first error, you were right with the O(n) by f(n) = 2n. Forgot about that. The video is here : [this video]
Cites ubaidsk · 2020-07 · Stack Overflow · on “What is the time complexity of this code? Is it O(logn) or O(loglogn)?”
You are correct , the time complexity of the complete code is O(log(n)). But, Abdul Bari Sir is also correct , Because:- In the video, Abdul Sir is trying to find the time complexity of the second for loop and not the time complexity of the whole code. Take a look at the video again and listen properly what he is saying at this time [this video] Once again, what he has derived is the time complexity of the second loop and not the time complexity of the complete code. Please listen to what he says at 9 mins and 28 secs in the video. If your confusion is clear, please mark this as correct.
Cites Ankit Jain · 2020-07 · Stack Overflow · on “What is the time complexity of this code? Is it O(logn) or O(loglogn)?”
int n = 8; // In the video n = 8 int p = 0; for (int i = 1; i < n; i *= 2) { // In the video i = 1 p++; } for (int j = 1; j < p; j *= 2) { // In the video j = 1 //code; } This is code from Abdul Bari Youtube channel ( link of the video [this video] ), they said time complexity of this is O(loglogn) but I think it is O(log), what is the correct answer?
Cites Satya Sridevi · 2021-08 · Stack Overflow · on “Problem in calculating time complexity for the given code”
@Olivier I thought the same but even if i = 0, it loops infinite, I think it is a printing mistake or I miss something. resources: code from the book - javascript data structures and algorithms [this video] and [LINK]