Introduction to Algorithms
Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
bartleby

Concept explainers

Question
Book Icon
Chapter 17, Problem 1P

(a)

Program Plan Intro

To describe how the function reverses that run in θ(k) time can runs in O(nk) if the length is n=2k .

(a)

Expert Solution
Check Mark

Explanation of Solution

The reverse operation is performed by using two arrays. Consider another array and copy the elements in the reverse order to the new array from the original array. The operation is performed as swapping the values with the same index in the both array.

After swapping the element to current index it required to set the entry in the second array corresponding to the bit-reverses.

Since the swapping of the element time is depends upon the number of element so suppose there are n -elements in the function of k bit reversed algorithm then the running time is equal to the product of n and k .

(b)

Program Plan Intro

To describe an implementation of the BIT-REVERSED-INCREMENT procedure that allows the bit-reversal permutation on an n -element to perform in O(n) time.

(b)

Expert Solution
Check Mark

Explanation of Solution

The pseudo-code of the BIT-REVERSED-INCREMENT implementation is given below:

REVERSED-INCREMENT( a )

Set m=1 followed by k zeroes.

while m bitwise-AND ais not zero do

  a=abitwiseXOR m .

shift m right by 1.

end while.

return m bitwise-OR a.

end

The algorithm swaps the value of binary counter and reversed counter so it updates the values by incrementing the counter variable.

The operation is performed is carried out bit by bit so it consider one bit at the time to compared and reversed the values.

The BIT-REVERSED-INCREMENT operation will take constant amortized time and to perform the bit-reversed permutation requires a normal binary counter and a reversed counter.

(c)

Program Plan Intro

To explain how shifting any word shift left or right by one bit in unit time without changing the run time of the implementation.

(c)

Expert Solution
Check Mark

Explanation of Solution

The procedure uses single shift so the complexity of the procedure is not changed as any words shift left with unit time.

The procedural is based on the number of bit swapped not on the operation therefore any change in the operation such as type of shift does not affect the time complexity of the procedure.

Since, the operation time is depends upon the number of element so the running time is equal to the product of n and k , where n is the size and k is shift bit.

Hence, there is no change in the running time of implementation.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
twosComplementBinaryToDecimal functionThis function takes a static array and bit pattern length as its arguments. The function must return the decimal (integer) value computed from the two's complement binary representation given in the array argument in the given bit pattern length. Assume the array is populated with binary bits in the given bit pattern length and that it is a two's complement representation.
7
Write a function in C swapRows(): which takes two 4x4 array as an argument and swap the values of its even rows with odd rows .   Expected input: 5 2 3 1 4 8 9 0 -1 3 8 -2 99 102 33 56   Expected Output: 4 8 9 0 5 2 3 1 99 102 33 56 -1 3 8 -2
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education