Embracing Algorithms

WWDC 2018

Posted by Den on June 21, 2018 · 5 mins read
Embracing Algorithms

Embracing Algorithms

WWDC 2018

Embracing Algorithms

WWDC 2018

Problem 1

1st Bug fix


But there is a problem that if you try to delete 2 consecutive elements.


Final Bug fix

Optimization

The remove(at: ) complexity is O(n)

remove(at: ) complexity is O(n)

So the deleteSelection() complexity is O(n²)

O(n²)

we can optimize the function O(n²) → O(n) by the removeAll(where: )

Linear vs Quadratic

Linear algorithms always wins

Problem 2

Optimization

O(n²) → O(n)

stablePartition

Problem 3

Optimization

stablePartition

Problem 4

Optimization