F. Consider the code segment in Listing 5. 1 2 3 4 5 Listing 5: Code...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
F. Consider the code segment in Listing 5. 1 2 3 4 5 Listing 5: Code Segment int i = 2; System.out.printf ("(%d ", i); for (i = 4; i <10; i++) { } if (i % 2 == 0) System.out.printf (" ,%d",i); System.out.println("}"); (a) How many iterations will this code segment make? (b) How many comparisons are made during the execution of this code segment? [3 points] (c) What would the code segment output? [5 points] (d) Rewrite the for-loop in the code segment without the use of the if- statement so that the output remains the same? [5 points] (e) How many iterations will the revised version of the code segment make? [2 points] (f) How many comparisons will the revised version of the code segment make? [3 points] (g) Is the revised version more efficient than the original? Why or why not? [5 points] F. Consider the code segment in Listing 5. 1 2 3 4 5 Listing 5: Code Segment int i = 2; System.out.printf ("(%d ", i); for (i = 4; i <10; i++) { } if (i % 2 == 0) System.out.printf (" ,%d",i); System.out.println("}"); (a) How many iterations will this code segment make? (b) How many comparisons are made during the execution of this code segment? [3 points] (c) What would the code segment output? [5 points] (d) Rewrite the for-loop in the code segment without the use of the if- statement so that the output remains the same? [5 points] (e) How many iterations will the revised version of the code segment make? [2 points] (f) How many comparisons will the revised version of the code segment make? [3 points] (g) Is the revised version more efficient than the original? Why or why not? [5 points]
Expert Answer:
Related Book For
Computer Systems A Programmers Perspective
ISBN: 9781292101767
3rd Global Edition
Authors: Randal E. Bryant, David R. O'Hallaron
Posted Date:
Students also viewed these programming questions
-
answer all questions as instructed below. attend all questions. 4 Computer Vision (a) Explain why such a tiny number of 2D Gabor wavelets as shown in this sequence are so efficient at representing...
-
Write an alternative definition that is tail-recursive (iterative) and makes use of accumulator variables. [10 marks] Explain why your alternative definition executes more efficiently. [3 marks] 1...
-
Do economists have any particular expertise at making normative arguments? In other words, they have expertise at making positive statements (i.e., what will happen) about some economic policy, for...
-
A card is drawn at random from a deck of 52 playing cards. Find the probability that it is a club or a king.
-
Find the force of attraction between two magnetic dipoles, m1 and m2, oriented as shown in Fig. 6.7, a distance r apart, (a) Using Eq. 6.2, and (b) Using Eq.6.3. m r m
-
Two rectangular plates of sizes \(L\) and \(W\) are facing each other and separated by a distance \(H\). Derive an expression for the view factor between these disks. Find the limit if \(W\) is...
-
The bank reconciliation prepared by Winfield Construction on June 30, 2020, appeared as follows: The Cash account in the general ledger appeared as follows on July 31: A list of deposits made and...
-
3. (2 points) A binary tree data structure can be implemented as: template class Node { T key; Node *left; Node "right; }; template class Tree ( Node "root; }; 8 3 (10) 1 6 (14) 7 (13) Write a...
-
What is activity-based costing, and what are its potential benefits?
-
a) Let A = {2,3,4,6,10, 12,16} and B = {2,4,8,16,25}. Draw the Hasse diagrams for the following posets: i. (A, |). ii. (B. I). b) Show that each of the below rule is not a function with the given...
-
Thinking about the organization you work for, or an organization you are familiar with, what (if anything) has it done/is it doing to reduce its direct or indirect emissions of green house gases?
-
What might be the key barriers to green finance becoming more widespread?
-
Which of the SDGs are most relevant, in your view, for the finance sector?
-
What might be the impact of these observed and projected future changes on the city/country/region where you live and work?
-
Who are the key stakeholders for your organization? Be as specific as possible.
-
Ngata Ltd. insured under a loss of profits policy of Sh.16,000,000. The companys premises were partly destroyed by fire which took place on 1 May 2018 and the business resumed normal operations on 1...
-
5. Convert the following ERD to a relational model. SEATING RTABLE Seating ID Nbr of Guests Start TimeDate End TimeDate RTable Nbr RTable Nbr of Seats RTable Rating Uses EMPLOYEE Employee ID Emp...
-
Given the assumptions of Practice Problem 6.18, determine the cache performance of the following code: A. What is the total number of reads? B. What is the total number of reads that hit in the...
-
The disassembled code for two functions first and last is shown below, along with the code for a call of first by function main: Each of these instructions is given a label, similar to those in...
-
Consider the following code, in which we have omitted the expression being computed: short arith3 (short x, short y, short z) { } short p1. short p2 short p3 = short p4 = return p4; The portion of...
-
Why should projects be linked to the organisation's Strategic Plan?
-
What is the BCG matrix and how is it used?
-
Explain the role projects play in the delivery of an organisation's strategy
Study smarter with the SolutionInn App