1 / 25

Understanding Decision Trees and Lower Bounds in Comparison-based Sorting Methods

This document explores the decision tree model used in comparison-based sorting algorithms. It discusses how binary trees represent comparisons between elements, with internal nodes holding indices and leaves containing permutations of input data. By tracing paths from the root to leaves, one can derive the correct ordering. The text also delves into the lower bounds of sorting algorithms, presenting the maximum number of comparisons in relation to the height of the tree and the permutations of the input data, underscoring the significance of decision trees in efficient sorting.

Télécharger la présentation

Understanding Decision Trees and Lower Bounds in Comparison-based Sorting Methods

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lower Bound on Sorting David Kauchak cs062 Spring 2010

  2. Decision-tree model • Binary tree representing the comparisons between elements by a sorting algorithm • Internal nodes contain indices to be compared • Leaves contain a complete permutation of the input • Tracing a path from root to leave gives the correct reordering/permutation of the input for an input 1:3 ≤ > [3, 12, 7] | 1,3,2 | [3, 7, 12] | 1,3,2 | [3, 7, 12] | 2,1,3 | [7, 3, 12]

  3. Comparison-based sorting • Sorted order is determined based only on a comparison between input elements • A[i] < A[j] • A[i] > A[j] • A[i] = A[j] • A[i] ≤ A[j] • A[i] ≥ A[j] • This is why most built-in sorting approaches only require you to define the comparison operator (i.e. compareTo in Java) • Can we do better than O(n log n)?

  4. A decision tree model 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1|

  5. A decision tree model 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [12, 7, 3]

  6. A decision tree model 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [12, 7, 3] Is 12 ≤ 7 or is 12 > 7?

  7. A decision tree model 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [12, 7, 3] Is 12 ≤ 3 or is 12 > 3?

  8. A decision tree model 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [12, 7, 3] Is 12 ≤ 3 or is 12 > 3?

  9. A decision tree model 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [12, 7, 3] Is 7 ≤ 3 or is 7 > 3?

  10. A decision tree model 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [12, 7, 3] Is 7 ≤ 3 or is 7 > 3?

  11. A decision tree model 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| 3, 2, 1 [12, 7, 3]

  12. A decision tree model 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| 3, 2, 1 [3, 7, 12] [12, 7, 3]

  13. A decision tree model 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [7, 12, 3]

  14. A decision tree model 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [7, 12, 3]

  15. A decision tree model 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [7, 12, 3]

  16. A decision tree model 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [7, 12, 3]

  17. A decision tree model 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [7, 12, 3]

  18. A decision tree model 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [3, 7, 12] [7, 12, 3]

  19. How many leaves are in a decision tree? • Leaves must have all possible permutations of the input • What if decision tree model didn’t? • Some input would exist that didn’t have a correct reordering • For an input of size n, how many leaves? • n! leaves

  20. A lower bound • What is the worst-case number of comparisons for a tree? 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1|

  21. A lower bound • The longest path in the tree, i.e. the height 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1|

  22. A lower bound • What is the maximum number of leaves a binary tree of height h can have? • A complete binary tree has 2h leaves log is monotonically increasing 

  23. Other heaps

  24. Other heaps

  25. Other heaps

More Related