f∘g means g(x) function is in f(x) function.
g∘f means f(x) function is in g(x) function.
f={(3,1),(9,3),(12,4)} and g={(1,3),(3,3),(4,9),(5,9)}
f={3,9,12}→{1,3,4} and g:{1,3,4,5}→{3,9}
Co-domain of f is a subset of the domain of g.
So, g∘f exists and g∘f:{3,9,12}→{3,9}
⇒ (g∘f)(3)=g[f(3)]=g(1)=3
⇒ (g∘f)(9)=g[f(9)]=g(9)=3
⇒ (g∘f)(12)=g[f(12)]=g(4)=9
⇒ g∘f={(3,3),(9,3),(12,9)}
Co-domain of g is a subset of the domain of f.
So, f∘g exists and f∘g:{1,3,4,5}→{3,9,12}
⇒ (f∘g)(1)=f[g(3)]=f(3)=1
⇒ (f∘g)(3)=f[g(3)]=f(3)=1
⇒ (f∘g)(4)=f[g(4)]=f(9)=3
⇒ (f∘g)(5)=f[g(5)]=f(9)=3
⇒ f∘g={(1,1),(3,1),(4,3),(5,3)}