Working of Quantum Algorithm and Comparison to classical Algorithm