Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Binary counter Pseudocode Increment( A, k ) i = 0 while i < k and A [ i ] = 1 A [ i ]

Binary counter Pseudocode

Increment(A, k)

i = 0

while i < k and A[i] = 1

A[i] = 0

i = i + 1

if i < k

A[i] = 1

Think back to the binary counter whose subroutine, Increment, counts up from zero. Suppose we want to add a Decrement operation as well. Its pretty clear that allowing both operations slows everything down, even if we amortize. For example, an adversary could alternate between the two operations to end up with values 2k and 2k-1, each of which would flip about k bits.

Instead, we can represent a number as a pair of bit strings <b1, b2>, where for any bit position i,

at most one of the bits b1[i] and b2[i] is equal to 1. The actual value of the counter is b1 - b2. We can design this system such that a worst-case operation takes (lg k) time and the amortized cost of each operation is 4.

Write the two operations: increment and decrement. Both operations should take both b1 and b2 as parameters, and they should maintain the constraint that at most one of the bits b1[i] and b2[i] is equal to 1.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

1. In most ways my life is close to my ideal.

Answered: 1 week ago

Question

12. What is a seasonal index?

Answered: 1 week ago

Question

1.who the father of Ayurveda? 2. Who the father of taxonomy?

Answered: 1 week ago

Question

Commen Name with scientific name Tiger - Wolf- Lion- Cat- Dog-

Answered: 1 week ago