Discussion Forum on time complexity, self referential structure (Week 2)

Answer the question and discuss if you have any confusion

Answer the question and discuss if you have any confusion

by Md Assaduzzaman -
Number of replies: 59

1. Why we need to know Time complexity?

2. Find out the time complexity of the following code and explain?

 #include <stdio.h>

int main() {

    int counter, N;

 printf("Enter a Positive Number\n");

    scanf("%d", &N);

    (counter = 1; counter <= N; counter++) {

        printf("%d \n", counter);}

     int a=12,n=12;

    if(N>10){

        for(i=0;i<a;i++){

             for(i=0;i<a;i++){

             a++;  }  }

      for(i=0;i<a;i*=2){

         printf("hello")

        }

    }


    return 0;

}


In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Janatul Naeem (201-15-3605) -

Ans To The Q No 1 :-


The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. ... The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.

Ans To The Q No 2 :-


At first I wanted to say that this code has some bug.

These are :-----

In line 3:-  we have to declare i
In line 6:-  before counter we have to also put for
In line 14:-  we have to put ; in last printf (“hello”) ;

In first for loop we can say it’s = 0 (n+1)
Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .

Final result is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ]

The time complexity is n³.


In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Avishek Das (201-15-3452) -

Answer to the Q. No 1

Time complexity :

In computer science, time complexity is the complexity of computation that describes the time it takes to run an algorithm. Time complexity is usually estimated by calculating the initial activities performed by the algorithm, assuming that each initial activity takes a certain amount of time to perform. Thus, the initial activity performed by time and algorithm is separated by the most constant factor.

Since the running time of the algorithm can vary between different inputs of the same size, the worst time complexity is generally considered to be the maximum amount required for inputs of a given size. Less common, and usually explicitly specified, is the mean-case complexity, which is the average of the time taken for inputs of a given size (this is understood because there are only a limited number of possible inputs of a given size). In both cases time complexity is usually expressed as a function of input size. Since this function is usually difficult to calculate accurately and running time for small inputs is not usually the result, one usually focuses on the behavior of the complex when the input size increases - i.e. the asymptomatic behavior of the complex.


Answer to the Q. No 2


#include <stdio.h>

int main() {

int counter, N;
printf("Enter a Positive Number\n");
scanf("%d", &N);

for(counter = 1; counter <= N; counter++) {

        printf("%d \n", counter);}

     int a=12,n=12;

    if(N>10){

        for(int i=0;i<n;i++){

             for(i=0;i<a;i++){

             a++;  }  }

      for(int i=0;i<a;i*=2){

         printf("hello");

   }

         }

        return 0;

     }

Ans:

At first I wanted to say that this code has some bug.

These are ….

  • ·        In line 3:-  we have to declare i .
  • ·        In line 6:-  before counter we have to also put for .
  • ·        In line 14:-  we have to put ; in last printf (“hello”) ;

 

In first for loop we can say it’s = 0 (n+1)

Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n= 0 (n2) .

Final result is = 0(n+1) + 0(n2) = 0 (n2) [ lower power finish ]

The time complexity is n2.




In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Nabid Anjum Ome 201-15-3308 -
Ans To The Q No 1 :-


The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. ... The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.

Ans To The Q No 2 :-


At first I wanted to say that this code has some bug.

These are :-----

In line 3:- we have to declare i .
· In line 6:- before counter we have to also put for .
· In line 14:- we have to put ; in last printf (“hello”) ;


In first for loop we can say it’s = 0 (n+1)

Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n= 0 (n2) .

Final result is = 0(n+1) + 0(n2) = 0 (n2) [ lower power finish ]

The time complexity n2
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Ismotara Dipty -

Answer to the question no 1  


Time complexity is the computational complexity that describes the amount of time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm.It can be applied to almost any algorithm or function but is more useful for recursive functions.



Answer to the question no 2


In line number 3- we need to announce i.

In line number 6:- preceding counter we need to likewise put for.  

In line number  14:- we need to put ; in last printf ("hello"); 

In first for circle we can say it's = 0 (n+1). At that point in second step we see that here is 3 settled for circle so this answer is = n*n*n=  0 (n³) .Conclusive outcome is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ]. 

The time complexity  is n³.

In reply to Ismotara Dipty

Re: Answer the question and discuss if you have any confusion

by 201-15-3255 Al Imran Alvy -
1. Use of time complexity makes it easy to estimate the running time of a program. Performing
an accurate calculation of a program’s operation time is a very labour-intensive process

2.
line 3:- declare i .
line 6:- before counter we have to also put ;     (counter = 1 ,counter <= N, counter++);
line 14:- we have to put ;


In first for loop we can say it’s = 0 (n+1)
Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .

Final result is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ]

The time complexity is n³.

In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Zannatul Mawya Priya 201-15-3209 -
Answer to the question no 1



