What is sample space? Set of all possible outcomes. Right? Here what we are doing is we are drawing one ball at random from the jar which contains 4 red, 3 white, 2 yellow and 20 black balls.
Now the ball I pick can be any of the yellow balls, any of the black balls, any of the red or white balls. It can be any of the 4 + 3 + 2 + 20 = 29 balls. Which means there are 29 possible outcomes and hence my set of sample space will contain 29 elements.