fix: Remove unnecessary if in Search[While] algorithm

This commit is contained in:
Samuel Ortion 2024-03-08 08:00:05 +01:00
parent d417d52d76
commit 9c743d6484
3 changed files with 28 additions and 33 deletions

View File

@ -34,12 +34,9 @@
\caption{Search an element in an array using a while loop (bis)}
\begin{algorithmic}[1]
\Function{Search}{A: Array(n), E: element}
\Comment{Version prefered by the professor}
\Comment{Version ``preffered" by the professor}
\State $i \gets 0$
\While {$i < n$ and $A[i] \neq E$}
\If {A[i] $ = $ E}
\State \Return \True
\EndIf
\State $i \gets i + 1$
\EndWhile
\If {$i = n$}
@ -100,21 +97,21 @@
\State $i \gets 0$
\State $j \gets 0$
\While {$i < n$}
\If{$S[i] = M[i]$}
\State $i \gets i + 1$
\State $j \gets j + 1$
\EndIf
\If {$j = m$}
\State $c \gets c + 1$
\State $j \gets table[j-1]$
\ElsIf {$j < n$ and $M[j] \neq S[i]$}
\If {$j \neq 0$}
\State $j \gets table[j-1]$
\Else
\State $i \gets i + 1$
\EndIf
\EndIf`
\EndWhile
\If{$S[i] = M[i]$}
\State $i \gets i + 1$
\State $j \gets j + 1$
\EndIf
\If {$j = m$}
\State $c \gets c + 1$
\State $j \gets table[j-1]$
\ElsIf {$j < n$ and $M[j] \neq S[i]$}
\If {$j \neq 0$}
\State $j \gets table[j-1]$
\Else
\State $i \gets i + 1$
\EndIf
\EndIf`
\EndWhile
\State \Return $c$
\EndFunction
@ -123,18 +120,18 @@
\State $previous \gets 0$
\State $table \gets $ array of zeros of size m
\For {$i = 0$; $i < m$; $i++$}
\If {$M[i] = M[previous]$}
\State $previous \gets previous + 1$
\State $table[i] \gets previous$
\State $i \gets i + 1$
\Else
\If {$previous = 0$}
\State $previous \gets table[previous - 1]$
\Else
\State $table[i] \gets 0$
\State $i \gets 1$
\EndIf
\EndIf
\If {$M[i] = M[previous]$}
\State $previous \gets previous + 1$
\State $table[i] \gets previous$
\State $i \gets i + 1$
\Else
\If {$previous = 0$}
\State $previous \gets table[previous - 1]$
\Else
\State $table[i] \gets 0$
\State $i \gets 1$
\EndIf
\EndIf
\EndFor
\EndFunction
\end{algorithmic}

BIN
main.pdf

Binary file not shown.

View File

@ -80,8 +80,6 @@
\input{content/chapters/include}
\chapter{}
% \input{content/conclusion}