Maximum number of edges in undirected graph with n vertices with k connected components?
This answer depends on whether your graphs are allowed to have self-loops or not. For simplicity, I'm going to assume they aren't.
If you have a connected component with x nodes in it, the maximum number of edges you can have in that connected component is x(x - 1) / 2. Therefore, if you have n total nodes and k different connected components, you can imagine distributing the nodes into the connected components in a way that maximizes the sum of x(x - 1) / 2 across the connected components.
Specifically, suppose your CC's have n1, ..., nk nodes each. You want to solve the following quadratic program:
Maximize: n1(n1 - 1) / 2 + ... + nk(nk - 1) / 2
Subject to: n1 + ... + nk = n
I'm going to claim that this is maximized when k - 1 of the connected components have 1 node and the last connected component has n - k + 1 nodes in it. Intuitively, this is true because any node you remove from the huge CC will cause a large drop in the number of possible edges that will not be offset by the meager increase in the number of possible edges in the other connected component the node was added to.
Under this setup, the maximum number of possible edges in the k - 1 singleton CC's will be 0 and the maximum number of possible edges in the other CC will be (n - k + 1)(n - k) / 2. Therefore, the total should be (n - k + 1)(n - k) / 2.
Hope this helps!