Both of these algorithms are giving same output but the first one takes nearly double time (>.67) compared to second one (.36). How is this possible? Can you tell me the time complexity of both algorithms? If they're the same, why is the time different?

Both of these algorithms are giving same output but the first one takes nearly double time (>.67) compared to second one (.36). How is this possible? Can you tell me the time complexity of both algorithms? If they're the same, why is the time different?

1st algorithm:

for (int i =0 ;i<n;i++){ cin>>p[i]; if(i>0){ if(p[i-1]>p[i]){ cout<<p[i]<<" "; } else{ cout<<"-1"<<" "; } } }

2nd algorithm:

for (int i =0 ;i<n;i++){ cin>>p[i];`} for (int i =0 ; i<n-1;i++){ if(p[i]>p[i+1]){ cout<<p[i]<<" "; } else{ cout<<"-1"<<" "; } }`

In this post, you'll see the difference between Rust and C/C++ in a developer’s perspective

ＬＩＫＥ | ＣＯＭＭＥＮＴ | ＳＨＡＲＥ | ＳＵＢＳＣＲＩＢＥ A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C# has a speci...