Discrete Mathematics University of Kentucky CS 275 Spring ... - MGNet
Discrete Mathematics University of Kentucky CS 275 Spring ... - MGNet
Discrete Mathematics University of Kentucky CS 275 Spring ... - MGNet
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Example <strong>of</strong> linear search average complexity: See page 44 in the class notes for<br />
the algorithm and worst case complexity bound. We want to find x in a distinct<br />
!<br />
set " a<br />
# i<br />
n<br />
$<br />
%<br />
&i=1<br />
. If x =<br />
!<br />
ai , then there are 2i+1 comparisons. If x6 " a i<br />
!<br />
2n+2 comparisons. There are n+1 input types: " a i<br />
!<br />
where p is the probability that x, " a<br />
# i<br />
n<br />
$<br />
%<br />
&i=1<br />
n<br />
i=1<br />
#<br />
n<br />
$<br />
%<br />
&i=1<br />
. Let q = 14p. So,<br />
E = (p/n)! (2i-1) + (2n+2)q<br />
= (p/n)((n+1) 2 + (2n+2)q<br />
= p(n+2) + (2n+2)q.<br />
There are three cases <strong>of</strong> interest, namely,<br />
• p = 1, q = 0: E = n + 1<br />
• p = q = 0.5: E = (3n + 4) / 2<br />
• p = 0, q = 1: E = 2n + 2<br />
#<br />
n<br />
$<br />
%<br />
&i=1<br />
, then there are<br />
2x. Clearly, p(ai ) = p/n,<br />
111<br />
Definition: A random variable X has a geometric distribution with parameter p if<br />
p(X=k) = (14p) k-1 p for k = 1, 2, …<br />
Note: Geometric distributions occur in studies about the time required before an<br />
event happens (e.g., time to finding a particular item or a defective item, etc.).<br />
Theorem: If the random variable X has a geometrix distribution with parameter<br />
p, then E(X) = 1/p.<br />
Pro<strong>of</strong>:<br />
E(X) =<br />
!<br />
!<br />
i=1<br />
!<br />
i=1<br />
!<br />
i=1<br />
ip(X=i)<br />
= i(1-p) i-1 p<br />
!<br />
= p i(1-p) i-1<br />
!<br />
= pp -2<br />
= 1/p<br />
112