The problem is actually the following. Let $A\subset B$ be a subring and suppose that the subrings $C:=A[b_1,\dots,b_n]$ and $C':=A[b'_1,\dots,b'_m]$ of $B$ are the rings of polynomials in the indicated variables such that $B$ is algebraic over both. Does $m=n$ ?
If "$B$ is algebraic over $C$" means $\forall b\in B\ \ \exists 0\ne g(x)\in C[x]\quad g(b)=0$, the answer is no. Just take $B:=A[b_1,b_2,b']/\text{Ideal}(b_1b',b_2b')$, where $A[b_1,b_2,b']$ is the ring of polynomials in $b_1,b_2,b'$. It is easy to see that the images $C:=A[\overline b_1,\overline b_2]$ and $C':=A[\overline b']$ are rings of polynomials respectively in $\overline b_1,\overline b_2$ and $\overline{b'}$ and that $\overline b_1\overline b_2B\subset C$ and $\overline{b'}B\subset C'$, implying that $B$ is algebraic over both $C$ and $C'$.
If "$B$ is algebraic over $C$" means $B$ is integer over $C$ (i.e., the above polynomial $g$ is always monic), the answer is yes. Here, you will need a bit of knowledge in commutative algebra. (Consult please some book, if necessary, say, "Commutative algebra" by M.F.Atiyah and I.G.Macdonald, the chapter about integer dependence.) You can relpace $B$ by the subring generated by $A$ and $\{b_1,\dots,b_n,b'_1,\dotsb'_m\}$. Let $M\triangleleft_mA$ be a maximal ideal. Then $MC\triangleleft_pC$ is a prime ideal in $C$ and $MC'\triangleleft_pC'$ is a prime ideal in $C'$. By the "going up" theorem, there are prime ideals $P,P'\triangleleft_pB$ such that $C\cap P=MC$ and $C'\cap P'=MC'$. Taking the quotient $B/(P\cap P')$ in place of $B$, you can assume that $A$ is a field. As $B,C,C'$ are noetherian now, it remains to observe that the Krull dimensions of $B$, $C$, and $C'$ coincide, whereas that of $C$ equals $n$ and that of $C'$ equals $m$.