QTC algorithm implementation.
First part of documentation.