Time complexity is the computational complexity that describes the amount of time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm.It can be applied to almost any algorithm or function but is more useful for recursive functions.





Answer to the question no 2



In line number 3- we need to announce i.

In line number 6:- preceding counter we need to likewise put for.

In line number 14:- we need to put ; in last printf ("hello");

In first for circle we can say it's = 0 (n+1). At that point in second step we see that here is 3 settled for circle so this answer is = n*n*n= 0 (n³) .Conclusive outcome is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ].

The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Alfi Sharin Rizvi -

ans to the ques no: 1

Time Complexity: It's a term that deals with the total execution time of an algorithm. The best time complexity ever is "Linear Time, Constant Space", which is the most efficient one ie. O(n). But not all the algorithms has a linear time complexity. That's why "the lesser the complexity is the better the algorithm".

ans to the ques no: 2

The code has got various loops to deal with. The first loop even though that's a bug as the 'for' is missing there counts a complexity of O(n+1). Cause it follows by a condition and a single loop.

In second phase there are 3 more loops. Where two of those are linked that gives us the complexity of O(n^2). And the last most loop is again a non nested one. SO, it counts  O(n) again.

As O(n^2) is greatest among all so the actual complexity is itself.

*But there is a catch. The highest complexity is always feasible in worst case. As the code's second phase deals with a condition where it executes only if it satisfies the condition so the complexity on it's best case can be as minimum as O(n+1). But in terms of total count we still can say it O(n^2). 

In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by ABU BAKAR SIDDIQUE 201-15-3352 -
1)Ans:
The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.

2)Ans:

In line number 3- we need to announce i.

In line number 6:- preceding counter we need to likewise put for.

In line number 14:- we need to put ; in last printf ("hello");

In first for circle we can say it's = 0 (n+1). At that point in second step we see that here is 3 settled for circle so this answer is = n*n*n= 0 (n³) .Conclusive outcome is = 0(n+1) + 0(n3) = 0 (n³).

The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Sanjida Zaman Toma 201-15-3102 -
Ans To The Question No 1 :-


Time complexity of an algorithm signifies the total time required by the program to run till its completion.

Ans To The Questions No 2 :-


There are some bugs in this code.

These are :

In line 3: we have to declare i
In line 6: before counter we have to also put for
In line 14: we have to put ; in last printf (“hello”) ;

In first for loop we can say it’s = 0 (n+1)
Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .

Final result is = 0(n+1) + 0(n3) = 0 (n³)

The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Mafujul Haque Plabon -
Answer to the question no(1)


The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. In simple words, every piece of code we write, takes time to execute. The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.aratē pāraba.
We can find out the minimum or maximum time taken by any algorithm through time complexity. As a result, I can use the program efficiently.

Answer to the question no(2)

Line 3: We have to declare i.
Line No 6 : - We need to keep the same in the previous counter.
In line 14: - We have to put; Latest printef ("hello");
For the circle first we can say it = 0 (n + 1). At that moment in the second step we can see that 3 circles are settled here so this answer is = n * n * n = 0 (n³) C Final result = 0 (n + 1) + 0 (n3) = 0 (NO) ) [Lower power finish] [. Higher power acceptable]

So the complexity during the program is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Sk Dhrubo (201-15-3169) -
Ans To The Q No 1 :

The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. ... The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.

Ans To The Q No 2 :
#include
int main() {

int counter, N;
printf("Enter a Positive Number\n");
scanf("%d", &N);
for(counter = 1; counter <= N; counter++) {

printf("%d \n", counter);}

int a=12,n=12;

if(N>10){

for(int i=0;i
for(i=0;i
a++; } }

for(int i=0;i
printf("hello");

}

}

return 0;

}
Right Answer :

This code contains bug.
These are some problems that I found
In line 3:- we have to declare i
In line 6:- before counter we have to also put for
In line 14:- we have to put ; in last printf (“hello”) ;

In first for loop we can say it’s = 0 (n+1)
Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .

Final result is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ]

The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Mohammad Ashikuzzaman 3438 -
Answer to the Question No:-1


The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.



Answer to the Question No:-2



At first I wanted to say that this code has some bug.

These are:-

In line 3:- we have to declare i .
In line 6:- before counter we have to also put for .
In line 14:- we have to put ; in last printf (“hello”) ;


In first for loop we can say it’s = 0 (n+1)

Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n= 0 (n2) .

Final result is = 0(n+1) + 0(n2) = 0 (n2) [ lower power finish ]

The time complexity is n2.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Md.Yeasin Chowdhury 201-15-3443 -

Answer :01



Time complexity is simply a measure of the time it takes for a function or expression to complete its task, as well as the name of the process to measure that time.

Answer :02



First of all I want to say there are some errors in this code.

