[Tex/LaTex] How to write algorithm like this in latex

algorithms

I want to write an algorithm in a latex. There are various ways to write, but I want to write in the way given below. I have tried but I am not able to do anything similar to the given in the image.

enter image description here

see my code:

\documentclass{article}
\usepackage[utf8]{inputenc}   

\begin{document}

Algorithm \\

Input : 

Output : \\

1. $T \leftarrow $ an set of size $S$ \\
2. \textbf{if} $x = 0$\\

3. \hspace{1cm} \textbf{return}

\end{document}

Question : Some of the problems, I am facing are the color of the background, line numbering, spacing etc

Best Answer

based on nice @CaptainNabla answer:

\documentclass{article}
\usepackage{geometry}
\usepackage{enumitem}
\usepackage[framemethod=tikz]{mdframed}

\usepackage{lipsum}
\begin{document}

\begin{mdframed}[hidealllines=true,backgroundcolor=gray!20]
\parindent=0pt
\parskip=2pt  % <-- gives more spaces between paragraphs

\underline{\textsc{ALLSUBSETSUMS}$^\#(S,u)$:}

\medskip      % for additional vertical space 
 \textsf{INPUT:} A set $S$ of $n$ positive integers and an upper bound integer $u$.

\textsf{OUTPUT:} The set of all subset sums with cardinality information of $S$ up to $u$.
\begin{enumerate}[nosep]
    \item \textbf{if} $S=\{x\}$
    \item \hspace{1cm} \textbf{return} $\{(0,0),(x,1)\}$
    \item $T \leftarrow$ an arbitrary subset of $S$ of size $[n/2]$
    \item \textbf{return} \textsc{ALLSUBSETSUMS}$^{\#}(T,u)\bigoplus_u$\textsc{ALLSUBSETSUMS}$^{\#}(S\setminus T,u)$
\end{enumerate}
\end{mdframed}

\lipsum[1]

\end{document}

gives:

enter image description here

Related Question