Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the time complexity of the given code?

While(n>=1)
{
    n=n/20;
    n=n/6;
    n=10×n;
    n=n-10000;
}

I tried like this =>

In this loop, N gets reduced by N/12 - 10000. so, time complexity is O(log N).

like image 723
Garrick Avatar asked Sep 05 '16 07:09

Garrick


People also ask

What is time complexity and example?

When we analyse an algorithm, we use a notation to represent its time complexity and that notation is Big O notation. For Example: time complexity for Linear search can be represented as O(n) and O(log n) for Binary search (where, n and log(n) are the number of operations).

What is the time complexity of this code snippet?

O(N^2)

What is O 1 time complexity example?

O(1) — Constant Time The execution time of these algorithm is independent of the size of the input. A good example of O(1) time is accessing a value with an array index. Other examples include: push() and pop() operations on an array.

How is time complexity measured?

How is time complexity measured? By counting the number of algorithms in an algorithm. By counting the number of primitive operations performed by the algorithm on a given input size. By counting the size of data input to the algorithm.


1 Answers

That seems to be correct. If this is an exercise, you should be prepared to argue why O(log_12(N))is O(log(N)).

like image 177
mort Avatar answered Oct 04 '22 10:10

mort