Complexity of the Adaptive ShiversSort Algorithm
and of its sibling TimSort
Vincent Jugé
LIGM – Université Paris-Est Marne-la-Vallée, ESIEE, ENPC & CNRS
18/03/2019
- V. Jugé
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm and of its sibling - - PowerPoint PPT Presentation
Complexity of the Adaptive ShiversSort Algorithm and of its sibling TimSort Vincent Jug LIGM Universit Paris-Est Marne-la-Valle, ESIEE, ENPC & CNRS 18/03/2019 V. Jug Complexity of the Adaptive ShiversSort Algorithm Contents
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm
1 Chunk your data in non-decreasing runs
Complexity of the Adaptive ShiversSort Algorithm
1 Chunk your data in non-decreasing runs 2 New parameters: Number of runs (ρ) and their lengths (r1, . . . , rρ)
Complexity of the Adaptive ShiversSort Algorithm
1 Chunk your data in non-decreasing runs 2 New parameters: Number of runs (ρ) and their lengths (r1, . . . , rρ)
Complexity of the Adaptive ShiversSort Algorithm
1 Chunk your data in non-decreasing runs 2 New parameters: Number of runs (ρ) and their lengths (r1, . . . , rρ)
Complexity of the Adaptive ShiversSort Algorithm
1 Chunk your data in non-decreasing runs 2 New parameters: Number of runs (ρ) and their lengths (r1, . . . , rρ)
Complexity of the Adaptive ShiversSort Algorithm
1 Chunk your data in non-decreasing runs 2 New parameters: Number of runs (ρ) and their lengths (r1, . . . , rρ)
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm
1 1 Invented by Tim Peters[1]
Complexity of the Adaptive ShiversSort Algorithm
1 2
1 Invented by Tim Peters[1] 2 Standard algorithm in Python
Complexity of the Adaptive ShiversSort Algorithm
1 2
3 3 3
1 Invented by Tim Peters[1] 2 Standard algorithm in Python 3 Standard algorithm
Complexity of the Adaptive ShiversSort Algorithm
1 2
3 3 3
4 1 Invented by Tim Peters[1] 2 Standard algorithm in Python 3 Standard algorithm
4 1st worst-case complexity analysis[4] – TimSort works in time O(n log n)
Complexity of the Adaptive ShiversSort Algorithm
1 2
3 3 3
4 5 1 Invented by Tim Peters[1] 2 Standard algorithm in Python 3 Standard algorithm
4 1st worst-case complexity analysis[4] – TimSort works in time O(n log n) 5 Refined worst-case analysis[5] – TimSort works in time O(n + n H)
Complexity of the Adaptive ShiversSort Algorithm
1 2
3 3 3
4 5 1 Invented by Tim Peters[1] 2 Standard algorithm in Python 3 Standard algorithm
4 1st worst-case complexity analysis[4] – TimSort works in time O(n log n) 5 Refined worst-case analysis[5] – TimSort works in time O(n + n H)
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm
1 Run merging algorithm: standard + many optimizations ◮ time O(k + ℓ) ◮ memory O(min(k, ℓ))
Complexity of the Adaptive ShiversSort Algorithm
1 Run merging algorithm: standard + many optimizations ◮ time O(k + ℓ) ◮ memory O(min(k, ℓ))
2 Policy for choosing runs to merge: ◮ depends on run lengths only
Complexity of the Adaptive ShiversSort Algorithm
1 Run merging algorithm: standard + many optimizations ◮ time O(k + ℓ) ◮ memory O(min(k, ℓ))
2 Policy for choosing runs to merge: ◮ depends on run lengths only 3 Complexity analysis:
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm
1
2
3
Complexity of the Adaptive ShiversSort Algorithm
1
2
3
Complexity of the Adaptive ShiversSort Algorithm
1
2
3
Complexity of the Adaptive ShiversSort Algorithm
1
2
3
Complexity of the Adaptive ShiversSort Algorithm
1
2
3
Complexity of the Adaptive ShiversSort Algorithm
1
2
3
Complexity of the Adaptive ShiversSort Algorithm
1
2
3
Complexity of the Adaptive ShiversSort Algorithm
1
2
3
Complexity of the Adaptive ShiversSort Algorithm
1
2
3
Complexity of the Adaptive ShiversSort Algorithm
1
2
3
Complexity of the Adaptive ShiversSort Algorithm
1
2
3
Complexity of the Adaptive ShiversSort Algorithm
1
2
3
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm
◮ O(r) to enter the stack (run entry phase)
3
Complexity of the Adaptive ShiversSort Algorithm
◮ O(r) to enter the stack (run entry phase)
3
Complexity of the Adaptive ShiversSort Algorithm
◮ O(r) to enter the stack (run entry phase)
Complexity of the Adaptive ShiversSort Algorithm
◮ O(r) to enter the stack (run entry phase)
◮ r pays for every merge ◮ (ri)i1 has exponential decay when r is pushed ◮ runs smaller than r are merged
Complexity of the Adaptive ShiversSort Algorithm
◮ O(r) to enter the stack (run entry phase) ◮ r to double its size (stabilisation phase)
◮ r pays for every merge ◮ (ri)i1 has exponential decay when r is pushed ◮ runs smaller than r are merged
Complexity of the Adaptive ShiversSort Algorithm
◮ O(r) to enter the stack (run entry phase) ◮ r to increase its bit length (stabilisation phase)
◮ r pays for every merge ◮ (ri)i1 has exponential decay when r is pushed ◮ runs with smaller bit length than r are merged
Complexity of the Adaptive ShiversSort Algorithm
◮ O(r) to enter the stack (run entry phase) ◮ r to increase its bit length (stabilisation phase)
◮ r pays for every merge ◮ (ri)i1 has exponential decay when r is pushed ◮ runs with smaller bit length than r are merged
◮ ri and ri+1 are merged only if their bit lengths are equal
Complexity of the Adaptive ShiversSort Algorithm
◮ O(r) to enter the stack (run entry phase) ◮ r to increase its bit length (stabilisation phase)
◮ r pays for every merge ◮ (ri)i1 has exponential decay when r is pushed ◮ runs with smaller bit length than r are merged
◮ ri and ri+1 are merged only if their bit lengths are equal
Complexity of the Adaptive ShiversSort Algorithm
◮ O(r) to enter the stack (run entry phase) ◮ r to increase its bit length (stabilisation phase)
◮ r pays for every merge ◮ (ri)i1 has exponential decay when r is pushed ◮ runs with smaller bit length than r are merged
◮ ri and ri+1 are merged only if their bit lengths are equal
Complexity of the Adaptive ShiversSort Algorithm
1 discover & push a new run length onto the stack 2 merge the top 1st and 2nd runs 3 merge the top 2nd and 3nd runs
2 3 1
Complexity of the Adaptive ShiversSort Algorithm
1 discover & push a new run length onto the stack 2 merge the top 1st and 2nd runs 3 merge the top 2nd and 3nd runs
2 3 1
Complexity of the Adaptive ShiversSort Algorithm
1 discover & push a new run length onto the stack 2 merge the top 1st and 2nd runs 3 merge the top 2nd and 3nd runs
2 3 1
Complexity of the Adaptive ShiversSort Algorithm
1 discover & push a new run length onto the stack 2 merge the top 1st and 2nd runs 3 merge the top 2nd and 3nd runs
2 3 1
Complexity of the Adaptive ShiversSort Algorithm
1 discover & push a new run length onto the stack 2 merge the top 1st and 2nd runs 3 merge the top 2nd and 3nd runs
2 3 1
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm
Complexity of the Adaptive ShiversSort Algorithm