If an amount P is invested for n terms at a rate of interest of r, it grows to P*(1 + r)^n.
Here, the annual rate of interest is 4%, as the compounding is done semi-annually, the effective rate for a term is 4/2 = 2%.
Let the number of terms be n.
We have to solve 8000 = 5000*(1 + 0.02)^n
=> 8/5 = 1.02^n
take the log of both the sides
=> n = log(8/5) / log (1.02)
=> n = 23.73
The term n is in half years, 23.73 terms rounded to the nearest year gives 12 years.
The time taken for the investment to grow to $8000 is 12 years.