Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. For the following four procedures find the exact value of c when the procedure terminates. If you cannot determine the exact value use the
1. For the following four procedures find the exact value of c when the procedure terminates. If you cannot determine the exact value use the -notation.
a. f(n) (* n > 0 is an integer *)
c = 0
for i = 1 to n do
for j = i to n do
c := c + 1
b. f(n) (* n > 0 is an integer *)
c = 0
for i = 1 to n do
for j = 1 to 2n do
for k = 1 to 3n do
c := c + 1
c. f(n) (* n = k 2 is a positove square integer *)
c = 0
for i = 1 to n do
if i is a square number then
c := c + 1
d. f(n) (* n = 2k is a power of 2 integer *)
c = 0
while n > 1 do
n := n/2
c := c + 1
1. For the following four procedures find the exact value of e when the procedure terminates. If you cannot deterie the exact value use the -notation (a) F(n) n 0 is an integer for i 1 to n do for j-i to n do c+1 b) f(n) n> 0 is an integer) 0 for i-1 to n do for j1 to 2n do for k 1 to 3n do (e) f(n) n2 is a positove square integer fori 1 to n do if i is a square number then e: c+1 (d) f(n) 2 is a power of 2 integer *) 0 while n>1 do nn/2Step 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