precondition: array V has size N e = 0; x = 1; for (k = 0; k < N; k++) { v = V[k]; if (v == x) { e++; } else if (2*e == k) { x = v; e++; } }