I wish to thank both Sarah Sharp and Maurice Abraham for thehelp that they have given me with this book by contributing some usefulsuggestions, proof reading, and helping to check that the examples and answersare correct. In addition, I would like to thank everyone else who hashelped me by making suggestions, giving feedback and encouraging me to embarkon this project.
Introduction
There are a number of topics within mathematics that have adirect relevance to computing and IT. Some of these topics form the basis ofhow a computer processes data, some are used at a higher level to enable aprogram to perform a required function, and others are algorithmic and can beeasily implemented within a computer program. This book attempts to bring together many of thesemathematical concepts and present them in a way that is relevant to those who arestudying, working with or just interested in computing and IT.
Not only is themathematics explained, but it is placed in context. The topics covered by this book include algorithms, flowcharts,recursion, matrices, discrete graphs, sequences, series, searching, sorting,probability, simulation, Venn diagrams, number systems, binary, Booleanalgebra, logic gates, character codes, UTF-8, Hamming Codes, MIME Base64, IPaddresses and Subnetting. Many of these topics are not routinely taught within mathematicalqualifications and could be of interest to mathematicians wishing to discoversomething new. The book includes a combination of explanation, examples,questions, algorithms and codes examples. Simple diagrams are used to helpillustrate certain points and to highlight the values of data when workingthrough a number of steps. Tables of values are provided for ease of referencewhen converting between number systems, referencing character codes values andto help with creating subnetworks.
Examples are used to help demonstrate how to apply themathematics to a given problem and form part of the explanation for each concept.There is a section of questions at the end of each chapter which are intendedto help the reader check that the concepts have been fully understood. Theanswers are in Appendix 3 at the end of the book. Many of the answers are fullyworked through and can be used to give more detail and further explanation tothe concepts within the book. Algorithms are used throughout computing and form the basisof determining how data is processed within an application. Several of thesections use algorithms to explain how a calculation is performed. They aredisplayed using a standard notation which is explained in section 1.2.
Chapter15 contains a number of additional algorithms which may be of interest to thereader. Coded examples are included for some of the topics todemonstrate how the calculations could be implemented within a computerprogram. The examples are in JavaScript. Although there are many differentlanguages which could have been used, JavaScript is relatively easy and quickto use as it can be added into a web page and run using a web browser. The useof JavaScript also complements studies in client-side programming. The section below describes how to run the code examplesusing a web browser.
Alternatively, the JavaScript examples can be run usingthe tool on the resources page of my website www.mathsandcomputing.com. Please note that this book is purely an introduction to thissubject and many of the concepts are described in their simplest form. Thereader may then wish to go and explore a specific topic in more depth.
How to Run The JavaScript Examples
Step 1: Create a Plain Text document containing the HTMLbelow. When naming the document, ensure that the extension is html or htm.
Title
Code Goes Here Step 2: Copy the required coding snippet and paste it in tothe HTML file instead of the text Code Goes Here.
Save the file. Step 3: Find the file and open it using a web browser. Theoutput from the JavaScript will appear as a web page.
1. Algorithms
Section Content
1.1 Introduction to Algorithms
An
algorithm is a series of steps that is used towork out the results of a given problem. It usually requires at least one
inputand must also produce an
output.
By creating an algorithm for a mathematical calculation orcomputational process, it is possible to write a computer program which usesthe algorithm to process and output the required results from given data. Many of the concepts in this book are explained using analgorithm. There are also examples of how code snippets can be written todemonstrate how the concept can be incorporated into a computer program.
Defining an algorithm
Algorithms are defined in terms of input, output, processes,decision points and loops.
Input
Algorithms require initial data values to be input. Incomputing terms, this could be through user entry, by data being read from afile or database, or by using the output from a previous process in a computerprogram
Output
Within an algorithm, there are points when some of thecurrent data values need to be output.
Frequently, this is just the final valueat the end of the algorithm. In computing terms, this could be by displayingthe output values on the screen, printing them out, storing them in a file ordatabase, or by passing them on to another process in a computer program.
Process es
Processes are specific actions or tasks which the algorithmrequires to be performed and usually consists of some type of calculation orfunction being performed on the data.
Decision
A decision is required if the subsequent processes that thealgorithm needs to perform vary depending on the current data values. This isusually done using an
if statement together with the condition whichneeds satisfying.