can someone explain its algorithm in detail?
Er… Which algorithm??
I think that’s what you are looking for…
People already provided you with links for your problem, and I hope you can solve it
But please, if you intend to obtain help from the community try to be as descriptive and organized as it is possible to you.
This is because it actually makes a lot easier for people to help you out and both you and the helper can benefit more of your questions
Please take this as an advice and not actually a critic