4. (16 points) Consider the following algorithm: int doSomethingToANumber(int a) { int t = 0; for...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
4. (16 points) Consider the following algorithm: int doSomethingToANumber(int a) { int t = 0; for (int i=0; i<a; i++) { for (int j-i; j<a; j++) { t = t + j - i; } } return t; } What will it return for input 4? Correct answers will receive full credit, but show as much work as you can tracing through the algorithm for partial credit for incorrect answers. 4. (16 points) Consider the following algorithm: int doSomethingToANumber(int a) { int t = 0; for (int i=0; i<a; i++) { for (int j-i; j<a; j++) { t = t + j - i; } } return t; } What will it return for input 4? Correct answers will receive full credit, but show as much work as you can tracing through the algorithm for partial credit for incorrect answers.
Expert Answer:
Answer rating: 100% (QA)
The outer for loop will run from i 0 to 3 since a 4 The inner for loop will run from j i to 3 ... View the full answer
Related Book For
Discrete and Combinatorial Mathematics An Applied Introduction
ISBN: 978-0201726343
5th edition
Authors: Ralph P. Grimaldi
Posted Date:
Students also viewed these accounting questions
-
Consider the following algorithm where the input is a rooted tree with root r. Step 1: Push r onto the (empty) stack Step 2: While the stack is not empty Pop the vertex at the top of the stack and...
-
Consider the following algorithm where the input is a rooted tree with root r. Step 1: Push r onto the (empty) stack Step 2: While the stack is not empty If the entry at the top of the stack is not...
-
Consider the following algorithm to sort the entries in a stack S1. First create two empty stacks, S2 and S3. Move the top of S1 to S2. Now, at any given time, stack S2 holds the entries in sorted...
-
On December 1, 2011, Lavender Manufacturing Company (a corporation) purchased another company's assets, including a patent. The patent was used in Lavender's manufacturing operations; $49,500 was...
-
Create a set of use cases for the following system: A Video Store (AVS) runs a series of fairly standard video stores. Before a video can be put on the shelf, it must be catalogued and entered into...
-
1. Is S a subset of T? Let U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} S = {x U: x divides 12 evenly} T = {x U: x is a multiple of 2}. 2. Prove that S is a subset of T, where U = {1, 2, 3, 4, 5, 6,...
-
How many accounts are involved in recording the sale of merchandise on credit?
-
Identifying long-term operational assets Required Which of the following items should be classified as long-term operational assets? a. Prepaid insurance b. Coal mine c. Office equipment d. Notes...
-
Based on the scenario only, how can social factors influence health and safety priorities in Bricks to Homes?
-
Michael and Jeanette Boyds Tax Return Michael D. and Jeanette S. Boyd live with their family at the Rock Glen House Bed & Breakfast, which Michael operates. The Bed & Breakfast (B&B) is...
-
S2/2003 Ltd produces two products, DA and DB in batches on the same production line. DA and DB are both machine oriented in their production process. Details for one unit of each product are: Direct...
-
What do you understand by the term currency in circulation? How is different from vault cash? Explain the relationship between vault cash and bank reserves.
-
An article in the Economist magazine remarks that the average hedge fund is unlikely to earn more than the average mutual fund, and since their fees are higher, the result will be disappointing...
-
An article in the Wall Street Journal titled Why the Feds Balance Sheet Is Shrinking, observed that: As people pay back their mortgages . . .the Feds holdings of mortgage backed securities shrink...
-
How does the Fed change the monetary base of the financial system through the use of open market operations? Where are these operations carried out and which securities are involved in these...
-
An article on the stock market observes: To protect profits, investors can buy put options, which act as insurance, while investors who want to add exposure to the market can buy call options. a. How...
-
A Map is a type of collection that associates a key with a value. The mapping of keys to values can be accomplished using different underlying data structures. In this three-part assignment, you will...
-
A consultant is beginning work on three projects. The expected profits from these projects are $50,000, $72,000, and $40,000. The associated standard deviations are $10,000, $12,000, and $9,000....
-
In defining the notion of independence for three events we found (in Definition 3.13) that we had to check four conditions. If there are four events, say E1, E2, E3, E4, then we have to check 11...
-
Prove Theorem 12.6 and Corollary 12.1. Theorem 12.6 Let T = (V, E) be a complete m-ary tree with |V| = n. If T has i leaves and i internal vertices, then (a) n = mi + 1; (b) = (m - 1)i + 1; and (c)...
-
Simplify the following Boolean expressions. (a) xy + (x + y) + y (c) yz + wx + z + [wz(xy + wz)] x y+ y +z)
-
Eastern Bank serves both university students and regular customers. For university students, the bank charges \($0.10\) per withdrawal. Regular customers get free withdrawal services. The bank earns...
-
After an extensive cost-benefit analysis, Mercy General Hospital has made a decision to outsource its ambulance operations to a private company. The administration has narrowed down its decision to...
-
The Peter Paint Company makes water- and oil-based paints for houses. Recently, the firm has been investigating other opportunities. One possibility is producing finger paints for children. Finger...
Study smarter with the SolutionInn App