The concept of complete bipartite graphs can be generalized to define the complete multipartite graph $K(r_1,r_2,...,r_k)$. It consists of $k$ sets of vertices each with cardinality $r_i$ for $i$ in $\{1,2,\ldots,k\}$ where all possible "interest" edges are present but no "intraset" edges are present.
For bipartite graphs I have Mathematica code: Table[Floor[n/2] Ceiling[n/2], {n, 0, 10}] {0, 0, 1, 2, 4, 6, 9, 12, 16, 20, 25}
for tripartite graphs I have:
f[n_] := Which[Mod[n, 3] == 0, 3 (n/3)^2, Mod[n, 3] == 1, Floor[n/3]^2 + 2 Ceiling[n/3] Floor[n/3], Mod[n, 3] == 2, Ceiling[n/3]^2 + 2 Ceiling[n/3] Floor[n/3]]; Table[f[n], {n, 0, 10}] {0, 0, 1, 3, 5, 8, 12, 16, 21, 27, 33}
In neither case am I convinced that I am correct. It just seems intuitive that the sets must be (as nearly as possible) the same size. How can I generalize for larger k?
This question is an exercise in "Combinatorics and Graph Theory" Harris,Herst,Mossinghoff. page 16.
I read and understood the solution given by Kaya in another post: $n^2\frac{k-1}{2k}$ but this is only true when $n$ is a multiple of $k$. I want to be able to write a code in Mathematica for any $k$ and any $n$.