Ask a Question

Is the time complexity on Algorithm Analysis the same for Algo-1 int a,b,c; scanf("%d",&a); scanf("%d",&b); c=a+b; printf("%d",c); Algo-2 int a[0],b[0],c; scanf("%d",&a[0]); scanf("%d",&b[0]); c=a[0]+b[0]; printf("%d",c); I mean to say that do arrays take more time than normal variables.


Soumyodeep

on 2012-01-17 10:30:00  

no dude they are same.... in this case... but it will change when there is other algos....

sourav

on 2012-01-18 10:30:00  

ur Algo-2 is totaly wrong because 1>any array should have atleast size 1..so ,a[0] is not valid....a[1] is valid... 2>why we should use a,b two different arrays.. just one array is sufficient.. like--int arr[3].. and finally REMEMBER IT THAT TIME COMPLEXITY IS NOT CONCERN ABOUT STORAGE...it is depends upon key operations like-searching...

Deepanwita

on 2012-01-18 10:30:00  

Thanks Sourav, for pointing the mistake; it was a typing error. it should be int a[1], b[1], c; I am not concerned of space complexity or storage