Number of 3-paths in a graph

How can I find the number of paths of length 2 and 3 in an arbitrary graph?(i.e. the number of $P_3$ s and $P_4$ s)