Richart Agarwala's Algorithm