Question
Find the time complexity for the given question
voidfunc() {
int x = 0 i = 0 j=1;
cout<< "Enter an Integer value";
cin>>n;
while (i<n] {
x //
i++;
}
while (j<n){
}
}
voidfunc() {
int x = 0 i = 0 j=1;
cout<< "Enter an Integer value";
cin>>n;
while (i<n] {
x //
i++;
}
while (j<n){
}
}
Answers
GPT 3.5
The time complexity of this code is O(n), where n is the input integer value. This is because there are two while loops that iterate up to n. The first while loop increments the variable i from 0 to n, and the second while loop increments the variable j from 1 to n. Therefore, the overall time complexity is O(n).