solution4

solution4 - [WPI[cs2223[cs2223...

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

View Full Document Right Arrow Icon
[cs2223] [cs2223 text] [News] [Syllabus] [Exams] [Exam 4] cs2223, D97/98 Exam 4 Solution Question 4.1 The first algorithm makes each dot either black or white with a 50% probability. The average gray level in a picture element is 0.5 and the dots are as uniform as the random generator. This algorithm addressed each locationin the array so the number of operations - calls to rand() , number of accesses to picture[][] , etc are all O( N ) where In the first algorithm, the number of picture elements painted black is about N/ 2 but it can vary because of randomness. The second algorithm picks random locations (one half the number of elements in the array) and puts the black value in them. So, there are exactly N /2 picture elemtens painted black. However, because of the possibility that some locations are written more than once - which doesn't make the picture elements any darker - the actual number of black picture elements - and thus the overall average gray level might be lower than for the first algorithm. Look at a single element. The probability that it gets any one of the hits is: Thus the probability that it doesn't get the hit - and it stays white - is The probability that the picture element stays white after two hits is the square of this: The probability that the picture element is still white after all N /2 hits is The probability that the picture element is black after all N /2 hits is one minus this. This, times the "black" level (1.0) is the average gray level for a picture element. And it is less than 0.5.
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 note was uploaded on 11/10/2009 for the course CS 2223 taught by Professor Ruiz during the Fall '05 term at WPI.

Page1 / 4

solution4 - [WPI[cs2223[cs2223...

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