Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Data structures class 2. (12 p.) Describe the order of magnitude (order of growth) of each of the following code segments using (single term) Big-
Data structures class
2. (12 p.) Describe the order of magnitude (order of growth) of each of the following code segments using
(single term) Big- notation. Assume that all the variables have been previously declared. For a bonus point
count the exact number of operations for each code segment (represent it as a function of n).
(a)
sum = 0;
for (i = 1; i <= n; i++)
sum++;
(b)
sum = 0;
for (i = 1; i <= n; i++)
sum++;
for (j = n; j > 0; j--)
sum++;
(c)
count = 0;
value = n;
while (value > 1) {
value = value / 2;
count++;
}
(d)
sum = 0;
for (i = 1; i < n; i++)
for (j = n; j >= 0; j--)
sum++;
(e)
sum = 0;
for (i = 1; i <= 10; i++)
for (j = 1; j <= n; j++)
sum++;
(f)
count = 0;
value = n;
value = n * ( n + 3) * (n + 5) ;
Step 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