Discussion forum week 2(Edited)

Click here

Click here

by Md Assaduzzaman -
Number of replies: 57

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: Week -2

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(n2)
then in the third loop it will be= O(Logn)
the final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)
In reply to Md Assaduzzaman

Re: Click here

by Tanmoy Komer (201-15-3439) -
Picture of DS-(PC-F)

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.
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(n2)
then in the third loop it will be= O(Logn)
the final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)
In reply to Md Assaduzzaman

Re: Click here

by MD.SADIK RAHMAN -
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(n2)
then in the third loop it will be= O(Logn)
the final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)
In reply to Md Assaduzzaman

Re: Click here

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 declare i
In line number 6:- before counter we need to put for
In line number 14:- we have to put ; in last printf ("hello");

In first for circle we can say it's = 0 (n+1)
In second and third loop it will be= 0(n2) and 0(Logn)
Final result=O(n+1)+O(n2)+O(Logn)= O(n2) (Ans)
In reply to Md Assaduzzaman

Re: Click here

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 have to fix some problems of this code.

There are...

• I have to declare i in the 3rd line.
• I have to use a for loop before the counter.
• I 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(n2)
then in the third loop it will be= O(Logn)
The final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)

The time complexity is n2.

In reply to Md Assaduzzaman

Re: Click here

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 

 Ans no 2:

In line number 3- we need to declare i

In line number 6:- before counter we need to put for

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


In first for circle we can say it's = 0 (n+1)

In second and third loop it will be= 0(n2) and 0(Logn)

Final result=O(n+1)+O(n2)+O(Logn)= O(n2) (Ans)

In reply to Md Assaduzzaman

Re: Click here

by Prayma Bishshash 201-15-3168 -
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

Ans no 2:

In line number 3- we need to declare i

In line number 6:- before counter we need to put for

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



In first for circle we can say it's = 0 (n+1)

In second and third loop it will be= 0(n2) and 0(Logn)

Final result=O(n+1)+O(n2)+O(Logn)= O(n2)
In reply to Md Assaduzzaman

Re: Click here

by Md.Yeasin Chowdhury 201-15-3443 -

Answer :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.

Answer:2 

At first I have to fix some problems of this code.
• I have to declare i in the 3rd line.
• I have to use a for loop before the counter.
• I 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(n2)
then in the third loop it will be= O(Logn)
the final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)

The time complexity is n2.
In reply to Md Assaduzzaman

Answer

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)

And the for the last loop time complexity = log(n)

So, Time complexity of this code = O(1)+O(n) + O(n^2) + log(n)

=O(n^2) (Answer)

In reply to Md Assaduzzaman

Re: Click here

by Taslima Jahan Tushi 201-15-3269 -

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(n2)
then in the third loop it will be= O(Logn)
the final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)

In reply to Md Assaduzzaman

Re: Click here

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: Click here

by Fiaj Rahman(201-15-3077) -
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 declare i

In line number 6:- before counter we need to put for

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



In first for circle we can say it's = 0 (n+1)

In second and third loop it will be= 0(n2) and 0(Logn)

Final result=O(n+1)+O(n2)+O(Logn)= O(n2) (Ans)
In reply to Md Assaduzzaman

Re: Click here

by Sanjida Zaman Toma 201-15-3102 -
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 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: Click here

by Sajib Bormon 201-15-3773 -
Ans to the question no: 1

Time complexity can be described as total time of that run an algorithm.
Time complexity is very important to a programmer to the total run time of a program. By knowing time complexity a programmer can make a program in efficient way to reduce the total time and can run it more faster.

Answer to the question no 2:

O(n^2) + log(a) + O(n)= O(n^2)
In reply to Md Assaduzzaman

Re: Click here

by Shohanur Rahman 201-15-3401 -

#Answer for question-01

Knowing the complexities of this period will help you determine if your code scales. Also, it is easy to compare multiple solutions to the same problem. At the end of it all, you'll be able to look at different implementations and find out which one will perform better without running the code. 

#Answer for question-02

