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
-
When conducting exercises, you should: A. Complete a full-scale exercises to test multiagency coordination before determining the objective of a tabletop exercise. B. Vary the conditions (e.g., time...
-
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...
-
The balance sheet for Plasma Screens Corporation along with additional information is provided below: Additional Information for 2012: 1. Net income is $69,000. 2. The company purchases $120,000 in...
-
Using the data in Q15, what are (a) the total cost of work in process and (b) the cost of goods manufactured? Data from in Q15 Jam Manufacturing Inc. has beginning work in process \($27,200\), direct...
-
Using Return Distributions suppose the returns on long-term corporate bonds are normally distributed. Based on the historical record, what is the approximate probability that your return on these...
-
Sketch the region enclosed by y = e3, y=e6, and x = 1. Find the area of the region.
-
A closed surface with dimensions a = b = 0.400 m and c = 0.600 m is located as in Figure P24.66. The left edge of the closed surface is located at position x = a. The electric field throughout the...
-
The probability that a student attends tutoring during a semester is 0.12, the probability a student passes their classes in a semester is is 0.71 and the probability a person attends tutoring and...
-
Betty, who just turned 17 today, receives an inheritance of $A. She will receive $5000 every 6 months for 10 years, starting the day she turns 25. If j2 = 8%, what is A?
-
A certain signal molecule S In brain tissue is degraded by two different biochemical pathways: when only Path 1 is active, the half-life of S is 15. s. When only Path 2 is active, the half-life of S...
-
firm a is acquiring firm b by exchanging 25,000 of its shares for all the shares in firm b. the total earnings, shares outstanding, and price per share for the two firms are presented in the...
-
Based on the current economy and your thoughts about the future economy, does the NVIDA beta make you want to invest in it? Why or why not?
-
What is the difference in total payments for a loan of $35,000 which is paid over 5 years with equal total payments, compared to a loan of $35,000 which is paid back in equal total payments starting...
-
Discuss advantages and disadvantages of cash settlement vsphysical settlement in futures markets. 2 answers
-
TRUE OR FALSE: 1. Banks with a significantly large share of fixed-interest rate home loans are less exposed to interest rate risks. 2. Although Australian banks are pretty big, they are not...
-
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,...
-
Using ficts in this chapter for Instruments du Rhone, assume the exchange rate on January 2. 2002, in Fxhibit 8.4 is \(\$ 0.9918\) / rather than \(\$ 1.0000\) / Recalculate Instruments du Rhone's...
-
Exhibits 8.7 and 8.8 in this chapter combine to create the consolidated balance sheet for Jefferson Controls, Inc. Instead of the rates used in the chapter, assume current rates are as reflected in...
-
Gwynn & Co. is a small firm of chartered accountants in Cardiff. The audit partner has been asked to make a proposal to Alhambra Bingo Clubs (ABC), a Cardiff-based company, which wants to change from...
Study smarter with the SolutionInn App