Find the complexity of the following blocks of code or algorithm's description. [Note: your answer must show the steps that lead to your final answer] 1) count = 0 for i = 1 to n do for k = 1 to n do count = 1 2) for i = 1 to n do count += i for k = 1 to n do for (j = 2 ; j

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question
Find the complexity of the following blocks of code or algorithm's description.
[Note: your answer must show the steps that lead to your final answer]
1) count = 0
for i = 1 to n do
for k = 1 to n do
count = 1
2)
for i = 1 to n do
for (j = 2;j<n;j*= 2)
count = i+k + j;
count += i
for k = 1 to n do
count *= k
k +=2
%3D
end for
while j< n do
count +=j
j*= 2;
end while
The algorithm solves the problem
of size n by recursively solving
sub-problems of size n– 1, and
then combining the solutions in
Q(n) time.
end for
end for
3) The algorithm solves the problem of 4)
size n by dividing it into 64 sub-
problems of size n/8, recursively
solving each sub-problem, and then
combining the solutions in O(n?)
time
5) The algorithm solves the problem
by breaking it into 8 sub-problems
of 1/4 the scale, recursively solving
each sub-maze, and then
combining the solutions in linear
time
Transcribed Image Text:Find the complexity of the following blocks of code or algorithm's description. [Note: your answer must show the steps that lead to your final answer] 1) count = 0 for i = 1 to n do for k = 1 to n do count = 1 2) for i = 1 to n do for (j = 2;j<n;j*= 2) count = i+k + j; count += i for k = 1 to n do count *= k k +=2 %3D end for while j< n do count +=j j*= 2; end while The algorithm solves the problem of size n by recursively solving sub-problems of size n– 1, and then combining the solutions in Q(n) time. end for end for 3) The algorithm solves the problem of 4) size n by dividing it into 64 sub- problems of size n/8, recursively solving each sub-problem, and then combining the solutions in O(n?) time 5) The algorithm solves the problem by breaking it into 8 sub-problems of 1/4 the scale, recursively solving each sub-maze, and then combining the solutions in linear time
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Matrix multiplication
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
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