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.
This is absolutely not true. Having battled against higher level cards since the beginning I have come up with a deck that does well when underpowered. The deck revolves around the golem, and I can assure you it is not random. I noticed it a lot when I got to level 12 cards and was constantly playing all max cards. If the golem is 7 or 8 I have such a slow start it is hard to recover. So I started tracking where the card starts. Less than 1/3 of the time (47 out of my last 152 matches) is the card in the starting four. This simply is not random.