We have $2n$ values $x_1,x_2,x_3,\ldots,x_n$ and $y_1,y_2,y_3,\ldots,y_n$ such that the pair $(x_i,y_i)$ represents the location of a city $i$. Assume there is no straight line that goes through all the cities.
We also have the $n$ values $z_1,z_2,z_3,\ldots,z_n$. $z_i$ represents the population of the city $i$.
Our goal is to find three cities $a,b,c$ who are not a straight line (meaning, they form a triangle) with the largest population.
The question is as follows:
Propose a greedy algorithm that solves this problem. Prove the correctness of the algorithm, and find its time complexity.
What I did
The naive greedy algorithm that comes to mind is: pick the city with the largest population $a$, then pick the city with the second largest population $b$. Remove $a,b$ from the list of cities.
$(*)$Now from the remaining cities, choose $c'$ the city with the largest population. does $c'$ form a triangle with $ab$? If yes, then define $c=c'$ and stop. If no, then remove $c'$ from the list of cities and repeat step $(*)$
This is a greedy algorithm, but I'm not sure how to prove that it is correct. I thought maybe induction is the way to go, and it's easy to see that this algorithm is correct when no $3$ cities are on a straight line. It's also easy to prove when $n-1$ cities are on a straight line. But I can't seem to prove the general case.
Let $(a, b,c)$ be the cities your algorithm finds. Let $(u,v,w)$ be an optimal solution (also ordered by decreasing population).
Claim. $z_a=z_u$.
Proof. Assume otherwise. Then $z_a>z_u\ge z_v\ge z_w$ and $(a,v,w)$ would be strictly better, which is absurd; hence $a,v,w$ are collinear. But then $(u,a,w)$ would be strictly better than $(u,v,w)$, qea. $_\square$
Claim. $z_b=z_v$.
Proof. Assume otherwise. If $z_v>z_b$ then we would not have picked $b$ unless $v=a$. But then $u\ne a$ and we would not have picked $b$ instead of $u$. Thus $z_v<z_b$. As above, we conclude that $u,b,w$ are collinear. But then $(u,b,v)$ would be strictly better than $(u,v,w)$, qea. $_\square$
Claim. $z_c=z_w$.
Proof. Assume otherwise. Then $z_c< z_w$ by optimality of $(u,v,w)$. Then $a,b,w$ are collinear or else we would not have picked $c$ instead of $w$. Then one of $u,v$ is not on the line determined by $a,b$. Hence $z_c\ge z_v\ge z_w$, qea. $_\square$