Concept explainers
(a)
To reword the parallel loop in SUM-ARRAYS utilizing nested within the manner of MAT-VEC-MAIN-LOOP.
(a)
Explanation of Solution
The implementation of the parallel loop that contains a worth grain-size to be specified is as follows:
SUM − ARRAYS’ (A, B, C)
Grain − Size
Sync
ADD − SUBARRAY (A, B, C, i, j)
Observing the
(b)
To calculate the parallelism of the given implementation if we set grain-size=1.
(b)
Explanation of Solution
It can be concluded that each call to
SUM − ARRAYS’ (A, B, C)
(c)
To formulate the span of SUM-ARRAYS’ in terms of
(c)
Explanation of Solution
Assume g be the grain-size. The runtime of the function is
To get this we will perform calculus and get a derivative, we have
To further solve this, we set
Want to see more full solutions like this?
Chapter 27 Solutions
Introduction to Algorithms
- Suppose that two matrices A and B with dimension n x n are stored on a 2D mesh of n2 processors such that P_(i,j) holds A[I,j] and B[j,i] . Write C-style pseudocode for an asynchronous algorithm that computes the product of A and B in O(n) time. (10 points) (WRITE THE PSEUDOCODE! IF YOU DON'T WRITE PSEUDOCODE, YOU WILL BE WRONG!! C-STYLE ONLY!!!)arrow_forwardConsider the following multithreaded algorithm for performing pairwise multiplication on n-element arrays A[1..n] and B[1..n], storing the multiplications in C[1..n]:Analyze the work, span and parallelism of this algorithm.arrow_forwardSuppose that two n x n matrices A and B are stored on a mesh of n2 processors such that Pi;j holds A[i; j] and B[j; i]. Write pseudocode for an asynchronous algorithm that computes the product of A and B in O(n).arrow_forward
- Write a technique to locate the indices m and n in an array of integers such that sorting items m through n will sort the entire array. Find the smallest such sequence by minimising n - m. Example inputs: 1, 2, 4, 7, 10, 11, 7, 12, 6, 7, 16, and 19; outputs: 3 and 9.arrow_forwardSuppose we are comparing implementations of insertion sort and merge sort on the same machine. For inputs of size n, insertion sort runs in 8n2 steps, while merge sort runs in 32nlogn steps. For which values of n does insertion sort beat merge sort? Group of answer choices: 1. n < 1024 2. n > 1024 3. n < 16 4. n > 16 5. Merge sort is always better since O(nlogn) is better than O(n^2)arrow_forwardFor this given code, please help me create a recursive case for transpose of matrix using the cache oblivious algorithm. for ( size_t i=0; i<n; i += block ) { for ( size_t j=0; j<n; j++ ) { for ( size_t b = 0; b < block && i + b < n; ++b){ b[ j*n + i ] = a[ i*n + j ]; } } else { recursMatTranspose ( n, n, a, 0, 0, b, 0, 0 ); //recursive case using cache-oblivious algo } }arrow_forward
- Describe an efecient in-place algorithm called Partition-Even-Odd(A) that partitions an array A in even and odd numbers. The algorithm must terminate with A containing all its even elements preceding all its odd elements. For example, for input A = [7, 17, 74, 21, 7, 9, 26, 10], the result might be A = [74, 10, 26, 17, 7, 21, 9, 7]. Partition-Even-Odd must be an in-place algorithm. What does this mean about your algorithm? (a) Write the pseudo-code for Partition-Even-Odd. (b) Characterize the complexity of Partition-Even-Odd. Brie y justify your answer. (c) Formalize the correctness of the partition problem as stated above, and prove that Partition-Even- Odd is correct using a loop-invariant.arrow_forwardGiven two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example 1: Input: nums1 = [1,3], nums2 = [2] Output: 2.00000 Explanation: merged array = [1,2,3] and median is 2. Example 2: Input: nums1 = [1,2], nums2 = [3,4] Output: 2.50000 Explanation: merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5. Constraints: nums1.length == m nums2.length == n 0 <= m <= 1000 0 <= n <= 1000 1 <= m + n <= 2000 -106 <= nums1[i], nums2[i] <= 106 Write the whole code in python language Attach the code outputs also and explain the implementation.arrow_forwardGiven two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example 1: Input: nums1 = [1,3], nums2 = [2] Output: 2.00000 Explanation: merged array = [1,2,3] and median is 2. Example 2: Input: nums1 = [1,2], nums2 = [3,4] Output: 2.50000 Explanation: merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5. Constraints: nums1.length == m nums2.length == n 0 <= m <= 1000 0 <= n <= 1000 1 <= m + n <= 2000 -106 <= nums1[i], nums2[i] <= 106arrow_forward
- Workout (a) parallel shell sort using 4 processors (use odd-even transposition sort for eventual sorting)and (b) prefix sum on a hypercube with 8 processors on the following input12 8 12 6 9 2 25 9arrow_forwardFor sorting a set of items, we can employ one of these famous algorithms, merge-sort, heapsort, quicksort, and shell-sort. We can program in both Java and Python, and we have the choice of using three different computers with different instruction set architectures: x86, ARM, and MIPs. Regarding microarchitecture, for x86 we have two choices, and for ARM and MIPS we have three choices for each of them. How many choices we have to run a sort algorithm? (Draw diagram).arrow_forwardFor the program below, calculate its worst-case complexity as a function of the size n of the input array A. Explain your answer by giving a detailed calculation.def initialCommon (A,B): # initial common component of A, B for i in range (len(A) ,-1,-1): same = True for j in range (i): if A[j] != B[j]: same = False if same : return [A[j] for j in range (i)]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