Question

1. Give the BigO notation for each of the following pseudocode fragments. (A) k = 0...

1. Give the BigO notation for each of the following pseudocode fragments.

(A)

k = 0

loop( k < n )

s = s + ary[k]

k = k + 2

end loop

(B)

j = 1

k = 1

loop( k <= n )

s = s + j

j = j + 1

k = k * 2

end loop

(C) Show work!

k = 0

loop( k < n )

s = s + aryA[k]

k = k + 1

end loop

j = 0

loop( j < n )

s = s + aryB[j]

j = j + 1

end loop

(D) Show work!

k = 0

loop( k < n )

s = s + aryA[k]

k = k + 2

end loop

j = 1

loop( j < n )

s = s + aryB[j]

j = j * 2

end loop

(E) Show work!

k = 1

loop( k < n )

s = s + aryA[k]

k = k * 2

end loop

j = 1

loop( j < n )

s = s + aryB[j]

j = j * 2

end loop

Please, show how you get the results!

Homework Answers

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1.) the following code fragments give running time analysis (Big Oh). Explain your answer: sum2 =...
1.) the following code fragments give running time analysis (Big Oh). Explain your answer: sum2 = 0; sum5 = 0; for(i=1; i<=n/2; i++) { sum2 = sum + 2; } for(j=1; j<=n*n; j++) { sum5 = sum + 5; } i think it is O(n^2) since big oh finds the order of worst case which is the the second loop being n^2 complexity. but im not sure. 2.) Give an efficient algorithm along with running time analysis to find the...
What is the tilde time complexity for the following code fragments: 1) int sum = 0;...
What is the tilde time complexity for the following code fragments: 1) int sum = 0; for (i = n; i > 0; i /= 2) for (j = 0; j < i; j++) sum++; 2) int sum = 0; for (int i = 0; i < n; i++) for (int j = 0; j < i; j+=2) sum++;
1.) Answer the following questions based on the following pseudocode for the function “foo”: Algorithm 1:...
1.) Answer the following questions based on the following pseudocode for the function “foo”: Algorithm 1: foo mystery() foreach i ←1 to n do mystery() foreach j ←1 to i do (A) Determine the exact number of times mystery() is called in terms of n. (B) Assume the mystery function is in O(log(n) ∗ n ^2 ). Determine the complexity of “foo” in O-notation. if i ≤ j then mystery()
give the notation(using letter designation for 1) for the subshells denoted by the following numbers? A)...
give the notation(using letter designation for 1) for the subshells denoted by the following numbers? A) n=6, L=2 B)n=5, l=0 C)n=4, l=3 D) n=6,l=1
As a function of n , what is the flop count of the following code, s=0...
As a function of n , what is the flop count of the following code, s=0 for k=1:n , s=s-j-1 for j=k:n , s=s+k+j^2*(k-1) end end
Solve the following sets of recurrence relations and initial conditions: S(k)−2S(k−1)+S(k−2)=2, S(0)=25, S(1)=16 The answer is:...
Solve the following sets of recurrence relations and initial conditions: S(k)−2S(k−1)+S(k−2)=2, S(0)=25, S(1)=16 The answer is: S(k)=k^2−10k+25 Please help me understand the solution. I get how to get the homogenous solution, I would get Sh(k) = a + bk But I get stuck on the particular solution. Thanks
Given the following algorithm, matching each statement to the correct sequence for complexity analysis. procedure Alg3(A):...
Given the following algorithm, matching each statement to the correct sequence for complexity analysis. procedure Alg3(A): A is a list of n integers 1 for i = 1 to n-1 do 2   x=aix=ai 3 j = i − 1 4 while (j ≥≥ 0) do 5 if x≥ajx≥aj then 6 break 7 end if 8   aj+1=ajaj+1=aj 9 j = j − 1 a end while b   aj+1=xaj+1=x c end for d return A The complexity of this algorithm is O(n2)O(n2)...
Consider the following pseudocode segment. x ← 3 for i  {1, 2,   , n} do      for j  {1,...
Consider the following pseudocode segment. x ← 3 for i  {1, 2,   , n} do      for j  {1, 2,   , n} do      x ← x + 5      for k  {1, 2, 3, 4, 5} do      x ← x + k + 1 What is the value of x after this segment runs?
Multiple Choice: The following function is intended to return the value of a[1] + a[2] +...
Multiple Choice: The following function is intended to return the value of a[1] + a[2] + … + a[n] for n ≥ 1. (The sum of the first n entries in an array of integers). Prove that the function is correct, or explain why it does not produce correct results. ArraySumA(integers n, a[1], a[2], … , a[n]) Local variables: integers i, j     i = 0     j = 0     while i ≤ n do         i = i +...
(Java) For the following code segment, match the different values of the empty line with the...
(Java) For the following code segment, match the different values of the empty line with the resulting Big O complexity of the algorithm. int n = int k = 0; for (int i=0; i <= n; i++){ int j = i; while (j > 0) { // ___MISSING CODE___ k++; } } j = 0; j--; j /= 2; j = j * 2; Options for each are: O(n^3)            O(n * log n)            an...