The following is the code and its output. The output doesn't look well. If they are both aligned horizontally by their left and then centered in the frame, it will looks better. But how? (The image is centered in the frame.)
\documentclass{beamer}
\usepackage{algorithm2e}
\begin{document}
\begin{frame}
\begin{center}
\includegraphics[width=0.5\textwidth, height=3cm]{fig4}
\medskip
%\fbox{
\begin{minipage}{0.66\textwidth}
\begin{algorithm}[H]
\DontPrintSemicolon
\KwSty{type} val : \KwSty{real}$[k]$\;
\KwSty{type} ind : \KwSty{int}$[k]$\;
\KwSty{type} ptr : \KwSty{int}$[s+1]$\;
\everypar={\nl}
\For{$d=0$ \KwTo $ptr[d+1]-ptr[d]$}{
\For{$l=0$ \KwTo $ptr[d+1]-prt[d]$}{
$z[l] \leftarrow z[l]+val[prt[d]+l] \cdot x[\textcolor{red}{ind[ptr[d]+l]}]$\;
}
}
\end{algorithm}
\end{minipage}
%}
\end{center}
\end{frame}
\end{document}

