[Tex/LaTex] Algorithmic package in LaTeX

algorithms

I want to write the following algorithm in LaTeX:

 V <- AllUnigramsInTraining(D)
 N <- NumberOfTweets(D)
**for** each c ∈ C do
  Nc <- Number of tweets in Class c
  prior(c) <- [...] 
  Tweetsc <- All Tweets in class c
  **for** each term t ∈ V do
    Tct <- No. of times term t appeared in Tweetsc
  **end for**
  **for** each term t ∈ V do
    prob[t][c] <- [...] 
  **end for**
**end for**

I wrote the following code but it is not compiling properly. Can anybody help?

\begin{algorithmic}
\STATE $V\gets AllUnigramsInTraining(D)$ \\
\STATE $N\gets NumberOfTweets(D)$ \\
 \FOR each $c \in C$ \DO \\
  \STATE $N_c\gets Number of tweets in Class c$ \\
  \begin{equation}
    prior(c) = \frac{N_c}{N} \\
   \end{equation}
  \STATE $Tweets_c\gets = All Tweets in class c$ \\
  \FOR each term $t \in V$ \DO \\
    T_ct = No. of times term t appeared in Tweets_c \\
  \END
  \FOR each term $t \in V$ \DO \\
    \begin{equation}
     $prob[t][c] = \frac{T_ct}{\sum_^t'{T_ct'+ 1}} \\
    \end{equation}
  \END
\END
\end{algorithmic}

Best Answer

There is so much wrong there. You don't need \\ at the end of lines for starters. You have an (unbalanced) inline math $ inside of an equation. You have subscripts outside of math mode. Your sum notation has problems. I don't know what you want exactly, but this should at least give you output, whether it's exactly what you want... I don't know.

\documentclass{article}
\usepackage{algorithmic}
\begin{document}
\begin{algorithmic}
\STATE $V\gets$ AllUnigramsInTraining($D$)
\STATE $N\gets$ NumberOfTweets($D$)
 \FORALL{$c \in C$}
  \STATE $N_c \gets$ Number of tweets in Class $c$
  \STATE \begin{equation}prior(c) = \frac{N_c}{N}\end{equation}
  \STATE $Tweets_c \gets $All Tweets in class $c$
  \FORALL{$t \in V$}
    \STATE $T_ct$ = No. of times term $t$ appeared in $Tweets_c$
  \ENDFOR
  \FORALL{$t \in V$}
    \STATE \begin{equation}prob[t][c] = \frac{T_ct}{\sum^{t'}T_ct'+ 1}\end{equation}
  \ENDFOR
\ENDFOR
\end{algorithmic}
\end{document}