There are some bugs in the code. We need to fix it- 

At first, we have to take for loop.  

Then, we need to declare i.  

After then, we need to put ; in the last printf() function.  


Now, finding the time complexity of this code- 

In the first loop, it will be = O(n+1) 

In the second loop, it will be = O(n2) 

Then in the third loop it will be= O(Logn) 

Finally, the result will be = O(n+1) +O(n2) +O(Logn)= O(n2) 

So, the time complexity is n2

In reply to Md Assaduzzaman

Re: Click here

by 201-15-3417 Arpita Basak -
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 declare i

In line number 6:- before counter we need to put for

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



In first for circle we can say it's = 0 (n+1)

In second and third loop it will be= 0(n2) and 0(Logn)

Final result=O(n+1)+O(n2)+O(Logn)= O(n2)
In reply to Md Assaduzzaman

Re: Click here

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)
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(n2)
then in the third loop it will be= O(Logn)
the final result will be=O(n+1)+O(n2)+O(Logn)= O(n2)
[Lower power finish] [. Higher power acceptable]
So the complexity during the program is n^2
In reply to Md Assaduzzaman

Re: Click here

by Md. Sakibuzzaman Alif -
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(n2)
then in the third loop it will be= O(Logn)
the final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)
In reply to Md Assaduzzaman

Re: Click here

by Sk Dhrubo (201-15-3169) -
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

Ans no 2:

In line number 3- we need to declare i

In line number 6:- before counter we need to put for

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



In first for circle we can say it's = 0 (n+1)

In second and third loop it will be= 0(n2) and 0(Logn)

Final result=O(n+1)+O(n2)+O(Logn)= O(n2).
In reply to Md Assaduzzaman

Re: Click here

by RIFAT JAHAN ZIM 201-15-3611 -

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 declare i
In line number 6:- before counter we need to put for
In line number 14:- we have to put ; in last printf ("hello");

In first for circle we can say it's = 0 (n+1)
In second and third loop it will be= 0(n2) and 0(Logn)
Final result=O(n+1)+O(n2)+O(Logn)= O(n2) (Ans)

In reply to Md Assaduzzaman

Re: Click here

by Sabbir Hossain Antar -
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 declare i
In line number 6:- before counter we need to put for
In line number 14:- we have to put ; in last printf ("hello");

In first for circle we can say it's = 0 (n+1)
In second and third loop it will be= 0(n2) and 0(Logn)
Final result=O(n+1)+O(n2)+O(Logn)= O(n2) (Ans)
In reply to Md Assaduzzaman

Re: Click here

by Ordha Nafiz Akbar -
There are some bugs in this code.
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(n2)
then in the third loop it will be= O(Logn)
the final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)
In reply to Md Assaduzzaman

Re: Click here

by Arifa Rahman Tony -
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(n2)
then in the third loop it will be= O(Logn)
the final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)
In reply to Md Assaduzzaman

Re: Click here

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

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 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: Click here

by Arpita Ghosh 201-15-3422 -
Ans: to the Questions 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 the line 3- we have to declare i
In the line 6:- before counter we need to put for
In the line 14:- we have to put ; in last printf ("hello");

In first for circle we can say it's = 0 (n+1)
In second and third loop it will be= 0(n2) and 0(Logn)
Final result=O(n+1)+O(n2)+O(Logn)= O(n2) (Ans)
In reply to Md Assaduzzaman

Re: Click here

by Mohammad Ashikuzzaman 3438 -
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: Click here

by Md. Atikur Rahman -
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: Click here

by Sabul Hasan -
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 declare i
In line number 6:- before counter we need to put for
In line number 14:- we have to put ; in last printf ("hello");

In first for circle we can say it's = 0 (n+1)
In second and third loop it will be= 0(n2) and 0(Logn)
Final result=O(n+1)+O(n2)+O(Logn)= O(n2) (Ans)
In reply to Md Assaduzzaman

Re: Click here

by MD. IMDADUL HAQUE 201-15-3538 -
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.
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(n2)
then in the third loop it will be= O(Logn)
the final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)
In reply to Md Assaduzzaman

