Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Find the time complexity of the following algorithms in terms of Big O. Explain your answer as well. A function (or set of statements) that

Find the time complexity of the following algorithms in terms of Big O. Explain your answer as well.

  1. A function (or set of statements) that doesnt contain loop, recursion and call to any other non-constant time function.
  2. A loop or recursion that runs a constant number of times, such as follows:

for (int i = 1; i <= c; i++) // Here c is a constant

{

// some O(1) expressions

}

  1. A loop where the loop variables is incremented / decremented by a constant amount, as follows:

// Here c is a positive integer constant

for (int i = 1; i <= n; i += c) {

// some O(1) expressions

}

  1. Time complexity of nested loops as follows:

// Here c is a positive integer constant

for (int i = 1; i <=n; i += c) {

for (int j = 1; j <=n; j += c) {

// some O(1) expressions

}

}

  1. Time Complexity of a loop if the loop variables is divided / multiplied by a constant amount as follows:

for (int i = 1; i <=n; i *= c) {

// some O(1) expressions

}

  1. Time Complexity of a loop if the loop variables is reduced / increased exponentially by a constant amount as follows:

// Here c is a constant greater than 1

for (int i = 2; i <=n; i = pow(i, c)) {

// some O(1) expressions

}

//Here fun is sqrt or cuberoot or any other constant root

for (int i = n; i > 0; i = fun(i)) {

// some O(1) expressions

}

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_2

Step: 3

blur-text-image_3

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

Why We Form Relationships Managing Relationship Dynamics?

Answered: 1 week ago