Consider the following Algorithm: ALGORITHM P(n) //Input a positive integer n i←1 j←0 for k← 1 to n do j←i+ji←j-i return j 1. a) What does this algorithm return when n=1, n=2, n=5? 2. b) What is its basic operation? 3. c) How many times the basic operation executed? 4. d) What is the space cost of the algorithm expressed in big-Theta? 5. e) What is the efficiency class of the algorithm? Show any assumptions you made to arrive at your answer. Indicate whether the efficiency class is constant, linear, quadratic, exponential, etc. in the input size.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter2: Problem Solving Using C++using
Section2.4: Arithmetic Operations
Problem 6E
icon
Related questions
Question

Only Typing answer

Consider the following Algorithm:
ALGORITHM P(n)
//Input a positive integer n
i←1
j←0
for k 1 to n do
ji+jij-i
return j
1. a) What does this algorithm return when n=1, n=2, n=5?
2. b) What is its basic operation?
3. c) How many times is the basic operation executed?
4. d) What is the space cost of the algorithm expressed in big-Theta?
5. e) What is the efficiency class of the algorithm? Show any assumptions you made to
arrive at your answer.
Indicate whether the efficiency class is constant, linear, quadratic, exponential, etc. in the
input size.
Transcribed Image Text:Consider the following Algorithm: ALGORITHM P(n) //Input a positive integer n i←1 j←0 for k 1 to n do ji+jij-i return j 1. a) What does this algorithm return when n=1, n=2, n=5? 2. b) What is its basic operation? 3. c) How many times is the basic operation executed? 4. d) What is the space cost of the algorithm expressed in big-Theta? 5. e) What is the efficiency class of the algorithm? Show any assumptions you made to arrive at your answer. Indicate whether the efficiency class is constant, linear, quadratic, exponential, etc. in the input size.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Counting Sort
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Operations Research : Applications and Algorithms
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole