11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

306 Chap. 9 SearchingWe now show th<strong>at</strong> this is the same as√ n∑P(need <strong>at</strong> least i probes)i=1= 1 + (1 − P 1 ) + (1 − P 1 − P 2 ) + · · · + P √ n= (P 1 + ... + P √ n) + (P 2 + ... + P √ n) +(P 3 + ... + P √ n) + · · ·= 1P 1 + 2P 2 + 3P 3 + · · · + √ nP √ nWe require <strong>at</strong> least two probes to set the bounds, so the cost is√ n∑2 + P(need <strong>at</strong> least i probes).i=3We now make take advantage of a useful fact known as Čebyšev’s Inequality.Čebyšev’s inequality st<strong>at</strong>es th<strong>at</strong> P(need exactly i probes), or P i , isP i ≤p(1 − p)n(i − 2) 2 n ≤ 14(i − 2) 2because p(1 − p) ≤ 1/4 for any probability p. This assumes uniformly distributedd<strong>at</strong>a. Thus, the expected number of probes is√ n∑ 12 +4(i − 2) 2 < 2 + 1 4i=3∞∑i=11i 2 = 2 + 1 π4 6 ≈ 2.4112Is QBS better than binary search? Theoretically yes, because O(log log n)grows slower than O(log n). However, we have a situ<strong>at</strong>ion here which illustr<strong>at</strong>esthe limits to the model of asymptotic complexity in some practical situ<strong>at</strong>ions. Yes,c 1 log n does grow faster than c 2 log log n. In fact, it is exponentially faster! Buteven so, for practical input sizes, the absolute cost difference is fairly small. Thus,the constant factors might play a role. First we compare lg lg n to lg n.Factorn lg n lg lg n Difference16 4 2 2256 8 3 2.72 16 16 4 42 32 32 5 6.4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!