\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{{[}deleted{]}} \pdfinfo{ /Title (algorithm-igcse.pdf) /Creator (Cheatography) /Author ({[}deleted{]}) /Subject (Algorithm IGCSE Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{1C5C8C} \definecolor{LightBackground}{HTML}{F0F4F7} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Algorithm IGCSE Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{{[}deleted{]}} via \textcolor{DarkBackground}{\uline{cheatography.com/131013/cs/26251/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}{[}deleted{]} \\ \uline{cheatography.com/deleted-131013} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 22nd January, 2021.\\ Updated 22nd January, 2021.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{x{2.38896 cm} x{2.58804 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Data Types \& Structures}} \tn % Row 0 \SetRowColor{LightBackground} INTEGER (whole numbers) & 1, 2, 45, 231, -2, -213 \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} REAL (decimal numbers) & 1.23, 938.232312, -23.233 \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} STRING (words or sentences) & "Hello World", "123 bipbop" \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} CHARACTER (one character or alphabet) & 'A', 'b', 'Y', 'o', '1', '8', 'd \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} BOOLEAN (true or false) & TRUE, FALSE, TRUE, TRUE \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} ARRAY (many words or numbers) & {[}"Hi", "me not smart", 174, 23, "12 bipbop", -1234{]} \tn % Row Count 15 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Rules: \newline {\bf{INT}} and {\bf{REAL}} are typed as numbers only \newline {\bf{STR}} must be in double quotation marks i.e. "Hello" \newline {\bf{CHAR}} must be in single quotation marks i.e. 'H' \newline {\bf{BOOL}} must be in either TRUE or FALSE \newline {\bf{Array}} can be assigned to variables and must be inside braces. i.e. names = {[}"Andy", "Cindy", "Bobby"{]}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.87657 cm} x{1.09848 cm} x{1.60195 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Operators (Arithmetic)}} \tn % Row 0 \SetRowColor{LightBackground} Operators & Examples & It Will Give \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} + (plus) & 5 + 5 & 10 \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} - (minus) & 8 - 3 & 5 \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} * (multiply) & 6*2 & 12 \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} / (divide) & 8/4 & 2 \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \textasciicircum{} (power) & 2\textasciicircum{}3 & 8 \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} DIV (dividend) & 12 DIV 5 & 2 \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} MOD (modulo) & 10 MOD 5 & 0 \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{5.377cm}}{Note: MOD will give you the remainder of the number} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{3.58344 cm} x{1.39356 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Operators (Assignment)}} \tn % Row 0 \SetRowColor{LightBackground} Operators & Examples \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \textgreater{} (greater than sign) & 100 \textgreater{} 5 \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \textless{} (lesser than sign) & 60 \textless{} 150 \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \textless{}\textgreater{} (not equal sign) & 7 \textless{}\textgreater{} 25 \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} = (equal sign) & 12 = 12 \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{The \textgreater{}= operator means greater than or equal to \newline The \textless{}= operator means lesser than or equal to} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.54287 cm} x{3.43413 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Operators (boolean)}} \tn % Row 0 \SetRowColor{LightBackground} Operators & Examples \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} AND & TRUE AND TRUE = TRUE \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} OR & TRUE OR FALSE = TRUE \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} NOT & NOT FALSE = TRUE \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Boolean Operators are also called Logical Operators. AND means conjunction, OR means disjunction, NOT means negation} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{The FOR Loop}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{FOR LOOP}} \newline {\emph{Use a FOR loop when you know how many times it'll run}} \newline \newline {\bf{The syntax:}} \newline FOR variable = something to something \newline do something \newline NEXT \newline \newline {\bf{The example:}} \newline FOR number = 1 to 3: \newline PRINT number \newline NEXT} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Running this on raptor/ other engines will output: \newline 1 \newline 2 \newline 3} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{REPEAT Loop}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{THE REPEAT LOOP}} \newline {\emph{Use a REPEAT loop when you know how many times it'll run}} \newline \newline {\bf{The syntax:}} \newline REPEAT \newline do something \newline UNTIL something \newline \newline {\bf{The example:}} \newline number = 1 \newline REPEAT \newline PRINT number \newline number = number + 1 \newline UNTIL number = 3} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Running this on raptor/ other engines will output: \newline 1 \newline 2 \newline 3} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{WHILE Loop}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{THE WHILE LOOP}} \newline {\emph{Use WHILE loop when you don't know how many times it'll run}} \newline \newline {\bf{The syntax:}} \newline WHILE something DO \newline do something \newline ENDWHILE \newline \newline {\bf{The example:}} \newline number = 1 \newline WHILE number \textless{} 3 DO \newline PRINT number \newline number = number + 1 \newline ENDWHILE} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{If you put this in raptor/other engines they will output: \newline 1 \newline 2 \newline 3} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Writing An Algorithm Example}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{You are tasked to find out what is the 16\textasciicircum{}th\textasciicircum{} number in the Fibonacci sequence, how do you do it?} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`fib\_0 = 0`\{\{nl\}\}`fib\_1 = 1`\{\{nl\}\}`find\_num = 16`\{\{nl\}\}`FOR i = 0 to find\_num`\{\{nl\}\}`\textasciicircum{}\_\_\_ \textasciicircum{} fib\_2 = fib\_0 + fib\_1`\{\{nl\}\}`\textasciicircum{}\_\_\_ \textasciicircum{}fib\_0 = fib\_1`\{\{nl\}\}`\textasciicircum{}\_\_\_ \textasciicircum{}fib\_1 = fib\_2`\{\{nl\}\}`PRINT "The 16\textasciicircum{}th\textasciicircum{} number is: ", fib\_2`} \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Answer of Output = 987} \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Fibonacci Sequence is a sequence where each number is the sum of the two preceding ones. For example: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Conditional Statements (IF)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Syntax:}} \newline IF condition \newline THEN do something \newline ELSE do something else \newline ENDIF \newline \newline {\bf{Example:}} \newline khaisar\_height = 100 \newline IF khaisar\_height \textless{} 120 \newline THEN PRINT "Please enter the kids room" \newline ELSE PRINT "Please enter the teenagers room" \newline ENDIF} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Description:}} \newline Conditional Statements are IF statements. The IF statement check if a condition is TRUE or FALSE. \newline \newline In the English language, we say: \newline If you come to the party, I'll buy one pizza. \newline \newline In the computer language. We say it like this: \newline IF answer = "YES" THEN pizza = 1 ENDIF \newline As simple as that!} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Extended IF statement}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{IF grade \textgreater{} 90 AND behavior \textgreater{} 80 \newline THEN PRINT "Excellent" \newline ELIF grade \textgreater{} 80 AND behavior \textgreater{} 70 \newline THEN PRINT "Well Done" \newline ELIF grade \textgreater{} 70 AND behavior \textgreater{} 60 \newline THEN PRINT "Good Job" \newline ELSE PRINT "Improvement is needed!" \newline ENDIF} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{IF and ELIF (else if) are used for a choice between several different values. You can either use ELIF or CASE, it is up to you.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{CASE OF}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Syntax:}} \newline CASE ... OF \newline something \newline OTHERWISE something \newline ENDCASE \newline \newline {\bf{Example:}} \newline CASE grade OF \newline 'A' : PRINT "Excellent" \newline 'B' : PRINT "Well Done" \newline 'C' : PRINT "Good Job" \newline 'D' : PRINT "Do Better" \newline 'F' : PRINT "Find Another Answer" \newline OTHERWISE PRINT "Improve next time" \newline ENDCASE} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{CASE is another conditional statement that is use for several different values} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Functions}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{The syntax:}} \newline \newline FUNCTION \seqsplit{do\_something(Parameters)} \newline statements \newline RETURN something \newline END PROCEDURE \newline \newline {\bf{Example:}} \newline \newline FUNCTION \seqsplit{count\_pizza\_slices(number\_of\_pizza)} \newline \seqsplit{number\_of\_pizza\_slices} = 0 \newline \seqsplit{number\_of\_pizza\_slices} = number\_of\_pizza * 8 \newline RETURN \seqsplit{number\_of\_pizza\_slices} \newline END PROCEDURE} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Running this on a engine/idle: \newline count\_pizza\_slices(5) \newline \newline Output: \newline 40} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}