These are
line 3:- we have to declare i .
line 6:- before counter we have to also put for .
line 14:- we have to put ; in last printf (“hello”) ;

In first for loop we can say it’s = 0 (n2)
Then in 2nd step we see that here is is = 0 (n) .
Final result is = 0(n) + 0(n2) = 0 (n2) [ lower power finish ]
The time complexity is n2.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Akteruzzaman 201-15-3139 -
#1
Time complexity is simply a measure of the time it takes for a function or expression to complete its task, as well as the name of the process to measure that time. It can be applied to almost any algorithm or function but is more useful for recursive functions.



#2

line 3-we have to declare i
line 6- before counter we have to add for
line 14- ; in the printf function printf (“hello”) ; would be used.
In first for loop it is = 0 (n+1)
After that in second term it is clear that here is three nested for loops,thats why the answer might be is = n*n*n = 0 (n³)

Finally result is = 0(n+1) + 0(n3) = 0 (n³)

The time complexity is n³
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Dipta bhowmik15-3425 -
Ans no 1:
In computer engineering, the time multifaceted nature is the computational intricacy that depicts the measure of time it takes to run a calculation. Time unpredictability is ordinarily assessed by checking the quantity of rudimentary tasks performed by the calculation, assuming that each rudimentary activity sets aside a fixed measure of effort to perform. Accordingly, the measure of time taken and the quantity of rudimentary tasks performed by the calculation are taken to contrast by all things considered a consistent factor.


Ans no -2
In line number 3- we need to call i
In line number 6:- before counter we need to put for
In line number 14:- we have to put ; in last printf ("hi");

In first for circle we can say it's = 0 (n+1)
At that point in second step we see that here is 3 settled for circle so this answer is = n*n*n = 0 (n³) .
outcome is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ].
The time unpredictability is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Sumia Sarower Trisha 201-15-3474 -

Answer to the question no 1  


Time complexity is the computational complexity that describes the amount of time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm.It can be applied to almost any algorithm or function but is more useful for recursive functions.



Answer to the question no 2


In line number 3- we need to announce i.

In line number 6:- preceding counter we need to likewise put for.  

In line number  14:- we need to put ; in last printf ("hello"); 

In first for circle we can say it's = 0 (n+1). At that point in second step we see that here is 3 settled for circle so this answer is = n*n*n=  0 (n³) .Conclusive outcome is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ]. 

The time complexity  is n³.

In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Khatuna Jannat Sarnali -
Answer no (1)

Time complexity is the total quantity of time needed by a code for its execution. By knowing time complexity, we can find out the more preferable code which is more time saver.

Answer no (2)

There are some errors in the code. They are-
1) The word "for" is missing in the 1st loop which is initialized by the "counter" variable.
2) Data type of "i" is not declared.
3) Semicolon(;) is missing in the last line "printf("hello")".

Time Complexity:
For the 1st loop time complexity = O(n)
Then, for the nested loop time complexity = O{(n^2)+1} =O(n^2)
And the for the last loop time complexity = log(n)
So, Time complexity of this code = O(n) + O(n^2) + log(n)
=O(n^2) (Answer)
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Prayma Bishshash 201-15-3168 -
Ans To The Question No 1 :
Time complexity is the computational complexity that describes the amount of time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm.

Ans To The Question No 2:
#include
int main() {

int counter, N;
printf("Enter a Positive Number\n");
scanf("%d", &N);
for(counter = 1; counter <= N; counter++) {

printf("%d \n", counter);}

int a=12,n=12;

if(N>10){

for(int i=0;i
for(i=0;i
a++; } }

for(int i=0;i
printf("hello");

}

}

return 0;

}

There are some bugs in this code.
In line 3: we have to declare i
In line 6: before counter we have to also put for
In line 14: we have to put ; in last printf (“hello”) ;
In first for loop we can say it’s = 0 (n+1)
Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .

Final result is = 0(n+1) + 0(n3) = 0 (n³)

The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Abdullah Al Noman 201-15-3646 -
Q1.
The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.


Q2.
There are some bugs in the given code. That should be fixed.
The problems are:
In line 3:- we have to declare i
In line 6:- before counter we have to also put for
In line 14:- we have to put ; in last printf (“hello”) ;
In first for loop we can say it’s = 0 (n+1)
Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .

Final result is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ]
The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Jannatul Ferdous Moon -
Ans to the question no : 1

Time complexity in computer science is the complexity of computation that describes the time it takes to run an algorithm. Time complexity is usually estimated by calculating the initial activities performed by the algorithm, assuming that each initial activity takes a certain amount of time to perform. Thus, the initial activity performed by time and algorithms is separated by the most constant factor.



Ans to the question no : 2

This code contains bug. These are some problems that I found -
In line 3:- we have to declare i
In line 6:- before counter we have to also put for
In line 14:- we have to put ; in last printf (“hello”) ;

