2

I would like to write pseudo code algorithm in Latex as in the attached picture.I have written code to make just like above algorithm but its not working for me. Is this code correct...

enter image description here

\IncMargin{1em}
 \begin{algorithm}
\SetKwInOut{Part 1}{input}
\SetKwInOut{Part 2}{output}
\Part 1{}
\BlankLine
\emph{abcdefgh $D$ ijklmnop}\;
\emph{ abcdefgh $A$}\;
\For{$k\leftarrow 1$ \KwTo $M$}{
            \For {each $m$ $ ∈ $ {1, 2, …, J}{
                \emph{ abcdefgh $D$}\;
                \emph{abcdef }\;
}
\Part 2{}
\emph{abcdefgh $A$ ijklmnop}\;
\emph{ abcdefgh $A$}\;
\For {each $m$ $ ∈ $ {1, 2, …, J}{
\emph{ abcdefgh $D$}\;
\emph{abcdef }\;
\emph{abcdef }\;
}
}
\For{$k\leftarrow 1$ \KwTo $M$}{
\emph{ abcdefghklmop}\;
\emph{ abcdefghklmop}\;
\emph{ abcdefghklmop}\;
}
\caption { Algorithm Sample}
\end{algorithm}
 \DecMargin{1em}
1

The following is more in line with the regular syntax of algorithm2e:

enter image description here

\documentclass{article}

\usepackage{amsmath}
\usepackage[ruled,vlined]{algorithm2e}
\DontPrintSemicolon
\newcommand{\To}{\mbox{\upshape\bfseries to}}

\begin{document}

\begin{algorithm}
  \caption{Algorithm sample}
  \textbf{Part 1}\;
  \nl abcdefgh $\{ D_i \}_{i = 1}^M$ ijklmnop\;
  \nl abcdefgh $A_m$\;
  \nl \For{$K = 1$ \To{} $M$}{%
    \ForEach{$m \in \{1, 2, \dots, J\}$}{
      abcdefgh $\{ D \}_m^t$\;
      abcdefgh\;
    }
    \textbf{Part 2}\;
    abcdefgh $\{ G_i \}_{i = 1}^K$\;
    abcdefgh $D_m$\;
    \ForEach{$m \in \{1, 2, \dots, J\}$}{
      abcdefgh $\{ G \}_m^y$\;
      abcdefgh\;
      abcdefgh\;
    }
  }
  \nl \For{$K = 1$ \To{} $M$}{
    abcdefghijklmno\;
    abcdefghijklmno\;
    abcdefghijklmno\;
  }
\end{algorithm}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.