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.

Sec. 15.2 Lower Bounds on Searching Lists 489Here is our first <strong>at</strong>tempt <strong>at</strong> proving the theorem.Proof 1: We will try a proof by contradiction. Assume an algorithm A exists th<strong>at</strong>requires only n − 1 (or less) comparisons of K with elements of L. Because thereare n elements of L, A must have avoided comparing K with L[i] for some valuei. We can feed the algorithm an input with K in position i. Such an input is legal inour model, so the algorithm is incorrect.✷Is this proof correct? Unfortun<strong>at</strong>ely no. First of all, any given algorithm neednot necessarily consistently skip any given position i in its n − 1 searches. Forexample, it is not necessary th<strong>at</strong> all algorithms search the list from left to right. Itis not even necessary th<strong>at</strong> all algorithms search the same n − 1 positions first eachtime through the list.We can try to dress up the proof as follows: Proof 2: On any given run of thealgorithm, if n − 1 elements are compared against K, then some element position(call it position i) gets skipped. It is possible th<strong>at</strong> K is in position i <strong>at</strong> th<strong>at</strong> time, <strong>and</strong>will not be found. Therefore, n comparisons are required.✷Unfortun<strong>at</strong>ely, there is another error th<strong>at</strong> needs to be fixed. It is not true th<strong>at</strong>all algorithms for solving the problem must work by comparing elements of Lagainst K. An algorithm might make useful progress by comparing elements of Lagainst each other. For example, if we compare two elements of L, then comparethe gre<strong>at</strong>er against K <strong>and</strong> find th<strong>at</strong> this element is less than K, we know th<strong>at</strong> theother element is also less than K. It seems intuitively obvious th<strong>at</strong> such comparisonswon’t actually lead to a faster algorithm, but how do we know for sure? Wesomehow need to generalize the proof to account for this approach.We will now present a useful abstraction for expressing the st<strong>at</strong>e of knowledgefor the value rel<strong>at</strong>ionships among a set of objects. A total order defines rel<strong>at</strong>ionshipswithin a collection of objects such th<strong>at</strong> for every pair of objects, one is gre<strong>at</strong>erthan the other. A partially ordered set or poset is a set on which only a partialorder is defined. Th<strong>at</strong> is, there can be pairs of elements for which we cannot decidewhich is “gre<strong>at</strong>er”. For our purpose here, the partial order is the st<strong>at</strong>e of ourcurrent knowledge about the objects, such th<strong>at</strong> zero or more of the order rel<strong>at</strong>ionsbetween pairs of elements are known. We can represent this knowledge by drawingdirected acyclic graphs (DAGs) showing the known rel<strong>at</strong>ionships, as illustr<strong>at</strong>ed byFigure 15.1.Proof 3: Initially, we know nothing about the rel<strong>at</strong>ive order of the elements in L,or their rel<strong>at</strong>ionship to K. So initially, we can view the n elements in L as being inn separ<strong>at</strong>e partial orders. Any comparison between two elements in L can affectthe structure of the partial orders. This is somewh<strong>at</strong> similar to the UNION/FINDalgorithm implemented using parent pointer trees, described in Section 6.2.Now, every comparison between elements in L can <strong>at</strong> best combine two of thepartial orders together. Any comparison between K <strong>and</strong> an element, say A, in L can<strong>at</strong> best elimin<strong>at</strong>e the partial order th<strong>at</strong> contains A. Thus, if we spend m comparisons

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

Saved successfully!

Ooh no, something went wrong!