+ 1
how can i find the time complexity of these two different algorithms to know which is better ??? š
6 Answers
+ 5
First: you have a single calculation, it does not depend on the size of the data, so it is constant time O(1)
Second: you loop through the array once, so the time depends on the size of the data with linear complexity O(n)
+ 1
Find which is the most repeated line of code
How much is it repeated ?
Ex
main (){
getline(input)
n = input.length
for ( i = 0; i < n; i++ )
}
Most repeated is the foor loop
Which repeats n times
+ 1
Tibor Santa helpful...
0
In your case the top one is only done once
There for its faster
0
I know this but what if there are several lines of code and i have to find time complexity of that code then how will i find .... is there any mathematical formula..?
0
imabhiiiiiiš„±
You could just run a few test and see how its time is growing as you increase the size of data