-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: ramona.burger <[email protected]>
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
% Set the Page Layout | ||
\documentclass[12pt]{article} | ||
\usepackage[inner = 2.0cm, outer = 2.0cm, top = 2.0cm, bottom = 2.0cm]{geometry} | ||
|
||
% Package to write pseudo-codes | ||
\usepackage{algorithm} | ||
|
||
% Don't Remove the 'end' at the end of the algorithm | ||
\usepackage{algpseudocode} | ||
|
||
% Manually remove the 'end' for some sections | ||
\algtext*{EndIf} | ||
\algtext*{EndFor} | ||
|
||
% Define Left Justified Comments | ||
\algnewcommand{\LeftComment}[1]{\Statex \(\triangleright\) #1} | ||
|
||
% Remove the Numbering of the Algorithm | ||
\usepackage{caption} | ||
\DeclareCaptionLabelFormat{algnonumber}{Algorithm} | ||
\captionsetup[algorithm]{labelformat = algnonumber} | ||
|
||
% Define the command for a boldface instructions | ||
\newcommand{\Is}{\textbf{ is }} | ||
\newcommand{\To}{\textbf{ to }} | ||
\newcommand{\Downto}{\textbf{ downto }} | ||
\newcommand{\Or}{\textbf{ or }} | ||
\newcommand{\And}{\textbf{ and }} | ||
% Use them inside Math-Mode (Hence the space!) | ||
|
||
\begin{document} | ||
|
||
\begin{algorithm} | ||
|
||
\caption{Searching an element in a sorted array} | ||
|
||
\begin{algorithmic}[1] | ||
\Statex | ||
\Procedure{BinarySearch}{$A$,$l$,$r$,$x$} | ||
\If {$l geq r$} | ||
\State $m \gets \lfloor l + (r-1) / 2) \rfloor$ | ||
\If {$A[m] == x$} | ||
\State \Return $m$ | ||
\EndIf | ||
\If {$A[m] > x$} | ||
\State \Return $BinarySearch(A,l,m-1,x)$ | ||
\Else | ||
\State \Return $BinarySearch(A,m+1,r,x)$ | ||
\EndIf | ||
\EndIf | ||
\EndProcedure | ||
\end{algorithmic} | ||
|
||
\end{algorithm} | ||
|
||
|
||
|
||
\end{document} |