Thompson's construction algorithm