3 ms·
This "efficient" algorithm takes O(n^2) time (where n is the number of grid squares) because it has to repeatedly remove elements from the middle of a list. It
by teraflop 16y ago
This "efficient" algorithm takes O(n^2) time (where n is the number of grid squares) because it has to repeatedly remove elements from the middle of a list. It can easily be improved to O(n) by simply shuffling the list once and traversing it in order.