In first for loop we can say it’s = 0 (n+1)
Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .

Final result is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ]

The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Md. Sakibuzzaman Alif -
Answer to the question no 1



Time complexity is the computational complexity that describes the amount of time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm.It can be applied to almost any algorithm or function but is more useful for recursive functions.





Answer to the question no 2



In line number 3- we need to announce i.

In line number 6:- preceding counter we need to likewise put for.

In line number 14:- we need to put ; in last printf ("hello");

In first for circle we can say it's = 0 (n+1). At that point in second step we see that here is 3 settled for circle so this answer is = n*n*n= 0 (n³) .Conclusive outcome is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ].

The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Tania Ahmed Nipa (201-15-3282) -
1. The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.

2.
In line number 3- we need to announce i.
In line number 6:- preceding counter we need to likewise put for.
In line number 14:- we need to put ; in last printf ("hello");
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Nabid Anjum Ome 201-15-3308 -

Ans To The Q No 1 :-



The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. ... The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.


Ans To The Q No 2 :-



At first I wanted to say that this code has some bug.


These are :-----



Ans To The Q No 1 :-



The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. ... The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.


Ans To The Q No 2 :-

At first I wanted to say that this code has some bug.

These are :-----


In line 3:-  we have to declare i .

·        In line 6:-  before counter we have to also put for .

·        In line 14:-  we have to put ; in last printf (“hello”) ;

 


In first for loop we can say it’s = 0 (n+1)


Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n= 0 (n2) .


Final result is = 0(n+1) + 0(n2) = 0 (n2) [ lower power finish ]


The time complexity n2


In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Taslima Jahan Tushi 201-15-3269 -

Ans to the ques No 1 :-

The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. ... The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.


Ans to the Q No 2:-


At first I wanted to say that this code has some bug.

These are :-

In line 3:-  we have to declare i

In line 6:-  before counter we have to also put for

In line 14:-  we have to put ; in last printf (“hello”) ;

In first for loop we can say it’s = 0 (n+1)

Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) . 

Final result is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ]

The time complexity n2

In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Arifa Rahman Tony -
Ans To the Q,no:1

Time Complexity: It's a term that deals with the total execution time of an algorithm. The best time complexity ever is "Linear Time, Constant Space", which is the most efficient one ie. O(n). But not all the algorithms has a linear time complexity. That's why "the lesser the complexity is the better the algorithm".

And To the ques no:2
line number 3- we need to announce i.

In line number 6:- preceding counter we need to likewise put for.

In line number 14:- we need to put ; in last printf ("hello");

In first for circle we can say it's = 0 (n+1). At that point in second step we see that here is 3 settled for circle so this answer is = n*n*n= 0 (n³) .Conclusive outcome is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ].

The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by 201-15-3293 Abdur Razzak -
Answer to the Question No 1:
The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. ... The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.
Answer to the Question No 2:
At first for simple expression the time complexity is 0(1).
Then for two for loops the time comolexity is 0(n*n) = 0(n^2).
And then for other for loop the time complexity is 0(n).
At last for return the time complexity is 0(1).
So the time complexity of the code is 0(n^2).
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Ordha Nafiz Akbar -
Answer to the question no : 1
time complexity of an algorithm is the total amount of time required by an algorithm to complete its excecution.

Answer to the question no : 2
the bugs are
in 3rd line we do not declare "i "so we need to declare i.
in 6th line we need to put for loop before (....).
in 14th line we need to write ( ; )


In first for loop we can say it’s = 0 (n+1)

Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n= 0 (n2) .

Final result is = 0(n+1) + 0(n2) = 0 (n2) [ lower power finish ]

The time complexity is n2
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Arif Hosen -
Answer to the Question No. 01
The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. A lot of times, there is more than one way to solve a particular problem and we should be able to identify the most efficient solution out of all. This is where time complexity comes into the picture. Time complexity helps us compare the performance of different solutions, thus helping us determine the most efficient solution. This is why we need to know time complexity.

Answer to the Question No. 02
This code contains bug.
These are,
In line 3: we have to declare i
In line 6: before counter we have to also put for
In line 14: we have to put ; in last printf (“hello”) ;

In first for loop we can say it’s = 0 (n+1)
Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .

Final result is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ]

The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Md. Farhatul Haider -
1.Importance time complexity :-

The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. In simple words, every piece of code we write, takes time to execute. The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.



2. Find out the time complexity and errors from the code :-

