Skip to content
Related Articles

Related Articles

Algorithms Quiz | SP Contest 1 | Question 1
  • Last Updated : 11 Jul, 2018

How many times is the below loop executed?




for(int i=0; i < n; i++)
{
   for(int j=0; j < (2*i); j+=(i/2))
   {
   cout<<"Hello Geeks";
   }
}

(A) O(n)
(B) Infinite times
(C) O(n2)
(D) O(nlogn)


Answer: (B)

Explanation: At the second iteration of the outer loop, i.e. when i = 1, the inner loop will become an infinite loop as the increment condition is j = j+(i/2) and for i = 1, i/2 = 0.

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :