N
N
Nazarevsky2021-05-06 18:19:56
Algorithms
Nazarevsky, 2021-05-06 18:19:56

Is the efficiency of this algorithm O(n*log(n))?

I am writing one code, I need to find out the time efficiency. I'm guessing O(n*log(n)), but I'm not sure.
Here is the code:

int end = 10;

void task1()
            {
                for (int i = 0; i < (int)(end/ 2); i++)
                {
                    // код 1
                }
            }

void mainTask()
            {
               task1();
               while(end != 0)
               {
                  task1();
                  end--;
               }
            }
mainTask();

As you understand, this is an example code of my program.
PS I forgot to add. end - the length of the array.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Wataru, 2021-05-06
@Nazarevsky

No, it's O(n^2). Where did you get the log from?

V
Vasily Bannikov, 2021-05-06
@vabka

It looks like O(1) if O(1) happens inside the loop, because there is no changeable parameter from which the
UPD time would change
if end is a variable, then it will be O(N^2)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question