dimanche 26 janvier 2020

Time complexity if else

        for(int i=0; i<=n;i++)
        {
          if(i%2==0)
           {
            for(int j=i;j<n-i;j++)
            {
             printf("");
            }
           }
           else{
           for( int j=n-i;j<n;j++)
           {
           printf(".");
           }
        }
      }

Since this is a if and else situation, is both the worse case O(N)? would the overall time complexity be O(N^2)?

Aucun commentaire:

Enregistrer un commentaire