#include
int main() {

int counter, N,i;

printf("Enter a Positive Number\n");

scanf("%d",&N);

for (counter = 1; counter <= N; counter++)

{

printf("%d \n", counter);

}

int a=12,n=12;

if(N>10)

{

for(i=0; i
{

for(i=0; i
{

a++;

}

}

for(i=0;i
{

printf("hello");

}

}

return 0;

}



From this code we find out 3 errors.

(a). Declare the variable i;

(b). We added for before (counter = 1; counter <= N; counter++)

(c). We added semicolon (;) after printf("hello");

Those are the errors of the code.



Time complexity for the code :-

According to the codeblocks, We see,

Line 7 : a loop of size N.

Line 13 to 20 : Size of loop n^3 and one operations.

So, We get, N + n^3

Again, when we have an asymptotic analysis, we drop all constants and leave the most important term: n^3. So, in big O notation, it would be O(n^3).
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Tanmoy Komer (201-15-3439) -
Ans To The Q No 1 :-


The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. ... The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.

Ans To The Q No 2 :-


At first I wanted to say that this code has some bug.

These are :-----

In line 3:- we have to declare i .
In line 6:- before counter we have to also put for .
In line 14:- we have to put ; in last printf (“hello”) ;


In first for loop we can say it’s = 0 (n+1)

Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n= 0 (n2) .

Final result is = 0(n+1) + 0(n2) = 0 (n2) [ lower power finish ]

The time complexity n2
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by MD.SADIK RAHMAN -
1. The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.
2. n3
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by 201-15-3417 Arpita Basak -
Ans To The Question No 1 :-


Time complexity of an algorithm signifies the total time required by the program to run till its completion.

Ans To The Questions No 2 :-


There are some bugs in this code.

These are :

In line 3: we have to declare i
In line 6: before counter we have to also put for
In line 14: we have to put ; in last printf (“hello”) ;

In first for loop we can say it’s = 0 (n+1)
Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .

Final result is = 0(n+1) + 0(n3) = 0 (n³)

The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Arpita Ghosh 201-15-3422 -
Ans: to the Ques: No.1

Time complexity is usually estimated by calculating the initial activities performed by the algorithm, assuming that each initial activity takes a certain amount of time to perform. Thus, the initial activity performed by time and algorithm is separated by the most constant factor that's why we need to know about time complexity.


Ans: to the Questions No. 2

There are some bugs in this code which I explain below :

In line 3: we have to declare i
In line 6: before counter we have to also put for
In line 14: we have to put ; in last printf (“hello”) ;

In first for loop we can say it’s = 0 (n+1)
Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .

Final result is = 0(n+1) + 0(n3) = 0 (n³)

The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Mohammad Nadiatul Islam Sakib -
Answer to the question No-01

The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. ... The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.

Answer to the question No-02

At first we have to fix some problems of this code.
• We have to declare i in the 3rd line
• We have to use a for loop before the counter
• We will have to put a ; in line 14
In the first loop, it will be = O(n+1)
In the second loop, it will be = O(n3)
Final result is = O(n+1)+ O(n3)= O(n3)
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Tanmoy Komer (201-15-3439) -
Ans To The Question No 1 :-


Time complexity of an algorithm signifies the total time required by the program to run till its completion.

Ans To The Questions No 2 :-


There are some bugs in this code.

These are :

In line 3: we have to declare i
In line 6: before counter we have to also put for
In line 14: we have to put ; in last printf (“hello”) ;

In first for loop we can say it’s = 0 (n+1)
Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .

Final result is = 0(n+1) + 0(n3) = 0 (n³)

The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Janatul Naeem (201-15-3605) -

Ans To The Q No 1 :-

The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. ... The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.

Ans To The Q No 2 :-


At first I wanted to say that this code has some bug.

These are :-----

In line 3:- we have to declare i
In line 6:- before counter we have to also put for
In line 14:- we have to put ; in last printf (“hello”) ;

In first for loop we can say it’s = 0 (n+1) then 0(Log n)
Then in 2nd step we see that here is 2 nested for loop so this answer is = n*n = 0 (n2) .

Final result is = Log n + n2+n +1 [ lower power finish ]

The time complexity is n2.


In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Sazzad Hosain Sagor -
1. Use of time complexity makes it easy to estimate the running time of a program. Performing
an accurate calculation of a program’s operation time is a very labour-intensive process

2.
line 3:- declare i .
line 6:- before counter we have to also put ; (counter = 1 ,counter <= N, counter++);
line 14:- we have to put ;


In first for loop we can say it’s = 0 (n+1)
Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .

Final result is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ]

The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Ibrahim Tasin -

Answer to the question no 1

 We need to know Time complexity because:

 Time complexity is the computational complexity that describes the amount of time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm. It can be applied to almost any algorithm or function but is more useful for recursive functions.

 


Answer to the question no 2

 The time complexity of the following code and explain are:


In line number 3: we need to announce i.

In line number 6: preceding counter we need to likewise put for.

In line number 14: we need to put ; in last printf("hello");

In first for circle we can say it's = 0 (n+1). At that point in second step we see that here is 3 settled for circle so this answer is = n*n*n= 0 (n³). Conclusive outcome is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ].

The time complexity is n³.

In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by RIFAT JAHAN ZIM 201-15-3611 -

1. Use of time complexity makes it easy to estimate the running time of a program. Performing
an accurate calculation of a program’s operation time is a very labour-intensive process

2.
line 3:- declare i .
line 6:- before counter we have to also put ;     (counter = 1 ,counter <= N, counter++);
line 14:- we have to put ;


In first for loop we can say it’s = 0 (n+1)
Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .

Final result is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ]

The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Maherunnesa Mim -
Ans To The Q No 1:-
The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. ... The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.

Ans To The Q No 2 :-
These are:-----
line number 3:- we have to declare i
line number 6:- before counter we have to also put for
line number 14:- we have to put; in the last printf (“hello”);
In first for loop we can say it’s = 0 (n+1) Then in 2nd step, we see that here is 2nested for loop so this answer is = n*n = 0 (n^2) .
Final result is = 0(n+1) + 0(n^2) = 0 (n^2) [ lower power finish ]. The time complexity is n^2.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Yousuf Rayhan Emon -
Answer to the Question No: 01
Time Complexity: It's a term that deals with the total execution time of an algorithm. The best time complexity ever is "Linear Time, Constant Space", which is the most efficient one ie. O(n). But not all the algorithms has a linear time complexity. That's why "the lesser the complexity is the better the algorithm".

Answer to the Question No: 02

The code has got various loops to deal with. The first loop even though that's a bug as the 'for' is missing there counts a complexity of O(n+1). Cause it follows by a condition and a single loop.
In second phase there are 3 more loops. Where two of those are linked that gives us the complexity of O(n^2). And the last most loop is again a non nested one. SO, it counts O(n) again.
As O(n^2) is greatest among all so the actual complexity is itself.
*But there is a catch. The highest complexity is always feasible in worst case. As the code's second phase deals with a condition where it executes only if it satisfies the condition so the complexity on it's best case can be as minimum as O(n+1). But in terms of total count we still can say it O(n^2).
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Zannatul Mawya Priya 201-15-3209 -
Ans To The Question No 1 :-


Time complexity of an algorithm signifies the total time required by the program to run till its completion.

Ans To The Questions No 2 :-


There are some bugs in this code.

These are :

In line 3: we have to declare i
In line 6: before counter we have to also put for
In line 14: we have to put ; in last printf (“hello”) ;

In first for loop we can say it’s = 0 (n+1)
Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .

Final result is = 0(n+1) + 0(n3) = 0 (n³)

The time complexity is n³.

Jump to...
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Amir Hamza Shuvo 201-15-3397 -
ans to the ques no: 1

Time Complexity: It's a term that deals with the total execution time of an algorithm. The best time complexity ever is "Linear Time, Constant Space", which is the most efficient one ie. O(n). But not all the algorithms has a linear time complexity. That's why "the lesser the complexity is the better the algorithm".
Ans To The Q No 2 :-


At first I wanted to say that this code has some bug.

These are :-----

In line 3:- we have to declare i .
· In line 6:- before counter we have to also put for .
· In line 14:- we have to put ; in last printf (“hello”) ;


In first for loop we can say it’s = 0 (n+1)

Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n= 0 (n2) .

Final result is = 0(n+1) + 0(n2) = 0 (n2) [ lower power finish ]

The ti
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Md. Shahin Alam -
ans to the ques no: 1

Time Complexity: It's a term that deals with the total execution time of an algorithm. The best time complexity ever is "Linear Time, Constant Space", which is the most efficient one ie. O(n). But not all the algorithms has a linear time complexity. That's why "the lesser the complexity is the better the algorithm".

ans to the ques no: 2

The code has got various loops to deal with. The first loop even though that's a bug as the 'for' is missing there counts a complexity of O(n+1). Cause it follows by a condition and a single loop.

In second phase there are 3 more loops. Where two of those are linked that gives us the complexity of O(n^2). And the last most loop is again a non nested one. SO, it counts O(n) again.

As O(n^2) is greatest among all so the actual complexity is itself.

*But there is a catch. The highest complexity is always feasible in worst case. As the code's second phase deals with a condition where it executes only if it satisfies the condition so the complexity on it's best case can be as minimum as O(n+1). But in terms of total count we still can say it O(n^2).
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Rimon Rimon -
Answer to the question no:1

Time complexity of an algorithm is a total amount of time required by algorithm to complete execution. we need to know because how long it's take and specify the total running time.

Answer to the question no: 2

This code contains bug. These are some problems that I found -
In line 3:- we have to declare i
In line 6:- before counter we have to also put for
In line 14:- we have to put ; in last printf (“hello”) ;

In first for loop we can say it’s = 0 (n+1)
Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .

Final result is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ]

