You saw in class that the standard algorithm to INCREMENT a binary counter runs in 0(1)...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
You saw in class that the standard algorithm to INCREMENT a binary counter runs in 0(1) amortized time. Now suppose we also want to support a second function called RESET, which resets all bits in the counter to zero. Here are the INCREMENT and RESET algorithms. In addition to the array B[...] of bits, we now also maintain the index of the most significant bit, in an integer variable msb. INCREMENT(B[0..∞], msb): i-0 while B[i] = 1 B[i] - 0 ii+1 B[i] - 1 if i > msb msb-i RESET(B[0..∞],msb): for i - 0 to msb B[i] - 0 msb-0 In parts (a) and (b), let n denote the number currently stored in the counter. (a) What is the worst-case running time of INCREMENT, as a function of n? (b) What is the worst-case running time of RESET, as a function of n? (c) Prove that in an arbitrary intermixed sequence of INCREMENT and RESET operations, the amortized time for each operation is 0(1). You saw in class that the standard algorithm to INCREMENT a binary counter runs in 0(1) amortized time. Now suppose we also want to support a second function called RESET, which resets all bits in the counter to zero. Here are the INCREMENT and RESET algorithms. In addition to the array B[...] of bits, we now also maintain the index of the most significant bit, in an integer variable msb. INCREMENT(B[0..∞], msb): i-0 while B[i] = 1 B[i] - 0 ii+1 B[i] - 1 if i > msb msb-i RESET(B[0..∞],msb): for i - 0 to msb B[i] - 0 msb-0 In parts (a) and (b), let n denote the number currently stored in the counter. (a) What is the worst-case running time of INCREMENT, as a function of n? (b) What is the worst-case running time of RESET, as a function of n? (c) Prove that in an arbitrary intermixed sequence of INCREMENT and RESET operations, the amortized time for each operation is 0(1). You saw in class that the standard algorithm to INCREMENT a binary counter runs in 0(1) amortized time. Now suppose we also want to support a second function called RESET, which resets all bits in the counter to zero. Here are the INCREMENT and RESET algorithms. In addition to the array B[...] of bits, we now also maintain the index of the most significant bit, in an integer variable msb. INCREMENT(B[0..∞], msb): i-0 while B[i] = 1 B[i] - 0 ii+1 B[i] - 1 if i > msb msb-i RESET(B[0..∞],msb): for i - 0 to msb B[i] - 0 msb-0 In parts (a) and (b), let n denote the number currently stored in the counter. (a) What is the worst-case running time of INCREMENT, as a function of n? (b) What is the worst-case running time of RESET, as a function of n? (c) Prove that in an arbitrary intermixed sequence of INCREMENT and RESET operations, the amortized time for each operation is 0(1).
Expert Answer:
Answer rating: 100% (QA)
Step 1 a The INCREMENT algorithm has a worstcase running time of On where n is the number currently recorded in the counter Explanation If the number ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
What is the cofactor of an entry of a matrix? How are cofactors used to find the determinant of the matrix?
-
Late Bloomer is taking a course in microeconomics. Grading in the course is based on 10 weekly quizzes, each with a 100-point maximum. On the first quiz, Late Bloomer receives a 10. In each...
-
is a debenture, and how does it differ from other types of debt securities? 2. What are the key features of a debenture, such as maturity, interest rate, and repayment terms? 3. How are debentures...
-
On January 7, Red Tucker, Inc., paid $254,700 for equipment used in manufacturing automotive supplies. In addition to the basic purchase price, the company paid $500 transportation charges, $300...
-
The following information for Lesky Corporation covers the year ended December 31, 2010: Required Change this statement to a multiple-step format, as illustrated in this chapter. LESKY CORPORATION...
-
Question 11, 2.5.39-BE > HW Score: 32.24%, 12.25 of 38 points Points: 0 of 1 Find the present value of $5000 payable at the end of 4 years, if money may be invested at 4% with interest compounded...
-
In a survey, adults were asked to answer yes or no to the question Do you regularly watch the evening TV news? Some of the results from the survey are detailed in the Venn diagram opposite. One adult...
-
ANNA Corporation imported goods from the United States. The goods were subjected to customs duties in the amount of P36,000.00 representing 8% of the dutiable value of the goods, excise tax of...
-
Compose three complete & well-written paragraphs using Walmart as an example, 1. Describe what business it is in 2. Describe some of the costs the company incurs. 3. Categorize the costs you...
-
Analysis of non-financial performance. Use annual report(s) and more for research into sector. Demonstrate an in-depth understanding of financial reporting content, context and legislation. Discusses...
-
The widespread unauthorized account activity at Wells Fargo represented acts of noncompliance with laws and regulations (NOCLAR) (i.e., consumer protection laws, banking regulations), which are...
-
A company begins the year with a zero balance in the LIFO Reserve account. Based on an analysis of LIFO and FIFO, the company determines the LIFO Reserve should be $20,000 at the end of the year?...
-
Do you think using communication methods based on information technology (IT) is the best way for a large business to communicate with its suppliers? Justify
-
Kelvin-Planck's law deals with Conservation of energy O conservation of heat O conservation of mass O conversion of work into heat O
-
The MIT Sloan School of Management is one of the leading business schools in the U.S. The following table contains the tuition data for the masters program in the Sloan School of Management. a. Use...
-
The second and third lines from Table H Random Numbers are shown below. Use these numbers to complete the random assignment of 18 subjects to three different experimental treatment conditions: 1, 2,...
-
Indicate whether the following statements indicate a positive or negative relationship. a. Duncan, Hoekstra, and Wilcox (2012) found that college students who used their cell phones more during...
-
Dietz-Uhler and Lanter (2009) devised a four-questions technique to help students understand material presented in an introductory psychology course. At the end of the course, the students completed...
-
Which of the following statements does not prop- erly describe a limitation of an audit? a. Many audit conclusions are made on the basis of examining a sample of evidence.. b. Some evidence...
-
Which of the following types of auditing is per- formed most commonly by CPAs on a contractual basis? a. Internal auditing. b. Government auditing. c. Internal Revenue Service auditing. d. External...
-
Which of the following statements does not de- scribe a condition that creates a demand for auditing? a. Conflict between an information preparer and a user can result in biased information. b....
Study smarter with the SolutionInn App