2

I am writing algorithm but it is giving error. Please see the code given below:

\documentclass{beamer} 
\usepackage{algorithm,algorithmic}
\begin{document}
\begin{frame}

\begin{algorithmic}
\STATE $S \Leftarrow (u,1);$
\WHILE{$S \neq \phi $}
\STATE $(u,1) \Leftarrow S ;$
\STATE color[$u$] := gray;
\IF{$k \le $ deg$(u)$};
\STATE $S \Leftarrow (u,k+1);$
\ELSE[$N$ ]
\ENDWHILE
\end{algorithmic}

\end{frame}
\end{document}

Question : How to give numbering to each line?

5

You asked,

How to give numbering to each line?

Since you're using the algorithmic environment, simply change \begin{algorithmic} to \begin{algorithmic}[1] if you want every single line numbered. Use \begin{algorithmic}[2] if only every second line should be numbered, \begin{algorithmic}[5] if only every fifth line should be numbered, etc.

You also have (at least) three syntax errors in the algorithmic code block: (a) a missing \ENDIF statement, (b) missing instruction(s) under the \ELSE branch, and (c) a spurious ; symbol immediately after \IF{...}.

\documentclass{beamer}
\usepackage{algorithm,algorithmic}
\begin{document}
\begin{frame}

\begin{algorithmic}[2] % number every 2nd line
\STATE $S \Leftarrow (u,1);$
\WHILE{$S \neq \phi $}
  \STATE $(u,1) \Leftarrow S ;$
  \STATE color[$u$] := gray;
  \IF{$k \le $ deg$(u)$}
    \STATE $S \Leftarrow (u,k+1);$
  \ELSE[$N$]
    \STATE something;
  \ENDIF
\ENDWHILE
\end{algorithmic}

\end{frame}
\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.