Midterm1-2010

Midterm1-2010 - CS 140 Midterm 1 - 8 February 2010 Name...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 140 Midterm 1 -- 8 February 2010 Name Perm# Problem 1 [20 points total] In Lake Wobegon, all the women are strong, all the men are good- looking, and all the children are above average. Well, everyone can’t be above average--but here we’ll count how many are. We have n kids and p processors. Each processor starts out with n/p elements of a vector IQ of the n kids’ IQ values. Your goal is to compute the average of all n IQs (that is, their sum divided by n ), and also to figure out how many of the n IQs are larger than average. The results, called averageIQ and numHighIQ , should end up on processor 0. For example, if the entries in IQ[] are 110, 90, 120, and 100, then the averageIQ is 420 / 4 = 105, and the numHighIQ is 2 (since two values, 110 and 120, are larger than average). A sequential algorithm to do this on one processor would be as follows. Note that IQ[] and averageIQ are doubles, not integers. double sum = 0; for (int i = 0; i < n; i++) sum += IQ[i]; double averageIQ = sum / n; int numHighIQ = 0; for (int i = 0; i < n; i++) if (IQ[i] > averageIQ) numHighIQ ++; For this problem only, you don’t have to worry about the efficiency of your code. (1a) [10 points]
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 02/22/2011.

Page1 / 4

Midterm1-2010 - CS 140 Midterm 1 - 8 February 2010 Name...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online