Embracing Algorithms
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)
So the deleteSelection() complexity is 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)