Hello guys i am new to LaTeX, i have written an algorithm in algorithm environment which is as follows:

```
\documentclass{report}
\usepackage{amsmath}
\usepackage{algorithm}
%\usepackage[noend]{algpseudocode}
\usepackage{algpseudocode}
\begin{document}
\makeatletter
\def\BState{\State\hskip-\ALG@thistlm}
\makeatother
\begin{algorithm}
\caption{Reduct Construction Algorithm}\label{euclid}
\begin{algorithmic}[1]
\Procedure{Reduct Construction}{}\newline
\textbf{Input:} Three matrices based on indiscernibility, discernibility and equal to one relations.\newline
\textbf{Output:} Reducts (sentences)
\State {{\text{\,\,\,\,\,} \textbf{for} i = 2 to n \text{\,\,\,\,\,}}
\State {{\text{\,\,\,\,\,\,\,\,} \textbf{for} j = 1 to n-1 \text{\,\,\,\,\,\,\,\,}}
\State {\text{\,\,\,\,\,\,\,\,\,\,\,} \textbf{if}$M(i,j) \neq \phi$ \text{\,\,\,\,\,\,\,\,\,\,\,}\textbf{then}
\State {{\text{\,\,\,\,\,} \textbf{for} every non-empty element M(i`,j`) \in B \text{\,\,\,\,\,}}
\State {{\text{\,\,\,\,\,\,\,\,} \textbf{if} $M(i`,j`)\subset M(i,j)$ \text{\,\,\,\,\,\,\,\,}\textbf{then}}
\State {{\text{\,\,\,\,\,\,\,\,\,\,\,\,\,\,} $M(i,j) = M(i`,j`)$ \text{\,\,\,\,\,\,\,\,\,\,\,\,\,\,}}
\State {{\text{\,\,\,\,\,} Divide M(i,j) into two parts\text{\,\,\,\,\,}}
\State {{\text{\,\,\,\,\,} \textbf{Select} an attribute a from M(i,j); \text{\,\,\,\,\,}}
\State {{\text{\,\,\,\,\,} $A = M(i,j)-\{a\}$ \text{\,\,\,\,\,}}
\State {{\text{\,\,\,\,\,} $M(i,j)=\{a\}$ \text{\,\,\,\,\,}}
\State {{\text{\,\,\,\,\,} Simplify every non empty element in B \text{\,\,\,\,\,}}
\State {{\text{\,\,\,\,\,} \textbf{if} {$a \in M(i`,j`)$} \text{\,\,\,\,\,}\textbf{then}
\State {{\text{\,\,\,\,\,\,\,\,\,\,\,} $M(i`,j`)=\{a\}$ \text{\,\,\,\,\,\,\,\,\,\,\,}}
\State {{\text{\,\,\,\,\,} \textbf{Else} \text{\,\,\,\,\,}}
\State {{\text{\,\,\,\,\,} $M(i`,j`) = M(i`,j`)- A$ \text{\,\,\,\,\,}}
\end{algorithmic}
\end{algorithm}
\end{document}
```

the packages i am using are:

```
\usepackage{amsmath}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
```

there are alot of errors, although the visuallization is correct but when i run first time no pdf is generated on run time which is pathetic, the errors are

```
Package algorithmicx Error: Some blocks are not closed!!!. \end{algorithmic}
Missing } inserted. \end{algorithmic}
Missing \endcsname inserted. \Procedure
Missing $ inserted. ...{for} every non-empty element M(i`,j`) \in
Extra }, or forgotten $. ... element M(i`,j`) \in B \text{\,\,\,\,\,}}
```

i've tried to correct them but failed, any help correcting these errors would be helpful, thanks

## Best Answer

You're misusing the tool:

I'm not sure the realization is exactly what you have in mind, but it should be easy to adjust it.

Note that math symbols should always be between

`$`

signs. For priming a symbol, use an apostrophe`'`

, not a backquote```