I'm confused whether the time complexities of these two codes are same or different.
code1
#include<iostream> using namespace std; bool check(int a[]) { if(a[0]==1 && a[1]==1 && a[2]==1 && a[3]==1 && a[4]==1 && a[5]==1 && a[6]==1) return true; return false; } int main() { int a[7] = {1,1,1,1,1,1,1}; if(check(a)) cout<<"yes"<<endl; else cout<<"no"<<endl; return 0; } code 2
#include<iostream> using namespace std; bool check(int a[]) { for(int i=0;i<7;i++) { if(a[i]!=1) return false; } return true; } int main() { int a[7] = {1,1,1,1,1,1,1}; if(check(a)) cout<<"yes"<<endl; else cout<<"no"<<endl; return 0; } when I checked it online at http://www.lizard.ws it showed that code 2 has less time complexity than code 1. If true why? please someone give me the reason.