TITLE: Guess that group via product queries
QUESTION [30 upvotes]: Suppose someone (person B) knows a finite group $G$ of order $n$.
You (person A) know only the order $n$, 
and that $1$ is the name of the identity element.
The group elements are named $1,2,\ldots,n$ in arbitrary
order, arbitrary except that $1$ is the identity.
You are permitted to make queries of this form to B, who answers truthfully:

Tell me which element $c$ of $G$ is the product (group operation) of elements $a$ and $b$, i.e., $a \circ b =\;$?


Q. How many queries always suffice (and are sometimes needed)
to determine $G$?

This has likely been studied but I must not be using the accepted terminology in
my searches.
As a simple example, how many queries are needed to distinguish between the
two groups of order $4$, $K_4$ and $Z_4$?
I believe that two queries suffice:

$2 \circ 2 =\;$?
$3 \circ 3 =\;$?

This is because in the Klein group, $a^2 = 1$ for all $a$, but in $Z_4$,
only one of the three non-identity elements has a square of $1$.
The first query could (unluckily) yield $2 \circ 2 = 1$, but then the
second query settles it.
Added. By "determine $G$," I mean identify which of the $k$ non-isomorphic
groups of order $n$ is $G$. For example, there are $5$ groups of order-$8$; there are
$14$ groups of order-$16$. The goal of the queries would be to pinpoint which
of these groups is $G$, up to group isomorphism.

REPLY [6 votes]: I can determine the multiplication table of $G$ in at most $n\log_2n$ queries.
Pick an element $g_1\in G\setminus\{1\}$ and compute the values of $g_1\circ h$ for all $h\in G$. This determines the values of $g\circ h$ for all $g\in\langle g_1\rangle$ and $h\in G$. If $\langle g_1\rangle=G$ then we are done. Otherwise, pick an element $g_2\in G\setminus\langle g_1\rangle$ and compute the values of $g_2\circ h$ for all $h\in G$. This determines the values of $g\circ h$ for all $g\in\langle g_1,g_2\rangle$ and $h\in G$. If $\langle g_1,g_2\rangle=G$ then we are done. Otherwise, pick an element $g_3\in G\setminus\langle g_1,g_2\rangle$ and repeat this process until $\langle g_1,\ldots,g_k\rangle=G$.
The total number of queries will be $kn$, where $k$ was the number of $g_j$ required to generate $G$ (perhaps suboptimally). By induction, $\lvert\langle g_1,\ldots,g_j\rangle\rvert\geq2^j$. Then $n\geq2^k$ so $k\leq\log_2n$.