Merge Sort
2/8/2005 12:09 AM
Outline and Reading
The Greedy Method
The Greedy Method Technique (5.1)
Fractional Knapsack Problem (5.1.1)
Task Scheduling (5.1.2)
Minimum Spanning Trees (7.3) [future lecture]
The Greedy Method
1
The Greedy Method
Technique
The Selection Problem Selection
Given an integer k and n elements x1, x2, , xn, taken from a total order, find the k-th smallest element in this set. Of course, we can sort the set in O(n log n) time and then index the k-th element.
k=3 7496224679
Can we
Radish-Sort
4/9/2002 13:4
Bucket-Sort ( 4.5.1)
Let be S be a sequence of n
(key, element) items with keys
in the range [0, N 1]
Bucket-sort uses the keys as
indices into an auxiliary array B
of sequences (buckets)
Bucket-Sort and Radix-Sort
1, c
3, a
B
3
(2,4) Trees
4/9/2002 13:1
Comparison-Based
Sorting ( 4.4)
Many sorting algorithms are comparison based.
They sort by making comparisons between pairs of objects
Examples: bubble-sort, selection-sort, insertion-sort, heap-sort,
merge-sort, quick-sort, .
So
Sequences
4/15/2002 11:5
Set Operations
We represent a set by the
sorted sequence of its
elements
By specializing the auxliliary
methods he generic merge
algorithm can be used to
perform basic set
operations:
Sets
Set union:
aIsLess(a, S)
S.insertFirst(a)