0

I am new to Data Structures and Algorithms.

for (int i=0; i<p; i++) {

   // Statement
}

This loop have 3 steps. Initializing, comparing and incrementing. Will this be 3n?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
bCM
  • 97
  • 1
  • 3
  • 12

1 Answers1

0

Initialization is performed only once at the start of loop. Comparison and increment is performed in each iteration. In this case there will be p iterations so complexity will be constant ie p or in other words O(n)

Vikas
  • 9
  • 3