algorithm explanation.