In this problem you will count the exact number of steps for the code segment below....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
In this problem you will count the exact number of steps for the code segment below. You should count each assignment and each comparison as one step. i = n; sum = 0; while (i > 0) { // this is the body of the loop j=i* 2; } sum sum + k=i*j; + j; i=i-1; Q1.(1 points) How many steps are executed when n is 0? Q2.(1 points) How many steps are executed when n is 1? Q3.(2 points) How many times does the body of the loop execute? Q4. (6 points) The total number of steps in an execution of the code segment is 9 In this problem you will count the exact number of steps for the code segment below. You should count each assignment and each comparison as one step. i = n; sum = 0; while (i > 0) { // this is the body of the loop j=i* 2; } sum sum + k=i*j; + j; i=i-1; Q1.(1 points) How many steps are executed when n is 0? Q2.(1 points) How many steps are executed when n is 1? Q3.(2 points) How many times does the body of the loop execute? Q4. (6 points) The total number of steps in an execution of the code segment is 9
Expert Answer:
Answer rating: 100% (QA)
Q1 When n is 0 the loop condition i 0 is false from the beginning so the loop does not execute at al... View the full answer
Related Book For
Data Structures and Algorithm Analysis in Java
ISBN: 978-0132576277
3rd edition
Authors: Mark A. Weiss
Posted Date:
Students also viewed these programming questions
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Mike is a salesperson in a retail carpet store. He is paid $500 base salary per month plus 5% commission on sales over $10,000. His sales this month were $23,750. His total deductions were $152.75....
-
Fourteen percent of U.S. residents are in their twenties. Consider a group of eight U.S. residents selected at random. In following Exercises, find the probabilities that the number of people in the...
-
On January 1, 2012, the Lovell Company budget committee has reached agreement on the following data for the 6 months ending June 30, 2012. Sales units:First quarter 5,000; second quarter 6,000; third...
-
A business firm is thinking of buying a capital good, which will earn \($2,000\) a year for the next four years and cost \($7,000.\) The interest rate is 8 percent. Should the firm buy the capital...
-
Ammonia is oxidized in a well-insulated continuous reactor: 4 NH 3 (g) + 5 O 2 (g) ? 4 NO (g) + 6 H 2 O (v): ?H? ? = ? 904.7 kJ/mol The feed stream enters at 200?C and the products leave at...
-
3. A particle of mass m is moving in the xy-plane such that its velocity at a point (x, y) is given as v = a(yx+2xy), where a is a non-zero constant. What is the force F acting on the particle? (A) F...
-
The proposed rates were not in the range the CEO expected given the pricing analysis. The CEO has asked the pricing actuary to verify the total projected loss cost excluding potential large storm...
-
16. Examine the following t-bill quote. Your pointy haired boss has instructed you to purchase $1 million in these treasury bills. a. b. C. d. Ask Yield Days to Maturity Date Maturity Bid Ask Dec 31...
-
Use your choice of question as the heading for the work. Use the sub-headings below to structure the report for this week and transfer this directly into your final assessment. 2.1 Critical analysis...
-
What are the three primary functions performed by the transaction processing system? The most commonly stated benefits of DDP are cost savings, increased user satisfaction, and improved operational...
-
The unit circle and trig values Tasks: Use "The Unit Circle" to find the exact value of each trigonometric function 1. cos 3 / 4 2. tan 2/3 3. cot /2 4. sec (-/4) 5. tan 5/4 6. csc (-5/6)
-
What do you think that only a small percentage of teachers or schools use experiential learning? What are some of the barriers? If you were a school principal planning to convert your conventional...
-
Perform an external environmental scan and industry environmental analysis on this publicly traded company from the perspective of a business unit. Begin your analysis with the seven segments of the...
-
Original Question Statement: The Covid-19 pandemic has fundamentally changed many traditional ways of doing business. For entrepreneurs, the trends that are emerging from these alterations present...
-
Tarick Toys Company manufactures video game consoles and accounts for product costs using process costing. The following information is available regarding its June inventories. The following...
-
Show the result of inserting keys 1 to 15 in order into a skew heap.
-
Show that if the items are sorted, then a treap can be constructed in linear time, even if the priorities are not sorted.
-
Suppose that binary heaps are represented using explicit links. Consider the problem of merging binary heap lhs with rhs. Assume both heaps are perfect binary trees, containing 2l 1 and 2r 1 nodes,...
-
Macquarie Manufacturing Ltd prepared the following planned production data for the forthcoming year ending 30 June 2019. Required (a) Prepare a table showing the predetermined factory overhead rate...
-
Beautiful Bottles Pty Ltd, bottle manufacturer for the food industry, has just installed a job order costing system. The company uses machine hours to apply its overhead to work in process. On 1 May...
-
Green Consultants Pty Ltd specialise in consulting on landscape design. The company developed a predetermined charge-out rate based on hours for each of its consultants on 1 July 2019 to assign the...
Study smarter with the SolutionInn App