12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

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

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

512 Chap. 15 Lower BoundsABCGDEFFigure 15.1 Illustration of using a poset <strong>to</strong> model our current knowledge of therelationships among a collection of objects. A directed acyclic graph (DAG) isused <strong>to</strong> draw the poset (assume all edges are directed downward). In this example,our knowledge is such that we don’t know how A or B relate <strong>to</strong> any of the otherobjects. However, we know that both C <strong>and</strong> G are greater than E <strong>and</strong> F. Further,we know that C is greater than D, <strong>and</strong> that E is greater than F.current knowledge about the objects, such that zero or more of the order relationsbetween pairs of elements are known. We can represent this knowledge by drawingdirected acyclic graphs (DAGs) showing the known relationships, as illustrated byFigure 15.1.Initially, we know nothing about the relative order of the elements in L, ortheir relationship <strong>to</strong> K. So initially, we can view the n elements in L as being inn separate partial orders. Any comparison between two elements in L can affectthe structure of the partial orders. This is somewhat similar <strong>to</strong> the UNION/FINDalgorithm implemented using parent pointer trees, described in Section 6.2.Now, every comparison between elements in L can at best combine two of thepartial orders <strong>to</strong>gether. Any comparison between K <strong>and</strong> an element, say A, in L canat best eliminate the partial order that contains A. Thus, if we spend m comparisonscomparing elements in L we have at least n − m partial orders. Every such partialorder needs at least one comparison against K <strong>to</strong> make sure that K is not somewherein that partial order. Thus, any algorithm must make at least n comparisons in theworst case.15.2.2 Searching in Sorted ListsWe will now assume that list L is sorted. In this case, is linear search still optimal?Clearly no, but why not? Because we have additional information <strong>to</strong> work with thatwe do not have when the list is unsorted. We know that the st<strong>and</strong>ard binary searchalgorithm has a worst case cost of O(log n). Can we do better than this? We canprove that this is the best possible in the worst case with a proof similar <strong>to</strong> that used<strong>to</strong> show the lower bound on sorting.Again we use the decision tree <strong>to</strong> model our algorithm. Unlike when searchingan unsorted list, comparisons between elements of L tell us nothing new about their

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

Saved successfully!

Ooh no, something went wrong!