How is class equation of a group of given order determined? How is class equation of a group of given order determined?
Suppose we have a group of order $8$ say $D_8=\{r^4=s^2=1;rs=sr^{-1}\}$.
How can I find the class equation of this group ?
Should I take each and every element and find the conjugacy class of that element.I know that class equation of a group is given by 
$|G|=|Z(G)|+\sum_{i=1}^n |cl(a_i)| $ where $a_i's$ are distinct class representatives.
Is there any elegant approach available that would even work for higher order groups such as $D_{10},S_4$ etc.
 A: Yes; you have to find conjugacy class of each element and sum their sizes. 
(You are explicitly taking a group of order $8$; there are other ways to determine class equation for this group with some techniques; but we do not use these techniques, since group is explicitly known here.)
In case $D_{10}, S_4$, the elegant approach would be following: in the family of dihedral groups, there is some pattern of conjugacy classes, which enables us to write down class equation. Similarly, in family of symmetric group, the conjugacy class sizes of elements is well known by a combinatorial formula. One can obtain class equation for the family. In general, for a finite group, there is no elegant way for class equation, which works for all (Except determining classes explicitly).
For specific group among dihedral or quaternion, some other information about group could help much to obtain class equation. For example, $D_8$, it is non-abelian group of prime-power order ($8$); its center should be non-trivial, hence $|Z(D_8)|\geq 2$. If $|Z(D_8)|=4$ or $8$ then $D_8/Z(D_8)$ will be cyclic, and $D_8$ will be abelian contradiction, so $|Z(D_8)|=2$. 
For $x\in D_8\setminus Z(D_8)$, the centralizer will contain $x$ as well as $Z(D_8)$, hence its order would be at least $4$. If it is $8$ then $x$ will be central, contr. Hence centralizer of $x$ has size $4$, i.e. its index in group is $2$, i.e. conjugacy class size is $2$, and is true for any non-central $x$. So class equation is $8=2+2+2+2$. 
But in this illustration, we are not using presentation of $D_8$; we are simply using fact that it is non-abelian group of order $8$. So, such small information about group may help to obtain class equation with some technique. 
