Recurrence relations
February 03, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 1
Recurrence relations February 03, 2020 Cinda Heeren / Andy Roth / - - PowerPoint PPT Presentation
Recurrence relations February 03, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 1 Analyzing recursive functions On the previous lesson: Geoff's recursion tree analysis for running time of recursive functions e.g. Merge sort running time
February 03, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 1
February 03, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 2
February 03, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 3
double arrMax(double arr[], int size, int start) { if (start == sz – 1) return arr[start]; else return max( arr[start], arrMax(arr, size, start + 1) ); }
February 03, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 4
February 03, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 5
February 03, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 6
February 03, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 7
The big question: Is it possible for a comparison-based sorting algorithm to have better asymptotic worst-case performance than Merge sort?
February 03, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 8
a b c d …
a < b a < c a < c Y N b < c b < c Y N b < c b < c Y N Y N Y N Y N Y N 𝑏 < 𝑐 < 𝑑 < ⋯ sorted … < 𝑑 < 𝑐 < 𝑏 sorted sorted sorted sorted sorted
… … … … … … The leaves represent the sorted output for some particular input permutation Each path from root to a leaf is the sequence of decisions made to sort some input permutation Longest path: maximum decisions in worst case
correctly sort some input permutations
February 03, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 9
February 03, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 10
n i n i
2 / 1 1
The worst case of any comparison-based sorting algorithm can be no better than Ω 𝑜 log 𝑜 The longest decision path can be no shorter than this But – there are non-comparison-based sorting algorithms that can perform better (with assumptions). Stay tuned in CPSC 320 (maybe)!
February 03, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 11