Given an array of node and an array of edges, how do you calculate the number of connected graphs?

You can use a union find (you can search it up). Start with all of the nodes as separate sets, then for each edge join the two nodes that the edge connects into the same set. Then check how many different sets there are by going through all the nodes and finding how many different representatives there are.