Case (i)
Mass, the FBD is as shown. The equation of motion of the two masses is
For 4 kg mass :mg – T = ma .....(1)
For 5 kg mass T = Ma .....(2)
From (1) and (2) we have


Case (ii)
The 5 kg mass will move downwards and 4 kg upwards. Let T be the tension in the string. Using free body diagram (FBD) we get

