top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How time complexity calculated for an algorithm ?

+2 votes
277 views
How time complexity calculated for an algorithm ?
posted Sep 6, 2013 by Vikram Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

Vikram I would suggest do your home work or use google, anyway Googled and found the following answer for you -

An algorithm that does not contain any loops (for example: Write Text to Console, Get Input From User, Write Result To Console, a hash function etc) is O(1), no matter how many steps. The "time" it takes to execute the algorithm is constant (this is what O(1) means), as it does not depend on any data.

An algorithm that iterates through a list of items one by one has complexity O(n) (n being the number of items in the list). If it iterates two times through the list in consecutive loops, it is still O(n), as the time to execute the algorithm still depends on the number of items only.

An algorithm with two nested loops, where the inner loop somehow depends on the outer loop, is in the O(n^x) class (depending on the number of nested loops).

An binary search algorithm on a sorted field is in the O(log(n)) class, as the number of items is reduced by half in every step.

answer Sep 6, 2013 by Majula Joshi
Similar Questions
+2 votes

Say we only know the worst case and best case complexity of an algo (Algo is not known). Is it possible to get the average case complexity?

+2 votes

Assume priority queue in Dijkstra’s algorithm is implemented using a sorted link list and graph G (V, E) is represented using adjacency matrix.

What is the time complexity of Dijkstra’s algorithm (Assume graph is connected)?

+6 votes

Looking for basic steps to analyse the algorithm.

+1 vote

While reading possible time complexity i found that time complexity O(log log n) exist for some algos,

Can any one explain an example which shows the calculation of the time complexity with O(log log n)

+3 votes

In an "N" element integer sorted array, a particular elements is repeating "(N/2)+1" times. How much time it take to find the repeating element.

...