I'm working on the following exercise:
Consider a point set $S = \{ p_1, p_2, ..., p_n \}$ in the plane in general position (i.e., no three points of $S$ are collinear). The points of $S$ have pairwise different $y$-coordinates and are sorted in increasing order of them, i.e., $y(p_i) < y(p_j) $ if and only if $i < j$. Develop an algorithm that computes a triangulation of $S$ and needs $O(n)$ runtime and memory.
I got the following algorithm (based on Andrew's monotone chain algorithm) from Marcelo Fornet in his answer to one of my previous questions (I condensed it a bit):
Input: a list P of points in the plane.
Precondition: There must be at least 3 points.
# Initialize T as empty list to store triangulation
Initialize U and L as empty lists.
The lists will hold the vertices of upper and lower hulls respectively.
for i = 1, 2, ..., n:
while L contains at least two points and the sequence of last two points
of L and the point P[i] does not make a counter-clockwise turn:
Add the last two points from L and P[i] to T (the triangulation)
remove the last point from L
append P[i] to L
for i = n, n-1, ..., 1:
while U contains at least two points and the sequence of last two points
of U and the point P[i] does not make a counter-clockwise turn:
# Add last two points from U and P[i] to T (the triangulation)
remove the last point from U
append P[i] to U
The triples of points in T will be the triangles
While I understand how this algorithm works I'm struggeling to show it's correctness in a formal way.
My idea would be to use induction on the invariant that this algorithm always prodcuces a triangulation of the given point set. This is what I tried:
Assertion: The said algorithm always returns a triangulation for a given point set.
The assertion is clear for a set of three points, so we got our induction start.
Now lets suppose the assertion holds for all sets with at most n points.
But I'm stuck at the induction step. I tried to make a case analysis wether the new point $p_{n+1}$ lies in the upper or the lower half of the convex hull of $\{p_1,....,p_n\}$, but it didn't work out.
I'd be thankful for any kind of help.