Answer
Please see the work below.
Work Step by Step
We know that the valence shell electronic configuration of magnesium is $3s^2$ and that of aluminium is $3s^2, 3p^1$.We also know that the valence shell electronic configuration with half filled sub shell are relatively more stable.