The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Md. Seyam Ali Biswas -
Answer to the question no : 1

Time complexity in computer science is the complexity of computation that describes the time it takes to run an algorithm. Time complexity is usually estimated by calculating the initial activities performed by the algorithm, assuming that each initial activity takes a certain amount of time to perform. Thus, the initial activity performed by time and algorithms is separated by the most constant factor.





Answer to the question no : 2

This code contains bug.These are some problems that I found -

In line 3: we have to declare i

In line 6: before counter we have to also put for

In line 14: we have to put ; in last printf (“hello”) ;





In first for loop we can say it’s = 0 (n+1)

Then in second step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .

Final result is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ]

The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by 201-15-3596 sadia afrin satu -
1. Use of time complexity makes it easy to estimate the running time of a program. Performing
an accurate calculation of a program’s operation time is a very labour-intensive process.

2.
line 3:- declare i .
line 6:- before counter we have to also put for
line 14:- we have to put ; in last printf (“hello”) ;


In first for loop we can say it’s = 0 (n+1)
Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .

Final result is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ]

The time complexity is n³
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by 201-15-3532 Sumaiya Haider -
1)Ans-The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. ... The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.
2)Ans-line 3:- declare i .
line 6:- before counter we have to also put for
line 14:- we have to put ; in last printf (“hello”) ;
In first for loop we can say it’s = 0 (n+1)
Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .
Final result is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ]
The time complexity is n³
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by 201-15-3311 Mehedi -
Ans 1.
Time complexity is the computational complexity that describes the amount of time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm.It can be applied to almost any algorithm or function but is more useful for recursive functions.
Ans 2.
This code has some bug.

