• + 1 comment

    OK, I edited my claim to be more accurate. My algorithm uses O(1) auxiliary space.

    I load the entire data set into memory, but you can rewrite the same algorithm using pointers or file offsets. Three pointers use O(1) space. It certainly beats O(d) auxiliary space.

    Evaluating each element up to 3 times is O(1) time each for a total of O(n) time.