Large (O) Designation: Can anyone check?

So, I answer the question of one of my computational classes. I developed an algorithm, and then asked me about the complexity of the algorithm. I'm not very good at complexity at the moment, so can anyone check?

The following code:

if( A.type is not Comparable ): return False // Max runs = 1 current ← A.head // Max runs = 1 printedFirst ← False // Max runs = 1 while( current.hasNext ): // Max runs = s-1 if ( current.value < current.next.value ): // Max runs = s-1 if ( printedFirst ): print ", " // Max runs = s-1 print "(" + current.value + ", " + current.next.value + ")" //runs = s-1 printedFirst ← True // Max runs = s-1 current = current.next // Max runs = s-1 

So we have

 3( 1 ) + 6(s - 1) = 3 + 6s - 6 = 6s - 3 = O( n ) 

Right?

+4
source share
1 answer

One while loop, with only one if inside ... for O (n).

Good luck with your studies.

+5
source

Source: https://habr.com/ru/post/1439918/


All Articles