I'm trying to calculate the maximum number of edges for 4 specifically-shaped connected graphs with n nodes (see the attached / below picture for the 4 specific shapes). So the first type of graph, the square, would come close to 2n edges for higher numbers of n, but I need something much more accurate for n between 0 and 100. For n=7, the max might be 8 but for n=8, the max might be 10 - both different and not at all close to 2n.
Visual representation of the 4 specifically-shaped connected graphs
I'm basically looking for 4 different functions which express the maximum number of edges for n nodes for these 4 different types of graphs.
This question might be quite vague since I'm not formally trained in math - but appreciate any clarifying questions / attempts at an answer.
For the square grid if you have a rectangular grid of $k \times m$ points the number of points is $km$. The number of edges is $k(m-1)+(k-1)m$ where one term counts horizontal edges and the other vertical. If you can factor $n$ into two close factors this will be optimal. Having an extra edge may help if $n$ does not factor nicely. For example, if $n=23$ you could have $22$ edges if you make a linear chain. If you make a $2 \times 11$ grid plus one edge you have $32$. If you make a $4 \times 5$ grid plus three edges you have $34.$ I don't think there is an easy formula.