Re: Click here

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
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(n2)
then in the third loop it will be= O(Logn)
the final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)
In reply to Md Assaduzzaman

Re: Click here

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: Click here

by Farzana shanchita 3574 -
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.Space complexity of an algorithm quantifies the amount of space or memory taken by an algorithm to run as a function of the length of the input.

2)In line number 3- we need to declare i
.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(n2)
then in the third loop it will be= O(Logn)
the final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)
In reply to Md Assaduzzaman

Re: Click here

by Mst Naima Sultana -

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(n2)
then in the third loop it will be= O(Logn)
the final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)

In reply to Md Assaduzzaman

Re: Click here

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 we can say that it is = 0 (n+1)
In second and third loop it will be= 0(n2) and 0(Logn)
Final result=O(n+1)+O(n2)+O(Logn)= O(n2) (Ans)
In reply to Md Assaduzzaman

Re: Click here

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: Click here

by Md. Farhatul Haider -
#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 we can say that it is = 0 (n+1)
In second and third loop it will be= 0(n2) and 0(Logn)
Final result=O(n+1)+O(n2)+O(Logn)= O(n2) (Ans)
In reply to Md Assaduzzaman

Re: Click here

by Nujhat Tabassum(201-15-3363) -

Ans. to the question no. 1


Why we need to know Time Complexity:

The time complexity is the number of operations an algorithm performs to complete its task (considering that each operation takes the same amount of time). The algorithm that performs the task in the smallest number of operations is considered the most efficient one in terms of the time complexity.
The time complexity of an algorithm can make a big difference as to whether it is practical to apply it to large instances. We know that for a small number of elements (say 10), the difference between the number of operations performed by binary search and linear search is not so big. But in the real world, most of the time, we deal with problems that have big chunks of data.
For example, if we have 4 billion elements to search for, then, in its worst case, linear search will take 4 billion operations to complete its task. Binary search will complete this task in just 32 operations. That’s a big difference. Now let’s assume that if one operation takes 1 ms for completion, then binary search will take only 32 ms whereas linear search will take 4 billion ms (that is approx. 46 days). That’s a significant difference.
This is the reason why studying time complexity becomes important when it comes to such a big amount of data.


Ans. to the question no. 2


Errors in the code:

• The data type of ‘i’ is not declared in the code.
• In 6th line, ‘for’ is missing to declare a loop.
• There is no need to assign n=12 in the 8th line.
• In 14th line, semicolon ‘ ; ' is missing after the statement.

Time complexity:

• In 6th line, for the 1st loop time complexity = O(n+1)
• In the 9th line, for the nested loop time complexity = O(n^2)
• In 13th line, the for the last loop time complexity = O(log(n))
So, Time complexity of this code = O(n+1)+O(n^2) + O(log(n)) = O(n^2)
In reply to Md Assaduzzaman

Re: Click here

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: Click here

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

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(n2)
then in the third loop it will be= O(Logn)
the final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)
In reply to Md Assaduzzaman

Re: Click here

by Md.Majedul Haque Tanin -
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(n2)
then in the third loop it will be= O(Logn)
the final result will be = O(n+1)+O(n2)+O(Logn)= O(n2).
In reply to Md Assaduzzaman

Re: Click here

by Md. Seyam Ali Biswas -
Answer to thequestion. 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.



Answer to the question. 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 we can say that it is = 0 (n+1)
In second and third loop it will be= 0(n2) and 0(Logn)
Final result=O(n+1)+O(n2)+O(Logn)= O(n2) (Ans)
In reply to Md Assaduzzaman

Re: Click here

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- a)We have to declare i in the 3rd line
b) We have to use a for loop before the counter
c) We will have to put a ; in line 14
d)In the first loop, it will be = O(n+1)
e)In the second loop, it will be = O(n2)
f)then in the third loop it will be= O(Logn)
g)the final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)
In reply to Md Assaduzzaman

Re: Click here

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 declare i

In line number 6:- before counter we need to put for

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


