This is very simple as you just need to apply the equation, Distance = Speed * Time.
Distance is same. The onward journey takes 2 hours at an avg speed of 4 mph. So, distance b/w A and B is (4*2) = 8 miles.
TOTAL TIME for the round trip is d/S1 + d/S2 [d is same AND S1 and S2 are speeds of onward and return journeys].
Simplifying,
(S1*d + S2*d)/ S1*S2 = d (S1+S2) / S1*S2
Sub values of d, S1, S2.
8 (4+6) / 4*6 = 80 / 24 = 3.33 hrs OR 3 1/3 hrs
Now,
Avg Speed = Total Distance/Total Time
Total Distance = 8+8 = 16 miles
Total Time = 3 1/3 hrs
Avg Speed = 16 / (3 1/3) = 4.8 mph or 4 4/5 mph
Alternate Method:
There is a cool shortcut to calculate Avg speed for round trip. If you find it confusing, just ignore this method. I find it very handy and easy to approach instead of framing those equations.
In this prob, Avg Speeds are 4 mph and 6 mph.
1) Express the avg speeds in the form of ratios (s1:s2)
4:6 = 2:3 (Totally 2+3 OR 5 parts) ==> Assume this simplified ratio as r1:r2
2) Divide the (difference of Total Avg Speeds) by ratio parts.
(6-4) / 5 = 2/5
3) Now, s1 + (r1*2/5)
4 + (2*2/5) = 4 + 4/5 = 24/5 = 4.8 mph OR 4 4/5 mph