So These are :

In line 3:- we have to declare i
In line 6:- before counter we have to also put for
In line 14:- we have to put ; in last printf (“hello”) ;

In first for loop we can say it’s = 0 (n+1)
Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .

Final result is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ]

The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Tapu Chandra Malo -
Ans. to the question NO-1

Time Complexity: It's a term that deals with the total execution time of an algorithm. The best time complexity ever is "Linear Time, Constant Space", which is the most efficient one . But not all the algorithms has a linear time complexity. That's why "the lesser the complexity is the better the algorithm".


Ans. to the question NO-2

This code contains bug. These are some problems that I found -
In line 3:- we have to declare i
In line 6:- before counter we have to also put for
In line 14:- we have to put ; in last printf (“hello”) ;

In first for loop we can say it’s = 0 (n+1)
Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .

Final result is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ]

The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Sazzad Hosen khan -
Answer to the question no 1



Time complexity is the computational complexity that describes the amount of time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm.It can be applied to almost any algorithm or function but is more useful for recursive functions.





Answer to the question no 2



In line number 3- we need to announce i.

In line number 6:- preceding counter we need to likewise put for.

In line number 14:- we need to put ; in last printf ("hello");

In first for circle we can say it's = 0 (n+1). At that point in second step we see that here is 3 settled for circle so this answer is = n*n*n= 0 (n³) .Conclusive outcome is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ].

The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Nujhat Tabassum(201-15-3363) -

Answer to the question no.1


Time complexity of an algorithm is the representation of the amount of time required by the algorithm to execute to completion. The time complexity of an algorithm can make a big difference as to whether it is practical to apply it to large instances. So we need to know the time complexity deeply to store the data efficiently in short time.

Answer to the question no.2


There are some errors in the code. They are-

1) Data type of "i" is not declared.
2) In the 1st loop, the word "for" is missing which is initialized by the "counter" variable.
3) In the last line, Semicolon(;) is missing after "printf("hello")"

Time Complexity of the given code:
For the 1st loop, time complexity = O(n)
For the nested loop, time complexity = O(n^2) + O(1) = O(n^2)
For the last loop time complexity = log(n)
So, Time complexity of the code = O(n) + O(n^2) + log(n) =O(n^2) (Answer)
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Arnab Saha -
Answer to the question no:1
The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. ... The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.
Answer to the question no:2
line 3:- declare i .
line 6:- before counter we have to also put ; (counter = 1 ,counter <= N, counter++);
line 14:- we have to put ;

In first for loop we can say it’s = 0 (n+1)
Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .

Final result is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ]

The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by 201-15-3165 MD.HASIBUL HASAN SHANTO -
Answer to the Q. No 1

Time complexity :

In computer science, time complexity is the complexity of computation that describes the time it takes to run an algorithm. Time complexity is usually estimated by calculating the initial activities performed by the algorithm, assuming that each initial activity takes a certain amount of time to perform. Thus, the initial activity performed by time and algorithm is separated by the most constant factor.

