explanation of algorithm