In first for circle we can say it's = 0 (n+1)

In second and third loop it will be= 0(n2) and 0(Logn)

Final result=O(n+1)+O(n2)+O(Logn)= O(n2) (Ans)

In reply to Md Assaduzzaman

Re: Click here

by Tania Ahmed Nipa (201-15-3282) -
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(n2)
then in the third loop it will be= O(Logn)
the final result will be = O(n+1)+O(n2)+O(Logn)= O(n2).
In reply to Md Assaduzzaman

Re: Click here

by Ibrahim Tasin -

Ans to the question no : 1



We need to know about time complexity because;

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


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 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: Click here

by ABU BAKAR SIDDIQUE 201-15-3352 -
1)ANS:
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
2)Ans:

At first I have to fix some problems of this code.

There are...

• I have to declare i in the 3rd line.
• I have to use a for loop before the counter.
• I 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(n2)
then in the third loop it will be= O(Logn)
The final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)

The time complexity is n2.
In reply to Md Assaduzzaman

Re: Click here

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³.
In reply to Md Assaduzzaman

Re: Click here

by Md Taufiq ali -
ANS 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 2 -

At first, we have to fix some problems with 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; inline 14
In the first loop, it will be = O(n+1)
In the second loop, it will be = O(n2)
then in the third loop, it will be= O(Logn)
the final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)
In reply to Md Assaduzzaman

Re: Click here

by Anika Nawar -
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-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(n2)
then in the third loop it will be= O(Logn)
the final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)
In reply to Md Assaduzzaman

Re: Click here

by Juwel Rana Jony -
Answer for question-01:

Knowing the complexities of this period will help you determine if your code scales. Also, it is easy to compare multiple solutions to the same problem. At the end of it all, you'll be able to look at different implementations and find out which one will perform better without running the code.

Answer for question-02:

There are some bugs in the code. We need to fix it-

At first, we have to take for loop.

Then, we need to declare i.

After then, we need to put ; in the last printf() function.



Now, finding the time complexity of this code-

In the first loop, it will be = O(n+1)

In the second loop, it will be = O(n2)

Then in the third loop it will be= O(Logn)


Finally, the result will be = O(n+1) +O(n2) +O(Logn)= O(n2)

So, the time complexity is n2
In reply to Md Assaduzzaman

Re: Click here

by 201-15-3311 Mehedi -
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.
Question no 2.
First we need to solve some problems with this code.
• We need to declare in the third line
We need to use for the loop before the counter
• We have to keep one; Line 14
In the first loop it will be = O(n + 1)
In the second loop it will be = O(n2)
Then in the third loop it will be = O(logn)
The final result will be = O(n + 1) + O (n2) + o (Logn) = O(n2)
In reply to Md Assaduzzaman

Re: Click here

by Abdullah Al Noman 201-15-3646 -
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(n2)
then in the third loop it will be= O(Logn)
the final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)
In reply to Md Assaduzzaman

Re: Click here

by Sazzad Hosen khan -
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(n2)
then in the third loop it will be= O(Logn)
the final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)
In reply to Md Assaduzzaman

Re: Click here

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: Click here

by Sazzad Hosen khan -
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.

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(n2)
then in the third loop it will be= O(Logn)
the final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)
In reply to Md Assaduzzaman

Re: Click here

by Shraboni Rahman Jui 201-15-3089 -
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 have to fix some problems of this code.

There are...

• I have to declare i in the 3rd line.
• I have to use a for loop before the counter.
• I 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(n2)
then in the third loop it will be= O(Logn)
The final result will be = O(n+1)+O(n2)+O(Logn)= O(n2)

The time complexity is n2.
In reply to Md Assaduzzaman

Re: Click here

by Mafujul Haque Plabon -
Picture of DS-(PC-J) Picture of DSLab-(PC-J)
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)
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(n2)
then in the third loop it will be= O(Logn)
the final result will be=O(n+1)+O(n2)+O(Logn)= O(n2)
[Lower power finish] [. Higher power acceptable]
So the complexity during the program is n^2