ifthen
package then
\newcommand\tree[2]{\ifthenelse{\equal{#1}{a}}{$\sqrt{#2}$}{Hi}}
actually I mis read your condition so I suppose the full version is
\newcommand\tree[2]{\ifthenelse{\equal{#1}{a}}%
{$\sqrt{#2}$}{\ifthenelse{\equal{#1}{b}}{Hi}{zzz}}}
I think all the answers given so far (including mine above) are not expandable which means that you can't to the test in places like a \write
or \edef
see the \typeout
below. Given your \sqrt
example that probably doesn't matter, but the following is a version using expandable tests that is almost certainly the quickest version posted so far, although rather expensive in terms of command name use.
\documentclass{article}
\makeatletter
\@namedef{tree@a}#1{$\sqrt{#1}$}
\@namedef{tree@b}#1{h1}
\def\tree#1{\expandafter\ifx\csname tree@#1\endcsname\relax
\expandafter\@gobble\else
\csname tree@#1\expandafter\endcsname
\fi}
\makeatother
\begin{document}
\tree{a}{2}
\typeout{[[[\tree{b}{2}]]]}
\tree{b}{xyz}
\tree{x}{Uh!}
\end{document}