I know that the card once used gets added to a queue in the backend. However, what I don't understand is what algorithm has been used to shuffle cards at the beginning of the game. Can anyone explain that?
The cards you draw at the start of a match are completely random. It doesn't matter how you initially arranged the cards in your deck, or what types of cards your deck consists of.
Per the Clash Royale wiki:
In battle, 4 of the 8 cards in your Battle Deck will be available to play in most cases. The first 4 cards will be randomly selected at the start of the battle.