Concept explainers
(a)
To describe how the function reverses that run in
(a)
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
(b)
To describe an implementation of the BIT-REVERSED-INCREMENT procedure that allows the bit-reversal permutation on an n -element to perform in
(b)
Explanation of Solution
The pseudo-code of the BIT-REVERSED-INCREMENT implementation is given below:
REVERSED-INCREMENT( a )
Set
while m bitwise-AND
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)
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)
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?
- Bitwise swaps Protiem Code ITWAPS Given an array A consisting of N integers A1, A2,..., AN, determine if you can sort this array by applying the following operation several times (possibly, zero): • Pick a pair of indices (i, j) with i jand A, & A, # 0, and swap the values of A, and Aj. Here, & denotes the bitwise AND operation For example, if A = [6, 4, 2], the two possible operations are (1,2) and (1, 3). (2, 3) cannot be performed because A2 & Az = 4 & 2 = 0. Input Format • The first line of input contains a single integer T, denoting the number of test cases, The description of T test cases follows. • The first line of each test case contains a single integer N. • The second line contains N space-separated integers A1, A2,..., AN Output Format For each test case, output the answer on a new line - YES if the given array can be sorted by repeatedly applying the given operation, and NO otherwise. You may print each character of the answer string in either uppercase or lowercase (for…arrow_forwardConsider the following functions which both take as arguments three n-element arrays A, B, and C: СОMPARE-1(A, В, С) For i =1 to n For j= 1 to n If A(i] + C[i] > B[j] Return FALSE Return TRUE СOMPARE-2(A, В, С) aux := A[1] + C[1] For i = 2 to n If A[i] + C[i] > aux Then aux := A[i] + C[i] For j = 1 to n If aux > B[j] Return FALSE Return TRUE (a) When do these two functions return TRUE? (b) What is the worst-case running time for each function?arrow_forwardPseudo code for a radix 4 DIF FFT on the array a[], the data length n must be a power of 2, is must be +1 or -1:arrow_forward
- Using Java Modify the program 1 to compute the multiplication of two vectors with the sizes mx1 and 1xn. The result is a matrix mxn computed as follows: the element on the position r and c in the product will be equal with m1[r][0]*m2[0][c].arrow_forwardWhat are the space requirements of an array of n integers assuming each requires c bytes?arrow_forwardWrite a code segment to add two matrices A and B, and store the results in matrix C. C = A+B, that is C[i][j] A[i][j] + B[i][j] The dimensions of both A and B are MxN. Both M and N are defined as constant (final) positive integers, and data types of both matrices are double as shown in the following code segment. double [] [] A = double [][] B = new double [M] [N]; new double [M] [N]; V/ code initialize both A and B /* insert your code here (you need to both define C and perform the sum that populates the values of C) */ ...arrow_forward
- Transcribed Image Text DNA is sequence of bases A, G, T, C. Let DNA [ab] be the subsequence of DNA starting from index a finishing in b inclusive, and DNA[a.] be the subsequence of DNA starting from index a to the end. We could perform the following ops on DNAS: cross operation - they take DNA1 and DNA2 and numbers kl and k2. Then two new DNAS are created: DNA3 = DNA1[1,,k1]+DNA2[k2+1.] and DNA4 = DNA2[1.k2]+DNA1[k1+1.].mutate operation - they take a DNA, number k and one of the bases. Then they replace the base in position k in DNA with that base. also, they need to know certain characteristics of those DNAS. So, they can perform count operation - they take DNA and numbers k1 and k2 (k1 <= k2). This operation should return the number of A, G, T, C bases in DNA[k1,,k2].The initial DNAS are numbered from 1 to n, where n is the amount of those DNAS. The new DNAS the first line of input file contains number n - the number of initial DNAS. Each of the following n lines containsarrow_forwardDefine a function called bell which takes a non-negative integer n and returns the number of partitions of a set of n elements. For example: Test Result print(bell(0)) 1 print(bell(1)) 1 print(bell(2)) 2arrow_forwardComputer Science Written in C, if I have a global 2d array [256][10] and it is already filled with 0's & 1's, write in C to show how I would use bitwise operators to write them to a file to make the file compressedarrow_forward
- Python Numpy function to complete: def t19(N, s, X, y): Inputs: N: An integer s: A floating-point number - x: A floating-point number - y: A floating-point number Returns: A numpy array I of shape (N, N) such that I[i, j] exp(-||(j, i) –- (x, y)||^2 / s^2) Par: 3 lines Instructor: 2 lines return Nonearrow_forwardusing matlab. Solve the question quicklyarrow_forwardPseudo Code shown in Figure Q2(c)(i) is an algorithm for binary searching for an array with n number of elements. By applying this algorithm, show step by step approach on how to find number 11 in an array as shown in Figure Q2(c)(ii). low + 0 high + n-1 while (low S high) do ix + (low + high)/2 if (t = A[ix]) then return ix else if (t < A[ix]) then high e ix - 1 else low + ix + 1 return -1 Figure Q2(c)(i) 9 | 10 | 11 | 12 [2] [3] [4] [5] [6] [7] 1 13 | 19 | 33| 45 55 [0] [1] [8] [9] Figure Q2(c)(ii)arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education