Use the compound interest formula:
A=P(1+i)^n
A=accumulated amount after n periods (years)
P=principal
i=interest per compounding period
n=number of compounding periods
If the smaller investment catches up to the larger one, then the accumulated amounts would be equal. Therefore by equating the two, we get an equation in which the only unknown is n, the number of periods (years in this case).
5000(1.072)^n=8000(1.054)^n
Solve for n:
(1.072/1.054)^n = 8000/5000
take logs and apply laws of logarithm,
n*log(1.072/1.054) = log(8000/5000)
n=log(8000/5000)/log(1.072/1.054)
I get approximately n=28.
Substitute in above solution to get the exact value.