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
1. Consider a problem of computing the prefix average of a sequence of numbers stored in an array P consisting of P integers. We want to compute an array P such that P is the average of P for P . Consider the two algorithms related to the above problem. Answer the questions given below
The MPI program 'Standard-Deviation.c' computes the standard deviation for an array of elements.Here, we assume that the maximum number of elements in the array is 10. Some necessary error checkings are performed to ensure that the number of inputs is correct and their values are valid.    (a) mpiexec -n 2 ./Stddev   (b) mpiexec -n 2 ./Stddev 0   (c) mpiexec -n 3 ./Stddev 7                        (d) mpiexec -n 3 ./Stddev 9         (e) mpiexec -n 4 ./Stddev 21   Standard-Deviation.c. This code is giving me an error when I compile /////////////////////////////////////////////////////////////////////////////////////////// This is an MPI program that computes the standard deviation for an array of elements.//// Note: The array is generated according to its size (the number of elements), which //       is specified by users from the command line. In the program, we assume its //       maximum number is 10.//// Compile:  mpicc Standard-Deviation.c -o  Stddev -lm// // Run:      mpiexec -n…
1.By own answer in short time.   an array of integers, every element appearsthree times except for one, which appears exactly once.Find that single one. Note:Your algorithm should have a linear runtime complexity.Could you implement it without using extra memory? Solution:32 bits for each integer.Consider 1 bit in it, the sum of each integer's corresponding bit(except for the single number)should be 0 if mod by 3. Hence, we sum the bits of allintegers and mod by 3,the remaining should be the exact bit of the single number.In this way, you get the 32 bits of the single number.""" # Another awesome answerdef single_number2(nums):    ones, twos = 0, 0    for i in range(len(nums)):        ones = (ones ^ nums[i]) & ~twos. Toko-.
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