VIKING-CALC(A) 1: output= -4 2: for in-1; i > 0; i-i-4 do 3: 4: 5: 6:...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
VIKING-CALC(A) 1: output= -4 2: for in-1; i > 0; i-i-4 do 3: 4: 5: 6: 7: 8: return output key= A[i] test =A[i -2] condition = A[i - 3] if test x key output = output + test x condition == (key x condition) then D CL ▷ C2 DC3 ▷ CA ▷ C5 ▷ C6 D C7 D C8 Part a: Explain (in prose) what VIKING-CALC does. Part b: What is the return value of VIKING-CALC when A={3,2,4,2,1,1,3,2,1,2,2,6,3,2,3,4}. Part c: Under what conditions does line 7 get executed the fewest number of times? Under what conditions does line 7 get executed the most number of times? Part d: What is the total cost run-time, T(n), of VIKING-CALC? Parte : What is T(n) for VIKING-CALC when line 7 is executed the fewest number of times possible? Please provide your answer in the most simplified form possible. Part f: What is T(n) for VIKING-CALC when line 7 is executed the most number of times possible? Please provide your answer in the most simplified form possible. Part g: What is the worst case total cost run-time of VIKING-CALC in Big-O notation? Part h: What is the best case total cost run-time of VIKING-CALC in Big-O notation? VIKING-CALC(A) 1: output= -4 2: for in-1; i > 0; i-i-4 do 3: 4: 5: 6: 7: 8: return output key= A[i] test =A[i -2] condition = A[i - 3] if test x key output = output + test x condition == (key x condition) then D CL ▷ C2 DC3 ▷ CA ▷ C5 ▷ C6 D C7 D C8 Part a: Explain (in prose) what VIKING-CALC does. Part b: What is the return value of VIKING-CALC when A={3,2,4,2,1,1,3,2,1,2,2,6,3,2,3,4}. Part c: Under what conditions does line 7 get executed the fewest number of times? Under what conditions does line 7 get executed the most number of times? Part d: What is the total cost run-time, T(n), of VIKING-CALC? Parte : What is T(n) for VIKING-CALC when line 7 is executed the fewest number of times possible? Please provide your answer in the most simplified form possible. Part f: What is T(n) for VIKING-CALC when line 7 is executed the most number of times possible? Please provide your answer in the most simplified form possible. Part g: What is the worst case total cost run-time of VIKING-CALC in Big-O notation? Part h: What is the best case total cost run-time of VIKING-CALC in Big-O notation?
Expert Answer:
Answer rating: 100% (QA)
Part a Explanation of VIKINGCALC The given code VIKINGCALC is a pseudocode representation of an algorithm that processes an array A The algorithm iter... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
The cost of a leading liquid laundry detergent in different sizes is given below. Size (ounces) Cost ($) Cost per ounce 16 3.89 32 4.79 64 5.49 200 10.19 Part (a) + Part (b) Part (c) Calculate the...
-
You are asked to develop a Floppy Disk program that allows users to access a floppy disk locally mounted on a computer. You are expected to use C programming language. In your program, all file I/O...
-
For each problem, show your work steps. A correct answer with no work shown gets half credit (which means you fail the assignment). An incorrect answer with no work receives 0 credit. With time value...
-
Consider a social network where people are represented as vertices and friendships as edges. If there are 1 0 people in the network and each person is friends with 3 others, calculate the total...
-
A swimmer does 7.7 105 J of work and gives off 3.9 105 J of heat during a workout. Determine U, W, and Q for the swimmer.
-
Columbia Sportswear Company reported cost of goods sold of U.S. $953,169 thousand on its 2012 income statement. It also reported a decrease in merchandise inventory of U.S. $1,874 thousand and a...
-
Beta Supply completed the following selected transactions during the year: Requirements 1. Open T-accounts for Allowance for Uncollectible Accounts and Uncollectible Accounts Expense. These accounts...
-
Standard Bent Glass wanted to buy a machine for its factory that would produce cut glass. In March 1998, it started negotiations with Glassrobots Oy, a Finnish corporation. By February 1999,...
-
5. Determine (a) cumulative markup percent, (b) gross cost of merchandise sold, and (c) maintained markup percent, given the following information: Cost ($) Retail ($) Opening inventory 37,840 69,320...
-
Reverend Peter Wilson qualifies as a minister for income tax purposes. He receives a $75,000 annual salary and a $32,000 housing allowance. He pays $24,000 (including utilities) per year for the...
-
Summarize the main points of the documentary called The Rise and Reign of Jeff Bezos. Who and what media companies produced it? When was it made? How does the documentary represent different people?...
-
Find f'(x) using the QUOTIENT RULE if f'(x)=0 Find f'(5). f'(5) = f(x) = 6+22
-
Explain how a manager creates a culture of creativity and innovation that facilitates business success. Be sure to provide specific examples as part of your explanation.
-
How can organizations cultivate a culture of continuous learning and knowledge sharing, and what are the challenges associated with implementing effective knowledge management systems?
-
Use the quotient rule to find the derivative of the following. 7x+1 y= 2 x +9 dy dx =
-
What creates change within a culture of integrity that helps the organization thrive over the long haul by promoting openness and honesty, positive relationships, and long-term innovation?
-
When we mention the prototype of a function? Defining Declaring Prototyping Calling
-
Vectors are drawn from the center of a regular n-sided polygon in the plane to the vertices of the polygon. Show that the sum of the vectors is zero.
-
During the 2012 tax year, Irma incurred the following expenses: Union dues..............................................................$275 Tax return preparation...
-
John Williams (age 42) is a single taxpayer, and he lives at 1324 Forest Dr., Reno, NV 89501. His Social Security number is 555-94-9358. John's earnings and withholdings as the manager of a local...
-
Carl and Jenny adopt a Russian orphan. The adoption takes 2 years and two trips to Russia and is final in 2012. They pay $6,000 in 2011 and $7,500 in 2012 of qualified adoption expenses, and have AGI...
-
Derive the equations of motion of the system shown in Fig. 6.29 using Lagrange's equations. k k k3 k4 000 m 000 m2 000 m3 000 FIGURE 6.29 Spring-mass system.
-
When an airplane (see Fig. 6.37(a)) undergoes symmetric vibrations, the fuselage can be idealized as a concentrated central mass \(M_{0}\) and the wings can be modeled as rigid bars carrying end...
-
Use Lagrange's equations to derive the equations of motion of each of the systems shown in Figs. 6.20. 000 k Free -21- -31- Rigid bar, mass 2m A G T x(1) F(t) X3(1) F3(1) 5m x2(1) F(1) FIGURE 6.20...
Study smarter with the SolutionInn App