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 27, Problem 1P

(a)

Program Plan Intro

To reword the parallel loop in SUM-ARRAYS utilizing nested within the manner of MAT-VEC-MAIN-LOOP.

(a)

Expert Solution
Check Mark

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)

  n=A.length

Grain − Size =?// to be calculated

  r=ceil(n/grainsize)fork=0tor1spawnADDSUBARRAY(A,B,C,k*grainsize+1,min((k+1)*grainsize,n))

Sync

ADD − SUBARRAY (A, B, C, i, j)

  fork=itojC[k]=A[k]+B[k]

Observing the algorithm SUM-ARRAYS (A, B, C) the parallelism is O(n) since it’s work is nlgn and the therefore the span is lgn .

(b)

Program Plan Intro

To calculate the parallelism of the given implementation if we set grain-size=1.

(b)

Expert Solution
Check Mark

Explanation of Solution

It can be concluded that each call to ADDSUBARRAY will return a sum of pair of numbers if the grain size = 1.

SUM − ARRAYS’ (A, B, C)

  n=floor(A.length/2)ifn==0C[1]=A[1]+B[1]elsespawnSUMARRAYS(A[1..n],B[1..n],C[1..n])SUMARRAYS(A[n+1..A.length],B[n+1..A..length],C[n+1..A.length])

(c)

Program Plan Intro

To formulate the span of SUM-ARRAYS’ in terms of n and grain-size and derived the most effective value worth for grain-size to maximize parallelism.

(c)

Expert Solution
Check Mark

Explanation of Solution

Assume g be the grain-size. The runtime of the function is ng . The runtime of any spawned task is g. So, we'd like to attenuate

  ng+g .

To get this we will perform calculus and get a derivative, we have

  0=1ng2 .

To further solve this, we set g=n . This minimizes the amount and makes the span O(ng+g)=O(n) and hence resulting in parallelism of O(n) .

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
) Consider an n x n array ARR stored in memory consisting of 0’s and 1’s such that, in a row of ARR, all 0’s comes before any of 1’s in the row. Write an algorithm having complexity O(n), if exists, that finds the row that contains the most 0’s. Step by step explain r algorithm with an illustrative example. 6
using c++ . Consider an unsorted array with N number of elements and given number k value in range from 1 to N; we have to find the kth largest element in the best possible way which take time complexity O(n)Example:Input:K = 3 A[] = {14, 5, 6, 12, 14, 8, 10, 6, 25} Output: Kth largest element = 12 Input:K = 5 A[] = {18, 15, 3, 1, 2, 6, 2, 18, 16} Output: Kth largest element = 3
Consider a hybrid sorting algorithm that combines Mergesort with Insertion Sort.It uses Mergesort until the number of elements in the input becomes smaller than or equal to 8, after which it switches to Insertion Sort. What is the number of key comparisons performed by this hybrid sorting algorithm in the best case when running on an input array of size n? Briefly justify your answer. You could assume n = 2k, k is more than 3
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