\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 (algorithms-aqa-computer-science.pdf) /Creator (Cheatography) /Author ({[}deleted{]}) /Subject (Algorithms - AQA Computer Science 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}{FF00BB} \definecolor{LightBackground}{HTML}{FFEFFA} \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{Algorithms - AQA Computer Science Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{{[}deleted{]}} via \textcolor{DarkBackground}{\uline{cheatography.com/56036/cs/15730/}}} \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-56036} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 11th May, 2018.\\ Updated 11th May, 2018.\\ 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{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{What is an 'Algorithm'?}} \tn \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{An {\bf{algorithm}} is an unambiguous sequence of steps that can be followed to complete a task. An algorithm is {\emph{not}} a computer program - a computer program is the implementation of an algorithm.% Row Count 4 (+ 4) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.181 cm} x{12.089 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Representing Algorithms}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Key Word}} & {\bf{Definition}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {\bf{Input(s)}} & Data given to an algorithm (e.g. user input to a program). \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{Processes}} & Actions performed during an algorithm. \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} {\bf{Output(s)}} & Data returned by an algorithm. \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{Decomposition}} & Dividing a problem or task into sub-tasks that are easier to accomplish. This makes creating an algorithm quicker and easier. \tn % Row Count 13 (+ 5) % Row 5 \SetRowColor{white} {\bf{Abstraction}} & Removing unnecessary detail from a problem, thus making it easier to solve. \tn % Row Count 16 (+ 3) % Row 6 \SetRowColor{LightBackground} {\bf{Flow Chart}} & A visual representation of an algorithm. \tn % Row Count 18 (+ 2) % Row 7 \SetRowColor{white} {\bf{Pseudocode}} & A way of planning code that bears some resemblance to code, but is not necessarily specific to one particular programming language and would not be able to run. Each programmer has their own way of writing pseudocode. \tn % Row Count 26 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Trace Tables}} \tn \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Trace tables}} are a technique used to manually analyse the output of an algorithm, which helps to determine the algorithm's purpose. Below is an example. \newline % Row Count 4 (+ 4) Algorithm (pseudocode): \newline % Row Count 5 (+ 1) ~~`x = USERINPUT` \newline % Row Count 6 (+ 1) ~~`y = USERINPUT` \newline % Row Count 7 (+ 1) ~~`z = 0` \newline % Row Count 8 (+ 1) ~~`WHILE x \textless{} y` \newline % Row Count 9 (+ 1) ~~~~`x = x + 1` \newline % Row Count 10 (+ 1) ~~`ENDWHILE` \newline % Row Count 11 (+ 1) ~~`z = x + y` \newline % Row Count 12 (+ 1) ~~`RETURN x, y, z` \newline % Row Count 13 (+ 1) Trace Table: \newline % Row Count 14 (+ 1) {\bf{~~x~~~~~~~y~~~~~~~z}} \newline % Row Count 17 (+ 3) ~~2~~~~~~~6~~~~~~~0 \newline % Row Count 19 (+ 2) ~~3~~~~~~~6~~~~~~~0 \newline % Row Count 21 (+ 2) ~~4~~~~~~~6~~~~~~~0 \newline % Row Count 23 (+ 2) ~~5~~~~~~~6~~~~~~~0 \newline % Row Count 25 (+ 2) ~~6~~~~~~~6~~~~~~~12% Row Count 27 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Efficiency of Algorithms}} \tn \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Generally, more than one algorithm can be used to solve a given problem. The one that is usually preferred is the most efficient one. \newline % Row Count 3 (+ 3) Although there are multiple ways of measuring efficiency, the time taken to execute a program is the main one. Obviously, a quicker solution is best (so that no time is wasted), so shorter algorithms are preferred.% Row Count 8 (+ 5) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{For the AQA specification, "exam questions in this area will only refer to time efficiency."} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Searching Algorithms}} \tn \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Searching algorithms}} are procedures used to find a specific item of data in a dataset. \newline % Row Count 2 (+ 2) A {\bf{linear search}} begins at the start of the dataset, then moves through it sequentially, testing every element for a match. This means that it can be used on {\bf{sorted or unsorted}} data and on an array of {\bf{any data type}}. However, if the array is long then a linear search can be quite {\bf{slow}} and take a long time. \newline % Row Count 9 (+ 7) A {\bf{binary search}} requires an {\bf{ordered}} data set, but is generally {\bf{quicker}} than a linear search. It divides a list in half and 'looks at' the middle element (if there is an even number of elements, the first item on the right is examined). If the element is not equal to the desired value, then the algorithm checks whether the element is greater than the desired value. If so, the left-hand side of the list is discarded. If not, the right-hand side is discarded. This is repeated until the correct element is found. \newline % Row Count 20 (+ 11) Both search algorithms {\bf{cannot search for multiple occurences}} of an element in the same data set.% Row Count 22 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Sorting Algorithms}} \tn \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Sorting algorithms}} are procedures used to arrange a data set into an order (usually ascending). \newline % Row Count 2 (+ 2) A {\bf{bubble sort}} starts at the beginning of the data set. It then goes through it sequentially, checking each item against the next one. If the first item is greater than the second one, they are swapped. This is repeated until it reaches the end of the data set. It then makes a second pass, doing the same thing. Once it makes one full pass without making any changes, it terminates because the list is in order. \newline % Row Count 11 (+ 9) A {\bf{merge sort}} starts by dividing the list in half repeatedly, until it is left with individual elements. It then merges these elements into pairs, with the smallest element on the left-hand side. This is repeated until all of the sublists are merged into one, which is now ordered. \newline % Row Count 17 (+ 6) Bubble sorts are {\bf{extremely inefficient}}, whereas merge sorts are {\bf{very fast}}. However, merge sorts need {\bf{additional storage}} because there are many more stages.% Row Count 21 (+ 4) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Bubble Sort}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{17.67cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/danielles_1526007768_bubble-sort-1.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{\seqsplit{http://www.algolist.net/Algorithms/Sorting/Bubble\_sort}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Merge Sort}} \tn \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Image could not be loaded.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{http://www.mcs.anl.gov/\textasciitilde{}itf/dbpp/text/node127.html} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \end{document}