Define N = 2 n . The array contains elements of N
Define M as the number of maj arrays appears in the array. The definition of "majority element" is that M > N/2 .
Now divide the array into pairs p[1] ... p[n] . Define q0 as the number of pairs containing zero instances of maj . Define q1 as the number of pairs that contain exactly one instance of maj . Define q2 as the number of pairs that contain exactly two maj instances.
Then N = 2 q0 + 2 q1 + 2 q2 and M = q1 + 2 q2 .
We substitute in the inequality that defines the element of the majority, and simplify:
M > N / 2 q1 + 2 q2 > (2 q0 + 2 q1 + 2 q2) / 2 q1 + 2 q2 > q0 + q1 + q2 2 q2 > q0 + q2 q2 > q0
Thus, the number of pairs containing two maj instances exceeds the number of pairs containing zero maj instances.
Now define M' number of times maj in the new array after running your algorithm. The algorithm removes one maj for each pair q1 and one maj for each pair q2 . So, M' = M - q1 - q2 .
Define N' as the size of the new array created by the algorithm. The algorithm removes two elements for each pair q1 and one element for each pair q2 .
But we do not know how many elements the algorithm removes for each pair q0 . Some q0 pairs contain two different elements, and the algorithm removes both. But other q0 pairs contain the same (not maj ) elements, and the algorithm removes only one.
One extreme is that all q0 pairs are completely removed. In this case, the algorithm removes the elements 2 q0 , therefore
N - 2 q1 - q2 - 2 q0 ≤ N'
Another extreme point is that only one element is removed from each pair q0 . In this case, the algorithm removes the elements q0 , therefore
N - 2 q1 - q2 - q0 ≥ N'
Let's go back to the definition of "majority element" and make some algebra:
M > N / 2 M - q1 - q2 > N / 2 - q1 - q2 M - q1 - q2 > (N - 2 q1 - 2 q2) / 2 M - q1 - q2 > (N - 2 q1 - q2 - q2) / 2
Left side M' .
M' > (N - 2 q1 - q2 - q2) / 2
Can we turn the right side into N' / 2 ? First, multiply both sides by 2:
2 M' > N - 2 q1 - q2 - q2
Recall that we have proved q2 > q0 . therefore
2 M' > N - 2 q1 - q2 - q2 > N - 2 q1 - q2 - q0
and, since we deduced N - 2 q1 - q2 - q0 ≥ N' ,
2 M' > N - 2 q1 - q2 - q0 ≥ N'
So
2 M' > N' M' > N' / 2
Thus, maj appears enough times in the new array as an element of most of the new array. Q.E.D.