Chan's algorithm