Solution: Nested Loop with Multiplication (Pro)
Learn to compute the Big O of an algorithm that involves nested loops, where the loop variables increase with each multiplication and addition.
We'll cover the following...
We'll cover the following...
Solution #
Explanation
The outer loop in the main function has iterations because it iterates on the list generated from the for loop. If the condition j < var is true, the inner loop is entered. However, immediately, j is doubled. Note that j is not reset to 1 in the code. The inner while loop will run at most once for each iteration of the outer loop. Therefore, lines 6, 7 and 8 run ...