Suppose that [e, e..... e] is a list of k integers. The following table defines some...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Suppose that [e, e..... e] is a list of k integers. The following table defines some operations on such lists. Each operation works in 0(1) time. 07 08 Operation [] [e] 01 MERGE(left, right) 02 both = [] 03 04 05 06 HEAD() TAIL() LENGTH() ler Suppose that I and rare lists of integers. The elements of each list are sorted into nondecreasing order, but you do not know what those elements are. The procedure MERGE(!) returns a new list that has all the elements of I and also sorted into nondecreasing order. else both both left = TAIL(left) while LENGTH(left) > 0 and LENGTH(right) > 0 if HEAD(left) 2. Questions 2a through 2d are about the procedure FACTORIAL, which returns the factorial of the integer n. Assume that n 0. Use a loop invariant to prove that FACTORIAL is correct. FACTORIAL(n) f=1 k=1 while k n f = kx f k = k+1 return f 2a. (5 points.) What is a loop invariant for FACTORIAL? 2b. (5 points.) Use the invariant from 2a to prove that FACTORIAL is correct at initialization. 2c. (5 points.) Use the invariant from 2a to prove that FACTORIAL is correct during maintenance. 2d. (5 points.) Use the invariant from 2a to to prove that FACTORIAL is correct at termination. 3. Questions 3a and 3b are about the backtracking procedure MAKE-SETS and its helper MAKING-SETS. The symbol 'o' is the empty set, and the symbol 'U' is the set union operator. The procedure PRINT(s) prints the set s. The parameters n, k, and e are nonnegative integers. The parameter s is a set of nonnegative integers. MAKE-SETS(n, k) MAKING-SETS(n, k, 1, ) MAKING-SETS(n, k, e, s) if k == 0 PRINT(S) else for e = e to n MAKING-SETS(n, k-1, e + 1, su{e }) 3a. (5 points.) What will MAKE-SETS(4, 2) print? Hint: enumerate the calls to MAKING-SETS breadth-first. 3b. (5 points.) Suppose that / and mare nonnegative integers. What does MAKE-SETS(/, m) compute? Your answer must be one short sentence, stated in terms of /and m. Suppose that [e, e..... e] is a list of k integers. The following table defines some operations on such lists. Each operation works in 0(1) time. 07 08 Operation [] [e] 01 MERGE(left, right) 02 both = [] 03 04 05 06 HEAD() TAIL() LENGTH() ler Suppose that I and rare lists of integers. The elements of each list are sorted into nondecreasing order, but you do not know what those elements are. The procedure MERGE(!) returns a new list that has all the elements of I and also sorted into nondecreasing order. else both both left = TAIL(left) while LENGTH(left) > 0 and LENGTH(right) > 0 if HEAD(left) 2. Questions 2a through 2d are about the procedure FACTORIAL, which returns the factorial of the integer n. Assume that n 0. Use a loop invariant to prove that FACTORIAL is correct. FACTORIAL(n) f=1 k=1 while k n f = kx f k = k+1 return f 2a. (5 points.) What is a loop invariant for FACTORIAL? 2b. (5 points.) Use the invariant from 2a to prove that FACTORIAL is correct at initialization. 2c. (5 points.) Use the invariant from 2a to prove that FACTORIAL is correct during maintenance. 2d. (5 points.) Use the invariant from 2a to to prove that FACTORIAL is correct at termination. 3. Questions 3a and 3b are about the backtracking procedure MAKE-SETS and its helper MAKING-SETS. The symbol 'o' is the empty set, and the symbol 'U' is the set union operator. The procedure PRINT(s) prints the set s. The parameters n, k, and e are nonnegative integers. The parameter s is a set of nonnegative integers. MAKE-SETS(n, k) MAKING-SETS(n, k, 1, ) MAKING-SETS(n, k, e, s) if k == 0 PRINT(S) else for e = e to n MAKING-SETS(n, k-1, e + 1, su{e }) 3a. (5 points.) What will MAKE-SETS(4, 2) print? Hint: enumerate the calls to MAKING-SETS breadth-first. 3b. (5 points.) Suppose that / and mare nonnegative integers. What does MAKE-SETS(/, m) compute? Your answer must be one short sentence, stated in terms of /and m.
Expert Answer:
Answer rating: 100% (QA)
1 The runtime of MERGEleft right is given by M L R where L is the length of the left list and R is t... View the full answer
Related Book For
Statistical Techniques in Business and Economics
ISBN: 978-0078020520
16th edition
Authors: Douglas Lind, William Marchal
Posted Date:
Students also viewed these accounting questions
-
For each transaction, indicate in which journal it should be recorded. Sales Journal Cash Receipts Journal Purchases Journal Cash Payments Journal General Journal Returned products to a supplier....
-
What is a branch delay slot and why does it arise? [7 marks] How can branch delays be avoided? If a processor exhibited one branch delay slot how would you reorder (and possibly modify) the...
-
Leanne buys, refurbishes, and resells used mobile phones. She agrees to give a refurbished mobile phone from the her warehouse to Dell, a 17-year-old, if Dell promises to pay for the mobile phone by...
-
The following information was taken from the accounts and records of the Community Society, a nongovernmental not-for-profit organization. The balances are as of December 31, 2016, unless otherwise...
-
Repeat Example 8.3 under the condition that the rotor speed is 4500 r/min and that a negative voltage of -250 V is used to turn off the phase current.
-
Which of the following represents the 30 largest capitalized public companies in the United States? a. The Dow Jones Industrial Average b. The New York Stock Exchange c. The NASDAQ d. The S&P 500
-
A newly hired staff accountant prepared the pre-audit income statement of Jericho Recreation Incorporated for the year ending December 31, 2008. The following information was obtained by Jericho's...
-
In a wheel of a bike, there are six spokes. If tensile forces in consecutive four spokes are 10N, 14N, 12N, and 5N respectively. Calculate the tensile forces in remaining two spokes. The wheel is in...
-
Using basic accounting principles as a guide, provide arguments to support The IASB approach for reporting R&D costs, and The ASPE approach for reporting R&D costs. In this era of rapidly changing...
-
(b) The company CityNet has several centers (nodes) connected as shown below and the cost of moving data between nodes. Using Dijkstra's algorithm, determine the shortest path, and the least cost, to...
-
A college student is buying a used car for $10,000. The student can either pay in full with cash from savings or finance the car for 60 months at a monthly compounding interest rate of 4.25%, which...
-
The Total Amount Of Money In An Account With P Dollars Invested In It Is Given By The Formula A = P +Prt Wherer Is The Rate Expressed As A Decimal And T Is Time (In Years). If $1670 Is Invested At 3...
-
Explain the credit score requirements for obtaining a mortgage loan from a bank. How does a borrower's credit history and creditworthiness impact the terms and conditions of the loan?
-
Tracy is preparing to apply a patch to her organization's enterprise resource planning system. She is concerned that the patch may introduce flaws that did not exist in prior versions, so she plans...
-
2. Here is a number represented in the IEEE standard single precision format 11010101010101000000000000000000 What is the decimal number represented by this string in the IEEE standard single...
-
Use a double integral to find the area of the cardioid below r = 2 2sin
-
Evaluate the integral, if it exists. Jo y(y + 1) dy
-
Out of 110 diesel engines tested, a rework and repair facility found 9 had leaky water pumps, 15 had faulty cylinders, 4 had ignition problems, 52 had oil leaks, and 30 had cracked blocks. Draw a...
-
The National Highway Association is studying the relationship between the number of bidders on a highway project and the winning (lowest) bid for the project. Of particular interest is whether the...
-
The following frequency distribution reports the electricity cost for a sample of 50 two-bedroom apartments in Albuquerque, New Mexico, during the month of May last year. Electricity Cost Frequency $...
-
Margin of error = 18.2 cm, standard deviation = 95.2 cm
-
Margin of error = 0.5 g, standard deviation = 8.7 g
-
Margin of error = 3.5 ml, standard deviation = 155.2 ml
Study smarter with the SolutionInn App