logo

Algorithm Complexity.

   

Added on  2022-10-10

4 Pages746 Words27 Views
Running Head: ALGORITHM COMPLEXITY 1
Algorithm Complexity
Institution
Date
Name
Algorithm Complexity._1
ALGORITHM COMPLEXITY
2
The given problem is nothing but to look for the time complexity of the algorithm. We will go
through the basic rules listed below:
1. Every statement or instruction takes 0(1) time in order to execute. For example, it
executes for one time.
2. In a case where we have loops, its time complexity that goes on a loop is the number of
times the instructions get executed within that loop.
Example:
For(int i=0; i<n; i++);
{
Printf(“Hello Buddy”); _____> n times
}
For the above example, Hello buddy is going to be printed for n times
This shows 0(n) time.
3. Whenever we have nested loops then it will be the number of times the outer loop will
run multiplied by the loop inner running. The time complexity of the algorithm in this
case will be the number of times the inner loop is executed.
Example:
For(int i=0; i<n; i++) _____> n times
{
For (int i=0; i<n; i++) _______> n*n times
{
Printf(“Hello Budy”); _______> n*n times
}
}
In this example, Hello Budy will be printed (n*n times). Therefore the time complexity of
thealgorithm will be inner statements executed ... as in:
0(n*n) = 0(n squared)
4. When we try finding the time complexity, we should take the order having the bigger
power.
Example:
Int a; +n
For(int i=0; i<n; i++) + n
For(int i=0; i<n; i++)
Printf(“Hello buddy”) +n
Time complexity = 1+n +n squared == 0(n squared) and we take the biggest degree.
Algorithm Complexity._2

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Answers to given questions
|2
|560
|159

Word Puzzle Generator in C++
|9
|2474
|149

CLDA Loan Management Application: View, Request, Sort and Accept Loans
|14
|3975
|327

C Programming Language Assignment
|44
|2042
|197