161202-ForkJoinParallelism.pdf

# Find the maximum or minimum element of an array given

• Notes
• 34

This preview shows pages 21–24. Sign up to view the full content.

• Find the maximum or minimum element of an array. • Given an array of strings, compute the sum (or max, or min) of all their lengths. • Find the left-most array index that has an element satisfying some property. Compared to summing an array, all that changes is the base case for the recursion and how we combine results. For example, to find the index of the leftmost 42 in an array of length n , we can do the following (where a final result of n means the array does not hold a 42): • For the base case, return lo if arr[lo] holds 42 and n otherwise. • To combine results, return the smaller number. CPEN 221 – Fall 2016

This preview has intentionally blurred sections. Sign up to view the full version.

Fork-Join Parallelism 23 Because reductions using associative operators are so common, we could write one generic algorithm that took the operator, and what to do for a base case, as arguments.

This preview has intentionally blurred sections. Sign up to view the full version.

This is the end of the preview. Sign up to access the rest of the document.
• Fall '17
• satish
• fork-join parallelism, SumThread

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern