If fϵX×Y and gϵY×Z
Then
gofϵX×Z i.e
(x,z)ϵgof
Applying the above concept, we gives us
gof={(1,2)|(2,3),(3,5)|(5,1),(4,1)|(1,3)}
={(1,3),(3,1),(4,3)}
Similarly
fog={(2,3)|(3,5),(5,1)|(1,2),(1,3)|(3,5)}
={(2,5),(5,2),(1,5)}
Hence both fog and gof has 3 elements.