smooth sort by: ahmed mustafa. smooth’s stats time: worst case: best case: average case: space:...

Download Smooth Sort By: Ahmed Mustafa. Smooth’s Stats Time: Worst Case: Best Case: Average Case: Space: Worst Case: O(n) and O(1) auxiliary BUT HOW?!

If you can't read please download the document

Upload: brooke-boone

Post on 17-Jan-2018

219 views

Category:

Documents


0 download

DESCRIPTION

For Starters it’s a heapsort…kinda If you recall a Heap sort: Construct a max-heap: O(n) Set x to the index of the last spot in the array. While the heap is not yet empty: Remove the maximum element from the heap. Place that element at position x, then move x to the previous position. Rebalance the max-heap: O(lg n) Time/Space: O(n log n)/O(n) What’s the problem? *hint next max Dude…what if?

TRANSCRIPT

Smooth Sort By: Ahmed Mustafa Smooths Stats Time: Worst Case: Best Case: Average Case: Space: Worst Case: O(n) and O(1) auxiliary BUT HOW?! For Starters its a heapsortkinda If you recall a Heap sort: Construct a max-heap: O(n) Set x to the index of the last spot in the array. While the heap is not yet empty: Remove the maximum element from the heap. Place that element at position x, then move x to the previous position. Rebalance the max-heap: O(lg n) Time/Space: O(n log n)/O(n) Whats the problem? *hint next max Dudewhat if? Forests What if we build a max-heap but store the maximum element in position to be swapped to the root? Better yet. When we break a max heap, the two children there are max-heaps in their own right. Instead of immediately rebalancing we'll maintain a sequence of max-heaps, a bunch of trees,(thats a forest kid) embedded into the array and guarantee that one of these heaps will have the next max element. Gnarly scary single binary max heap Smooth beautiful forest Leonardos Nomination Why Leornardo? LeonardoNUMBERS! S.T. L(0)=1 L(1)=1 L(n+2)= L(n)+L(n+1)+1 Ex. 1,1,3,5,9,15 L(6) = L(4)+(L(5)+1 (9+15+1)= 25 Applicable? YEA! HERES A PROOF WELL NEED! Leonardo Proof Lemma: Any positive integer can be written as the sum of O(lg n) distinct Leonardo numbers. Proof: for any positive integer n, there is a sequence x 0, x 1,..., x k such that: There is some sequence of Leonardo numbers that sums up to the number n. If the sum contains two consecutive Leonardo numbers, then those are the smallest two Leonardo numbers in the sequence Proved by induction: proof Prove the sequences use at most O(lg n) with its cousinFibonacci The proof that L(k) = 2F(k + 1) - 1 is by induction on k. For k = 0, 2F(1) - 1 = = 1 = L(0). For k = 1, 2F(2) - 1 = = 1 = L(1). Now assume that for all k' < k, the claim holds. Then L(k) = L(k - 2) + L(k - 1) + 1 = 2F(k - 1) F(k) = 2(F(k - 1) + F(k)) - 1 = 2F(k + 1) - 1. Wow that was MathHeaps of fun Finally, Leonardo Heaps Collection of Leonardo Trees (see picture top right) S.T. The sizes of the trees are decreasing (none are equal in size) Each Tree is a Max-Heap The tree roots are ascending left to right Insertion: Must uphold above properties Decreasing size Essentially follows cases of proof Sorted roots Compare roots and their children; heapify or swap Dequeue: Rebalance the heap like Sorted roots and heapify THE ALOGRITHM HAS ARRIVED! Smooth Overview Scan an input sequence, converting it into a sequence of implicit max- heaps. Leonardo Max-Heaps (which places the heaps' top elements in ascending order, thus forcing the rightmost heap to hold the maximum of the remaining elements.) Once we've done this, we'll continuously dequeue the top element of the rightmost max-heap, which is in the correct location since it's in the rightmost unfilled spot. Two Content Layout with Table First bullet point here Second bullet point here Third bullet point here Group 1Group 2 Class Class Class 38490 Two Content Layout with SmartArt First bullet point here Second bullet point here Third bullet point here Group A Task 1 Task 2 Task 3 Task 4 hwarz.com/smooth sort/