Recall that a standard queue maintains a sequence of items and supports the following oper- ations: PUSH(x) (add an item z to the end of the sequence), PULL (remove and return the item at the beginning of the sequence), and SıZE (returns the current length of the sequence). Using a doubly- linked list, you can easily implement a queue so that the worst case time for each of these operations is O(1). Suppose we introduce a new operation called HALVE that removes every alternate element from the sequence. It is implemented in the following way. The algorithm maintains a counter variable i, initially set to 0, and another variable n set to the result of SIZE. When i is even, it executes a PULL, discarding the result. When i is odd, it executes a PUSH(PULL()), pulling the front element and pushing it to the back of the queue. In either case, i is incremented by one. The algorithm halts at the end of the n'th iteration (before i equals n). Prove that in any sequence of PUSH, PULL, and HALVE operations, the amortized cost of each operation is O(1). Use the accounting method.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Recall that a standard queue maintains a sequence of items and supports the following oper-
ations: PUSH(x) (add an item r to the end of the sequence), PULL (remove and return the
item at the beginning of the sequence), and SIZE (returns the current length of the sequence).
Using a doubly- linked list, you can easily implement a queue so that the worst case time for
each of these operations is O(1).
Suppose we introduce a new operation called HALVE that removes every alternate element
from the sequence. It is implemented in the following way. The algorithm maintains a counter
variable i, initially set to 0, and another variable n set to the result of SIZE. When i is even,
it executes a PULL, discarding the result. When i is odd, it executes a PUSH(PULL()), pulling
the front element and pushing it to the back of the queue. In either case, i is incremented by
one. The algorithm halts at the end of the n'th iteration (before i equals n).
Prove that in any sequence of PUSH, PULL, and HALVE operations, the amortized cost of
each operation is 0(1). Use the accounting method.
Transcribed Image Text:Recall that a standard queue maintains a sequence of items and supports the following oper- ations: PUSH(x) (add an item r to the end of the sequence), PULL (remove and return the item at the beginning of the sequence), and SIZE (returns the current length of the sequence). Using a doubly- linked list, you can easily implement a queue so that the worst case time for each of these operations is O(1). Suppose we introduce a new operation called HALVE that removes every alternate element from the sequence. It is implemented in the following way. The algorithm maintains a counter variable i, initially set to 0, and another variable n set to the result of SIZE. When i is even, it executes a PULL, discarding the result. When i is odd, it executes a PUSH(PULL()), pulling the front element and pushing it to the back of the queue. In either case, i is incremented by one. The algorithm halts at the end of the n'th iteration (before i equals n). Prove that in any sequence of PUSH, PULL, and HALVE operations, the amortized cost of each operation is 0(1). Use the accounting method.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education