smooth sort

112
Analysis of Algorithm SmoothSort Habib Ullah MS(CS)

Upload: habib786

Post on 15-Jan-2015

1.712 views

Category:

Education


13 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Smooth Sort

Analysis of Algorithm

SmoothSort

Habib Ullah MS(CS)

Page 2: Smooth Sort

Science of Computer ProgrammingVolume 1, Issue 3, Pages 223–233

Smoothsort, an alternative for sorting in situ

(Edsger Wybe)

http://www.sciencedirect.com/science/article/pii/0167642382900168

Page 3: Smooth Sort

Contents

• What is Smoothsort• Heapsort Analysis• Idea: A family of heaps• Leonardo Numbers & Trees• Smoothsort operations• Algo & Runtime Analysis• Conclusion

Page 4: Smooth Sort

Waybe

Page 5: Smooth Sort
Page 6: Smooth Sort

Why is Heapsort O(n lg n)?

Page 7: Smooth Sort

Why is Heapsort O(n lg n)?

Page 8: Smooth Sort

Why is Heapsort O(n lg n)?

Page 9: Smooth Sort

Why is Heapsort O(n lg n)?

Page 10: Smooth Sort
Page 11: Smooth Sort
Page 12: Smooth Sort
Page 13: Smooth Sort
Page 14: Smooth Sort

Building a Leonardo Heap

Insert Operation

Page 15: Smooth Sort

Insert Operation

Page 16: Smooth Sort
Page 17: Smooth Sort
Page 18: Smooth Sort
Page 19: Smooth Sort
Page 20: Smooth Sort
Page 21: Smooth Sort
Page 22: Smooth Sort
Page 23: Smooth Sort
Page 24: Smooth Sort
Page 25: Smooth Sort
Page 26: Smooth Sort
Page 27: Smooth Sort
Page 28: Smooth Sort
Page 29: Smooth Sort
Page 30: Smooth Sort
Page 31: Smooth Sort
Page 32: Smooth Sort
Page 33: Smooth Sort
Page 34: Smooth Sort
Page 35: Smooth Sort
Page 36: Smooth Sort
Page 37: Smooth Sort
Page 38: Smooth Sort
Page 39: Smooth Sort
Page 40: Smooth Sort
Page 41: Smooth Sort
Page 42: Smooth Sort
Page 43: Smooth Sort
Page 44: Smooth Sort
Page 45: Smooth Sort

DE queuing from a Leonardo Heap

Remove Operation

Page 46: Smooth Sort

Dequeue Operation

Page 47: Smooth Sort
Page 48: Smooth Sort
Page 49: Smooth Sort
Page 50: Smooth Sort
Page 51: Smooth Sort
Page 52: Smooth Sort
Page 53: Smooth Sort
Page 54: Smooth Sort
Page 55: Smooth Sort
Page 56: Smooth Sort
Page 57: Smooth Sort
Page 58: Smooth Sort
Page 59: Smooth Sort
Page 60: Smooth Sort
Page 61: Smooth Sort
Page 62: Smooth Sort
Page 63: Smooth Sort
Page 64: Smooth Sort
Page 65: Smooth Sort
Page 66: Smooth Sort
Page 67: Smooth Sort
Page 68: Smooth Sort
Page 69: Smooth Sort
Page 70: Smooth Sort
Page 71: Smooth Sort
Page 72: Smooth Sort
Page 73: Smooth Sort
Page 74: Smooth Sort
Page 75: Smooth Sort
Page 76: Smooth Sort
Page 77: Smooth Sort
Page 78: Smooth Sort
Page 79: Smooth Sort
Page 80: Smooth Sort
Page 81: Smooth Sort
Page 82: Smooth Sort

Algo & Runtime Analysis

Page 83: Smooth Sort

• Insert

– If last two heaps are two consecutive leonardo numbers• Add new element as there root

– Else if the rightmost is not of size 1• New element becomes a new heap of size 1. This 1 is taken to be

L(1)– Else

• New element becomes a new heap of size 1. This 1 is taken to be L(0)

• Restore

– Set new element as "current" heap.

– While there is a heap to the left of the current heap and its root is larger than the current root and both of its child heap roots

• Swap(left-root with current).[Now current is that left root]

– While the current heap has a size greater than 1 and either child heap of the current heap has a root node greater than the root of the current heap

• Swap the greater child root with the current root. That child heap becomes the current heap.

C1

(Log N) times (Log N)

Log N

Page 84: Smooth Sort

Dequeue

– Remove topmost node of rightmost heap.– If it has no children, we're done.

– Otherwise:

– Fix up the left of the two heaps.– Then fix up the right of the two heaps.

For N elements to dequeue running time is (N LogN) but this is asymptotically far less than Heap sort.

C1

Log N

Page 85: Smooth Sort
Page 86: Smooth Sort
Page 87: Smooth Sort
Page 88: Smooth Sort
Page 89: Smooth Sort
Page 90: Smooth Sort
Page 91: Smooth Sort
Page 92: Smooth Sort
Page 93: Smooth Sort
Page 94: Smooth Sort
Page 95: Smooth Sort
Page 96: Smooth Sort
Page 97: Smooth Sort
Page 98: Smooth Sort
Page 99: Smooth Sort
Page 100: Smooth Sort
Page 101: Smooth Sort
Page 102: Smooth Sort
Page 103: Smooth Sort
Page 104: Smooth Sort
Page 105: Smooth Sort
Page 106: Smooth Sort
Page 107: Smooth Sort
Page 108: Smooth Sort
Page 109: Smooth Sort
Page 110: Smooth Sort
Page 111: Smooth Sort

Conclusion

• Compared to Heap Sort– Efficient in Best Case– Equal in Worst Case but the asymptotic graph is

far less than Heap Sort

Page 112: Smooth Sort