If you want to calculate number of paths from one node to another ,let say from s to t.then you can follow the following approach.

To reach a node t from s , you need to calculate that how many ways are there to reach t from its adjacent vertices .
means
PathsTo(s,t)=sum(PathsTo(s,u)) , where u are adjacents vertices of t.

as we can see there is a subproblem optimality and overlapping subproblems, so we can use a DP approach to do this in Linear time.

We can do this by modifying our DFS algorithm.

Psuedocode:

declare an array A of size |V| , memset it to NULL
array represent , number of ways to reach a node v from s.

Paths(s,t):

if(s==t):

```
return 1;
```

else:

```
if(A[t]==NULL):
A[t]=sum(Paths(s,u)) for all adjacent u of t
else
return A[t]
```

Time complexity is O(V+E) same as DFS.