Answered step by step
Verified Expert Solution
Link Copied!

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, read/write take constant time c). For example, your answer should be as detailed as shown in the following sample example.
Sample algorithm
for (int i =1; i <= n; i++){
int a =4;
int b =5;
int c = a + b;
}
Algorithms
Sample analysis
for (int i =1 to n){//loop is running n times
int a =4; //constant time c.
int b =5; //constant time c.
int c = a + b; //constant time c.
}
Exact time = n (c+c+c)=3cn
Asymptotic time = O(n)
-------
1.A function (or set of statements) that doesnt contain loop, recursion and call to any other non-constant time function, such as follows:
Fun(int array A of size n){
int x =5;
int y =4;
int z = x + y;
}
Exact = Asymptotic =
2.A loop or recursion that runs a constant number of times, such as follows:
Fun(int array A of size n){
for (int i =1 to k){// Here k is a constant, it could be any constant number
for (int j =1 to k)
{
int a =5;
a++;
a--;
}
}
}
Exact = Asymptotic =
3.A loop where the loop variables is incremented / decremented by a constant amount k, as follows:
Fun(int array A of size n){
// Here k is a positive integer constant
for (int i =1; i <= n; i += k){
int a =5;
a+=i ;
}
}
Exact = Asymptotic =
4.Time complexity of nested loops as follows:
Fun(int array A of size n){
// Here k is a positive integer constant
for (int i =1; i <=n; i += k){
for (int j = n; j >=1; j = k){
int a = i + j;
}
}
}
Exact = Asymptotic =
5.Time Complexity of a loop if the loop variables is divided / multiplied by a constant amount k as follows:
Fun(int array A of size n){
for (int i =1; i <=n; i *= k){
int a = i + i ;
} Exact = Asymptotic =
6.Time Complexity of a loop if the loop variables is reduced / increased exponentially by a constant amount as follows:
Fun(int array A of size n){
for (int i =2; i <=n; i = i2){
int a = i;
}
}
Exact = Asymptotic =
7.Time Complexity of a loop if the loop variables is reduced / increased by a sqrt amount as follows:
Fun(int array A of size n){
for (int i = n; i >2; i = sqrt(i)){//here sqrt means square root
int a = i;
}
}
Exact = Asymptotic =
8.Time Complexity of a function with a variety of loops:
Fun(int array A of size n){
for (int i =1; i <=n; i*=2){
for (int j =1; j <=n; j*=3){
int a = i+j;
}
for (int j =2; j <=n; j = j2){
int a = j;
}
}
for (int i =1; i <=n; i+=4){
for (int k =2; k <=n; k = k2){
int a = i+k;
}
}
}
Exact = Asymptotic =

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago