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 MAKESETS and its helper MAKINGSETS. 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. MAKESETS(n, k) MAKINGSETS(n, k, 1, ) MAKINGSETS(n, k, e, s) if k == 0 PRINT(S) else for e = e to n MAKINGSETS(n, k1, e + 1, su{e }) 3a. (5 points.) What will MAKESETS(4, 2) print? Hint: enumerate the calls to MAKINGSETS breadthfirst. 3b. (5 points.) Suppose that / and mare nonnegative integers. What does MAKESETS(/, 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 MAKESETS and its helper MAKINGSETS. 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. MAKESETS(n, k) MAKINGSETS(n, k, 1, ) MAKINGSETS(n, k, e, s) if k == 0 PRINT(S) else for e = e to n MAKINGSETS(n, k1, e + 1, su{e }) 3a. (5 points.) What will MAKESETS(4, 2) print? Hint: enumerate the calls to MAKINGSETS breadthfirst. 3b. (5 points.) Suppose that / and mare nonnegative integers. What does MAKESETS(/, 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: 9780078020520
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....

2. Let f(x) = x3x + 3 on the interval [2, 2]. (a) Find all the critical numbers of f(x).

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 17yearold, if Dell promises to pay for the mobile phone by...

Graph each inequality in Problem y < 5

a. The introduction to this chapter included a table listing the population of the United States from 1950 to 2000. Use Lagrange interpolation to approximate the population in the years 1940, 1975,...

Consider two financial institutions. Each institution employs two loan officers (henceforth: agents), and both institutions have the same objectives: financial selfsustainability and poverty...

For each of the following independent situations, calculate the amount(s) required. Required: 1. At the breakeven point, Jefferson Company sells 115,000 units and has fixed cost of $349,600. The...

Report an Error question 3 of 5 A baseball diamond is square shaped and has 90 feet between each base located at the corners of the square. How far will the catcher at one corner (standing at home...

In 20X0 Haleys Department Store devoted 6,000 square feet to the display and sale of clothing, 1,500 square feet to linens and bedding, and 2,000 square feet to jewelry and cosmetics. The store is...

Intel stock is currently trading at $33, and you think that the price of the stock will go down by Oct 16, 2015. For $3, you can buy a put Intel stock that expires on Oct 16, 2015, and that has an...

What is the PersonnelEquipment Interactions Model?

Identify the performance metrics used in project supply chain management.

What is the System Element Architecture (SEA) Model?

What is the Users Level 0 Enterprise Model?

How are control flow and data flow related?

The unadjusted trial balance for Bramble Corp. is shown below. Bramble Corporation Trial Balance October 31, 2025 Debit Credit Cash $15,540 Supplies 2,570 Prepaid Insurance 690 Equipment 4,690 Notes...

How many years will it take a $700 balance to grow into $900 in an account earning 5%?

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 twobedroom apartments in Albuquerque, New Mexico, during the month of May last year. Electricity Cost Frequency $...

What are the three major activities of a manager?

The President of the ICAEW has proposed that regulators from developed and developing countries start talking to agree a set of principles for universal application that could underpin the regulation...

Describe the four steps in the planning and control cycle.
Study smarter with the SolutionInn App