edited by
588 views
0 votes
0 votes

What is the time complexity of the following code snippet?
 

function(n)

{
           for i=1 to n

               {

                 if(n<=10000)

                    {
                       for j=1 to n

                        {

                            for k=1 to n

                              {

                                 val = val + 1;

                              }

                          }

                    }

          else

                     {

                       for j=1 to n

                         val = val + 1

                     }

          }

}


I am getting answer as O(n$^{2}$). But answer is given as O(1).

Explain briefly.

edited by

Please log in or register to answer this question.

Related questions

0 votes
0 votes
0 answers
2
0 votes
0 votes
1 answer
3
NeelParekh asked Jul 27, 2023
277 views
If an array is split in the form of increasing and decreasing order then what is TC to find minimum element in the array?
2 votes
2 votes
1 answer
4
h4kr asked Dec 30, 2022
466 views
What is the correct time complexity in $\theta()$ ?