Notes-592-ch4-L-05

Notes-592-ch4-L-05 - SHEN'S CLASS NOTES Chapter 4...

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

SHEN’S CLASS NOTES 1 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 .

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

View Full Document
SHEN’S CLASS NOTES 2 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? 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 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 > > > > >
SHEN’S CLASS NOTES 3 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 .

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 15

Notes-592-ch4-L-05 - SHEN'S CLASS NOTES Chapter 4...

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

View Full Document
Ask a homework question - tutors are online