Chapter 4 - SHEN'S CLASS NOTES Chapter 4 Non-Comparison...

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

View Full Document Right Arrow Icon
SHEN’S CLASS NOTES Chapter 4 Non-Comparison Sorting As   we   can   observe   that   all   comparison   sorting   algorithms  discussed in Chapter 3 have a worst case running time  ( n lg n or larger. Can we do better? The answer is no if the sorting is  based on comparisons. We will prove this conclusion in this  chapter. Moreover, we show that we may get faster running time  if we use non-comparison sorting techniques.  4.1 Lower Bounds for Comparison Sorting Any comparison sorting algorithm can be represented by a binary decision tree. A decision tree is used to model a process that makes a decision based on a sequence of tests. Moreover, what kind of test should take place at each step is determined from the outcome of previous test. Example. The following binary tree represents an execution of an algorithm that sorts three numbers in A[1], A[2], and A[3]. Note that any correct algorithm should clearly define how to construct the decision tree for any input size n . 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
SHEN’S CLASS NOTES Fig. 8-1 In the decision tree, each leaf corresponds to a decision that tells us how to re-arrange the three elements such that they are in increasing order. This arrangement corresponds to a permutation among the three numbers. In general, a decision for sorting n numbers must have at least n ! leaves, each of which represents a permutation among the n numbers. Conducting the permutation will produce a sorted sequence. How to conducting the permutation is not shown by the decision tree, but is clearly given by the algorithm. Then, why do we need the decision tree? 1:2 2:3 1:3 2:3 1:3 1, 2, 3 1, 3, 2 2, 1, 3 3, 1, 2 2, 3, 1 3, 2, 1 > > > > > 2
Background image of page 2
SHEN’S CLASS NOTES The decision tree is usually used to evaluate the complexity. For example, the longest path from the root to a leaf in the decision tree corresponds to the worst case. This is because the length of the path equals the number of tests performed to reach the decision (leaf). The shortest path from the root to a leaf corresponds to the best case. The average path length represents the average complexity of the algorithm. Lemma 1 In any rooted binary tree with height h and L leaves, we have the relation L 2 h (or h lg L ). Proof. Fig. 8-2 illustrates the case for a complete binary tree. The lemma is correct for the complete tree. Obviously, if the tree is not complete, then the number of leaves will be less than 2 h . Therefore, in any case, we have L 2 h (or h lg L ). level
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 17

Chapter 4 - SHEN'S CLASS NOTES Chapter 4 Non-Comparison...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online