Huang's termination detection algorithm - Needs the input in a particular format.