I know that any permutation cycle can be decomposed into transpositions as follows:
$(a_1,a_2...,a_n) = (a_1,a_{n-1})...(a_1,a_2)$
But in my book there is an example of the following form
$(1,2,3,4,5) = (5,4)(5,2)(2,1)(2,5)(2,3)(1,3)$
I verified that it holds true. But I cant seem to figure out how the author came up with that. Also, What is the generic algorithm to produce all decompositions of permutation in terms of transpositions.
The decomposition given in your question appears to just be an example. As amWhy has pointed out, thus is by no means unique.
In answer to how the author came up with the decompositions, then the one in the question may well have been found by listing a series of transpositions and then working out what their product was! However, here's a bit of intuition behind the two decompositions given in amWhy's answer.
Let $\theta=(a_{1},a_{2},\ldots,a_{n})$. Then for $\theta=(a_{1},a_{n})(a_{1},a_{n-1})\cdots(a_{1},a_{2})$ we start by seeing where $\theta$ maps $a_{n}$. It gets mapped to $a_{1}$, so we start with the transposition $(a_{1},a_{n})$. Then we add things before this transposition that don't include $a_{n}$. So where does $\theta$ map $a_{n-1}$? It gets mapped to $a_{n}$. Thus if we add $(a_{1},a_{n-1})$ to our decomposition we get $(a_{1},a_{n})(a_{1},a_{n-1})$ which maps $a_{n}\mapsto a_{1}$ and $a_{n-1}\mapsto a_{n}$ as we want. Continuing in this way, we get the telescoping series:
$\theta=(a_{1},a_{n})(a_{1},a_{n-1})\cdots(a_{1},a_{2})$
The decomposition $\theta=(a_{1},a_{2})(a_{2},a_{3}\cdots(a_{n-1},a_{n})$ is formed in exactly the same way, but you just start off by seeing where $\theta$ maps $a_{1}$.