Download presentation
Presentation is loading. Please wait.
1
Optimal Algorithms Search and Sort
2
Decision Trees Represents a Series of Decisions
Every Algorithm Has It’s Own We can draw conclusions based on the mathematical properties of trees x[1] = x[2]? True False x[3] = x[4]? x[5] = x[6]? These may be identical
3
Example: Searching Assume List is Ordered
Comparisons of the Form: Key<L[i]? For all x, 0<x£n, There must be a comparison: Key<L[x]? Decision Tree for ANY Search Algorithm Must have at least n vertices Property of Trees: Any binary tree with n vertices must have height at least lg n
4
Example: Sorting It is difficult to quantify the number of vertices
However, there must be at least one leaf for each possible re-ordering of keys There are n! possible reorderings The tree must have at least n! leaves A tree with k leaves must have height at least lg k lg(n!) Î Q(n lg n)
5
General Principles To find an Upper Bound on the complexity of a problem Write an Algorithm To find a Lower Bound on the complexity of a problem Make a Mathematical Argument Optimal means Upper Bound = Lower Bound Only a few Optimal Results are known
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.