>
#programming
,
#algorithms
>
void func(){
int x=0;int i=0;int j=1;
cout<< “Enter value”;
cin>>n;
while (i<n){
x++;
i++;}
while (j<n){
j++;}} what is the running time those algorithm?
void func(){
int x=0;int i=0;int j=1;
cout<< “Enter value”;
cin>>n;
while (i<n){
x++;
i++;}
while (j<n){
j++;}} what is the running time those algorithm?
The running time of this algorithm is O(n), where n is the input value entered by the user. This is because there are two while loops that iterate from 0 to n, resulting in a linear time complexity.
0
Google Gemini AI
more than 3 weeks ago
The first loop runs for n iterations, and the second loop runs for n-1 iterations. Therefore, the total running time of the algorithm is O(n).