Since the running time of the algorithm can vary between different inputs of the same size, the worst time complexity is generally considered to be the maximum amount required for inputs of a given size. Less common, and usually explicitly specified, is the mean-case complexity, which is the average of the time taken for inputs of a given size (this is understood because there are only a limited number of possible inputs of a given size). In both cases time complexity is usually expressed as a function of input size. Since this function is usually difficult to calculate accurately and running time for small inputs is not usually the result, one usually focuses on the behavior of the complex when the input size increases - i.e. the asymptomatic behavior of the complex.


Answer to the Q. No 2


#include
int main() {

int counter, N;
printf("Enter a Positive Number\n");
scanf("%d", &N);
for(counter = 1; counter <= N; counter++) {

printf("%d \n", counter);}

int a=12,n=12;

if(N>10){

for(int i=0;i
for(i=0;i
a++; } }

for(int i=0;i
printf("hello");

}

}

return 0;

}

Ans:

At first I wanted to say that this code has some bug.

These are ….

· In line 3:- we have to declare i .
· In line 6:- before counter we have to also put for .
· In line 14:- we have to put ; in last printf (“hello”) ;


In first for loop we can say it’s = 0 (n+1)

Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n= 0 (n2) .

Final result is = 0(n+1) + 0(n2) = 0 (n2) [ lower power finish ]

The time complexity is n2.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Wahid Tausif -
Ans To The Q No 1 :-


The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. ... The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.

Ans To The Q No 2 :-


At first I wanted to say that this code has some bug.

These are :-----

In line 3:- we have to declare i .
· In line 6:- before counter we have to also put for .
· In line 14:- we have to put ; in last printf (“hello”) ;


In first for loop we can say it’s = 0 (n+1)

Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n= 0 (n2) .

Final result is = 0(n+1) + 0(n2) = 0 (n2) [ lower power finish ]

The time complexity n2
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Md Taufiq ali -
Ans To The Q No 1 :-


The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution. ... The time taken by any piece of code to run is known as the time complexity of that code. The lesser the time complexity, the faster the execution.

Ans To The Q No 2 :-


At first I wanted to say that this code has some bug.

These are :-----

In line 3:- we have to declare i
In line 6:- before counter we have to also put for
In line 14:- we have to put ; in last printf (“hello”) ;

In first for loop we can say it’s = 0 (n+1)
Then in 2nd step we see that here is 3 nested for loop so this answer is = n*n*n = 0 (n³) .

Final result is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ]

The time complexity is n³.


Tags: Asymptotic Notations Best case Wrost Case Average case Big Notation Omega Notation Theta Notation Arithmetic operation Time Complexity
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Mehedi Hasan (201-15-3144 ) -
Time complexity of an algorithm is the representation of the amount of time required by the algorithm to execute to completion. The time complexity of an algorithm can make a big difference as to whether it is practical to apply it to large instances. So we need to know the time complexity deeply to store the data efficiently in short time.

Answer to the question no.2


There are some errors in the code. They are-

1) Data type of "i" is not declared.
2) In the 1st loop, the word "for" is missing which is initialized by the "counter" variable.
3) In the last line, Semicolon(;) is missing after "printf("hello")"

Time Complexity of the given code:
For the 1st loop, time complexity = O(n)
For the nested loop, time complexity = O(n^2) + O(1) = O(n^2)
For the last loop time complexity = log(n)
So, Time complexity of the code = O(n) + O(n^2) + log(n) =O(n^2) (Answer)
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Rayhanul Amin Nafis (201-15-3164) -
Answer to the question no 1



Time complexity is the computational complexity that describes the amount of time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm.It can be applied to almost any algorithm or function but is more useful for recursive functions.





Answer to the question no 2



In line number 3- we need to announce i.

In line number 6:- preceding counter we need to likewise put for.

In line number 14:- we need to put ; in last printf ("hello");

In first for circle we can say it's = 0 (n+1). At that point in second step we see that here is 3 settled for circle so this answer is = n*n*n= 0 (n³) .Conclusive outcome is = 0(n+1) + 0(n3) = 0 (n³) [ lower power finish ].

The time complexity is n³.
In reply to Md Assaduzzaman

Re: Answer the question and discuss if you have any confusion

by Atikur Mithun -

Answer to the question number :1

The time complexity of an algorithm is total amount of time required by an algorithm of complete its excution.the time taken by any piece of code to run is khown as the time complexity of that code.the lesser the time complexity,the faster the excution.

We can find out the minimum or maximum time taken by any algorithm through time complexity.As a result,i can use the program efficiently.

Answer to the question number :2

  Line 3: We have to declare i.

Line No 6 : - We need to keep the same in the previous counter.
In line 14: - We have to put; Latest printef ("hello");
For the circle first we can say it = 0 (n + 1). At that moment in the second step we can see that 3 circles are settled here so this answer is = n * n * n = 0 (n³) C Final result = 0 (n + 1) + 0 (n3) = 0 (NO) ) [Lower power finish] [. Higher power acceptable]


The time complexity is n³.