Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write the exact as well as asymptotic ( Big Oh ) for the time complexity of the following algorithms. Assume that all operations ( arithmetic
Write the exact as well as asymptotic Big Oh for the time complexity of the following algorithms. Assume that all operations arithmetic logical readwrite take constant time c For example, your answer should be as detailed as shown in the following sample example.
Sample algorithm
for int i ; i n; i
int a ;
int b ;
int c a b;
Algorithms
Sample analysis
for int i to nloop is running n times
int a ; constant time c
int b ; constant time c
int c a b; constant time c
Exact time n ccccn
Asymptotic time On
A function or set of statements that doesnt contain loop, recursion and call to any other nonconstant time function, such as follows:
Funint array A of size n
int x ;
int y ;
int z x y;
Exact Asymptotic
A loop or recursion that runs a constant number of times, such as follows:
Funint array A of size n
for int i to k Here k is a constant, it could be any constant number
for int j to k
int a ;
a;
a;
Exact Asymptotic
A loop where the loop variables is incremented decremented by a constant amount k as follows:
Funint array A of size n
Here k is a positive integer constant
for int i ; i n; i k
int a ;
ai ;
Exact Asymptotic
Time complexity of nested loops as follows:
Funint array A of size n
Here k is a positive integer constant
for int i ; i n; i k
for int j n; j ; j k
int a i j;
Exact Asymptotic
Time Complexity of a loop if the loop variables is divided multiplied by a constant amount k as follows:
Funint array A of size n
for int i ; i n; i k
int a i i ;
Exact Asymptotic
Time Complexity of a loop if the loop variables is reduced increased exponentially by a constant amount as follows:
Funint array A of size n
for int i ; i n; i i
int a i;
Exact Asymptotic
Time Complexity of a loop if the loop variables is reduced increased by a sqrt amount as follows:
Funint array A of size n
for int i n; i ; i sqrtihere sqrt means square root
int a i;
Exact Asymptotic
Time Complexity of a function with a variety of loops:
Funint array A of size n
for int i ; i n; i
for int j ; j n; j
int a ij;
for int j ; j n; j j
int a j;
for int i ; i n; i
for int k ; k n; k k
int a ik;
Exact Asymptotic
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started