Answer
a) $27.7\;\rm m/s$
b) $22.3\;\rm m/s$, $44.2\;\rm m/s$
Work Step by Step
a)
If your friend throws the ball perfectly horizontal, so the initial vertical velocity component must be zero.
Now we know the ball's initial height, which is 4 m above the ground, its final height, which is the ground, its initial vertical velocity component, and its vertical acceleration which is the free-fall acceleration.
So, the time of the whole trip is given by
$$y_f=y_i +v_{iy}t-\frac{1}{2}gt^2$$
Thus,
$$0=4+0-\frac{1}{2}gt^2$$
$$t=\sqrt{\dfrac{8}{9.8}}=\bf 0.9\;\rm s$$
Now we know the time of the trip and the horizontal displacement, so we can find its initial velocity.
$$v_{i}=v_{ix}=\dfrac{x_f-x_i}{t}=\dfrac{25-0}{0.9}$$
$$\boxed{v_i=\color{red}{\bf 27.7}\;\rm m/s}$$
b) We need to repeat the same steps above but now there is an initial vertical velocity component.
When the initial angle is above or below the horizontal by $\theta$;
$$y_f=y_i +v_i\sin \theta t-\frac{1}{2}gt^2$$
$$0=4+v_i\sin \theta t-\frac{1}{2}gt^2$$
$$-4.9t^2+v_i\sin \theta t+4=0\tag 1$$
Now we need to find the time of the trip in terms of $x$;
$$x_f=x_i+v_{ix}t+\overbrace{\frac{1}{2}a_xt^2}^{0}$$
$$25=0+v_{i}\cos\theta t$$
Thus,
$$t=\dfrac{25}{v_{i}\cos\theta}\tag 2$$
Plugging $t$ from (2) into (1);
$$-4.9\left(\dfrac{25}{v_{i}\cos\theta}\right)^2+v_i\sin \theta \left(\dfrac{25}{v_{i}\cos\theta}\right)+4=0 $$
$$ \dfrac{-4.9\times 25^2}{v_{i}^2\cos^2\theta} +25\tan \theta+4=0 $$
Thus,
$$ \dfrac{-4.9\times 25^2}{v_{i}^2\cos^2\theta} =-25\tan \theta-4 $$
$$ \dfrac{4.9\times 25^2}{\left(25\tan \theta+4 \right)\cos^2\theta} =v_{i}^2$$
Therefore,
$$v_i=\sqrt{ \dfrac{4.9\times 25^2}{\left[25\tan \theta+4 \right]\cos^2\theta} }$$
When the angle is above the horizontal, $\theta=+5^\circ$
$$v_i=\sqrt{ \dfrac{4.9\times 25^2}{\left[25\tan(5^\circ)+4 \right]\cos^2(5^\circ)} }$$
$$\boxed{v_i=\color{red}{\bf 22.3}\;\rm m/s}$$
When the angle is below the horizontal, $\theta=-5^\circ$
$$v_i=\sqrt{ \dfrac{4.9\times 25^2}{\left[25\tan(-5^\circ)+4 \right]\cos^2(-5^\circ)} }$$
$$\boxed{v_i=\color{red}{\bf 41.2}\;\rm m/s}$$