Time Complexity in Data Structure

Neha Shaikh
2 min readNov 15, 2019

Its lab no:3 where we had gone through a new concept —“Time Complexity”.

What is Time Complexity?

In Programming, time complexity deals with the magnitude of time taken by a code to complete its compilation for producing the desired or required output. Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm, supposing that each elementary operation takes a fixed amount of time to perform.

Representation:

Time Complexity in Data Structure Algorithm is usually expressed by the big “O” notation.It is the relative representation of Algorithm’s complexity.

For Example,

We need to calculate the square of n that can be calculate in the following two ways.


for i=1 to n
do n = n + n
return n

Or, we can simply use a mathematical operator * to find the square.
return n*n

In the above two simple algorithms, you saw how a single problem can have many solutions. While the first solution required a loop which will execute for n number of times, the second solution used a mathematical operator * to return the result in one line. So which one is the better approach, of course the second one.

So we came to know the more the less line of code the more efficient our program will be and it would require less time to complete its execution so far.

Then there came the concept of linear and Binary search Time Complexities,

Linear Search Time Complexity:

Time Complexity of Linear Search is O(n), A linear search scans one item at a time, without jumping to any item .

Binary Search Time Complexity:

Time Complexity of Binary Search is O(log n),A binary search however divide your search to half as soon u find the middle of sorted list.

Now you can came to know the concept of above mentioned time complexities. Hope it might help……

Your feedback is well appreciated.

--

--