189 views

Uploaded by rodwellhead

Big O Notation in Computing

save

- Computer Fundamentals
- Ibps Computer Awareness Study Material
- intro ch 01blooking inside the computer system
- Concepts of IT Quiz
- Computer New Questions
- Computer Awareness
- Intro to computer ch3
- Revised DOEACC A Level SYLLABUS
- barrios kelly
- SBI Marketing & Computers
- folleto ingles
- Intro Ch 01A
- SECTION A
- Intro Ch 01B
- Towards the Unification of RAM to Non
- BPLec1
- Computer Hardware
- 108week2
- Case Study
- Basic Computer Concepts - Computer Basics
- David I. Schneider-An Introduction to Programming Using Visual Basic 2005-Pearson_Prentice Hall (2006)
- CT Syllabus
- 0137048920 pp5
- Intro Comp Jun 2012
- Fundamentals of Computer Studies
- 0611mayth
- 2.Computers and the Internet
- Computer Science and Information Technology
- Computer Terminology--Types of Computers
- Satellite A205-S4577 Datasheet
- gls_bas
- Computation of the Discrete Forms of the Laplace Integral Operators
- GLS_T.FOR
- The Laplace Integral Operators
- Representation of a Surface by Triangular Panels
- Numerical Solution of a General Linear System of Equations.pdf
- gls.xls
- REGLS.FOR
- Outline of the Boundary Element Method
- GLS.FOR
- Discretization of the Laplace Integral Operators
- Representation of a 2D Line by Straight Line Elements
- Boundary Representation in the Boundary Element Method
- Representation of an Axisymmetric Surface by Conical Panels
- regls_bas
- glt7.bas
- GEOM3D.FOR User Guide
- Approximation of Integrals Over Rectangular Regions
- GLT7.FOR
- Polynomial Test Problems for Quadrature Rules on the Standard Triangle
- GL8.FOR
- GL8TESTS.FOR
- gl8tests.bas
- gl8.bas
- Geometry codes in matlab
- GLT7TESTS.FOR
- GEOM.xlsm User Guide
- GEOM2D.FOR User Guide
- glt7tests.bas
- CLUTESTS.FOR

You are on page 1of 5

uk

**Big O Notation in Computing
**

In computer science it is important to have a measure of the computer memory requirements and the processing time of computer codes. However, the means of storage may be altered and different computers run at different speeds and the purpose of O notation is that it is a means of abstracting the performance of a computer programming technique from its environment. Big O notation is also used in mathematics in a similar way, where it can model the asymptotic (or limiting) behaviour of a function either at a point (often zero) or at infinity1. In computing big O notation is normally used to give a concise representation of the space (memory) or processing time requirements of an algorithm or computer code, as the amount of data that is handled gets large or (theoretically) approaches infinity. Computer codes can be analysed so that often a functional representation of its space and time requirements can be determined2. Computers are a means or storing and manipulating data. Data is stored in data structures3 and data is manipulated by algorithms4. Data structures require computer memory for their storage (eg RAM (random access memory) or hard drive) and algorithms take time to execute. For many computing tasks we do not need to concern ourselves with the storage requirements or the execution time since much everyday personal computing can be easily stored and the execution times are not noticeable. However, there are many occasions in computing where we need to be aware of the storage requirements – since we may exceed the (finite) memory capacity of the computer – and aware of the computing time – since the user may need to know how long to wait for the solution to a problem. In this document we analyse space and time requirements of algorithms from samples of code. From this a computer scientist can select or develop algorithms and data structures with a view to solving a problem within the constraints of the computer system, or select a computer system that can sustain the developed code. If we think of a computer program that handles n items, where n is simply a number that is most representative of the storage or execution time requirements of the software. For example a banking program may have n accounts, a university database may have n students. The following diagram gives a simple illustration of a computational process. N items input Process requiring computer memory and execution time output

Modern computers have RAM measured in megabytes (MB) or gigabytes (GB), hard drives measured in gigabytes (GB) or terabytes (TB) and the central processing unit’s speed is measured in megahertz (MHz) or gigahertz (GHz), meaning that they can compute millions or billions of basic instructions per second. For small values of n the storage requirements and the computer processing time is likely to be insignificant on modern computers. However, this may not be the case for large values of n. For example a typical bank could have around ten million accounts: how would a computer system cope with such demands on it? Every int, float or “object” etc declared in a program requires memory for storage (RAM)

**Big O Notation in Mathematics Space and Time 3 Data Structures 4 Algorithms
**

1 2

www.computing.me.uk

Where does the demand for ‘space’ or computer memory arise and why does the computer require ‘time’ to complete an operation? When a computer program is run the data structures and their components (eg ints, floats, arrays) require memory for storage (usually RAM). Every basic computer operation such as addition, multiplication and comparison takes a fragment of time to complete. Computer memory or space is allocated when a computer program declares a data structure and time is required when an algorithm is implemented. Those responsible for software design or computer specification will normally show an interest in the storage and execution time requirements of computer programs. However, they will not be particularly interested in an exact specifications. For example if we knew that a process required 3.261785 GB and it would require 5.362945 seconds to run then it is of little interest to include the information after the decimal points. Rather it is sufficient to obtain an estimate or simple formula which approximates or indicates the storage requirements and execution time. The following table shows the memory required to store data types. The examples given are from c or Java, but they are very similar across computer programming languages. Data type boolean char int float double Storage (bytes) 1 (1 bit usually stored in a byte) 1 or 2 4 4 8

A byte is made up of 8 bits and a bit is a variable that can only take one of two values ‘0’ or ‘1’. A kilobyte is 1024 (ie 210) bytes, a magabyte is 1024 kilobytes, a megabyte is 1024 kilobytes and a terabyte is 1024 gigabytes. The operations of a computer take place in the central processing unit (CPU) or ‘chip’. All computer operations, such as multiplying integers or adding floating point numbers are broken down into simpler operations that can be directly executed by the CPU. These operations are measured in ‘cycles’ such as the ‘fetch and execute cycle’. The speed of the CPU is measured by the number of cycles that it can execute in each second or hertz (Hz). A kilohertz (KHz) is 1000Hz, a megahertz (MHz) is 1000KHz and a gigahertz (GHz) is 1000 MHz. Computers can include a number of CPUs, so that the computer is able to carry out a number of computations simultaneously, sometimes referred to as parallel processing. The measurement of the space or time requirements can vary from being very simple to be rather complicated. To get things started, we will begin with a simple example program for finding the average (arithmetic mean)5 of a set of data written in pseudo-code.

5

Measures of Average, Centre or Central Tendency

www.computing.me.uk

Pseudocode for computing the average of ‘n’ pieces of data data [n] total=0.0 for i=1..n { total=total+ data[i] } average=total/n

Let us first look at the data storage requirements. There is an array of data of length n and variables called total, i, and average. Let us assume that data is a float array and hence its size is 4n bytes6. If the variables total and average are also of the float data type and i is an int then this requires another 12 bytes. Hence the total memory requirements for the data structures in this code can be estimated at 4n+12 bytes. Let us now consider the execution time for this code. Time will be required for the general housekeeping, setting up the data structures and initialisation. Looking outside of the for loop, there are assignments and a division. Let the work outside of the for loop take time T and this will be largely independent of n. If we now consider the loop then clearly the piece of code within the loop needs to be executed n times. Let t be the time taken for each iteration of the loop and hence the completion of the execution of the loop will takes a time of nt. Hence the total time for the execution of this piece of code is nt+T. The following sketches of graphs7 of the memory requirements and the processing time of the code above are given below.

Memory (bytes) 12 0 0 gradient =4 Processing time T 0

gradient =t

n Space

0

n Time

From a computing point of view, these graphs can help estimate memory requirements and computer time for any value of n. In the case of the code for finding the average of a set of n pieces of data the graph of memory requirements and computer processing time are both straight line graphs. Both graphs show a ‘growth’ with n, which indicates that for ‘large’ values of n that some threshold may be reached. For example we may not have sufficient memory to store the data structures or the computer time may be too long to wait for a computer to process some data, as illustrated in the following extensions of the above graphs.

6 7

Arrays Plotting a Graph

www.computing.me.uk

Memory (bytes) maximum memory

Processing time maximum time

nS Space

n

nT Time

n

In the practical circumstances of running the code on a computer there are limits on n the number of items of data. As illustrated in the graphs above, n≤nS in order to fit in the finite space and n≤nT in order that the time taken for the process is acceptable. This is the case with all computer codes. Computer scientists are therefore very interested in the nature of the graph of memory requirements and computer processing time with respect to the size of the data that is to be managed. In order to illustrate this further we will consider the following fragment of code for computing the average of a set of data stored in a square array. Pseudocode for computing the average of ‘n2’ pieces of data data [n][n] total=0.0 for i=1..n { for j=1..n { total=total+ data[i][j] } ) average=total/n/n If we analyse the data requirements in this code then is an array of data with n2 components and variables called total, i, j, and average. Using the same assumptions about types as in the previous code then the data structures in this code can be estimated at 4n2+16 bytes. If we analyse the data requirements then let us assume that the code within the innermost loop takes a time u and the code outside the loops and the set-up time is U, then the total time for the code can be estimated as n2u+U. The following graphs illustrate how space and time requirements o the code vary with n.

www.computing.me.uk

The graphs show that in the case of this latest code that the growth in both space and time with respect to n is stronger than in the first code. In general the stronger the growth in either space or time the more concerned that computer scientists will be about its viability. In the two examples the graphs of space and time have similar shapes. However, this is not normally the case and space and time should be analysed independently. In the following graphs, typical function that crop up in algorithm and data structure analysis are graphed. The graphs have been scaled for illustrative purposes. However, the most important area to focus on in these graphs is their growth, for it is the growth in the curve that will have the significant impact when n is large.

~ n!

~2n ~n3 ~n2 ~n ~log(n)

In the graphs we consider the factorial function (n!)8, logarithmic and exponential functions9 as well as powers of n. For these functions, in terms of ‘growth’ we note that the factorial function is the most powerful, followed by the exponential and then the descending powers of n. The logarithm of n has the weakest growth.

8 9

Factorial Logarithm and Exponential Functions

- Computer FundamentalsUploaded byromeofatima
- Ibps Computer Awareness Study MaterialUploaded byparvejk
- intro ch 01blooking inside the computer systemUploaded byapi-247714257
- Concepts of IT QuizUploaded byeshwariee
- Computer New QuestionsUploaded bysaurabhsuman2735
- Computer AwarenessUploaded byjairaj321
- Intro to computer ch3Uploaded byawais4u177
- Revised DOEACC A Level SYLLABUSUploaded byharvinder thukral
- barrios kellyUploaded byapi-239279585
- SBI Marketing & ComputersUploaded byapi-19621192
- folleto inglesUploaded byJohana Salazar
- Intro Ch 01AUploaded byirfan900
- SECTION AUploaded bymunny_2957471
- Intro Ch 01BUploaded byapi-3831049
- Towards the Unification of RAM to NonUploaded byJesusMercadoVidal
- BPLec1Uploaded bym150
- Computer HardwareUploaded byToche Doce
- 108week2Uploaded bybobbyhandsome
- Case StudyUploaded byzyrkz
- Basic Computer Concepts - Computer BasicsUploaded byIAn JoSeph VeLasco
- David I. Schneider-An Introduction to Programming Using Visual Basic 2005-Pearson_Prentice Hall (2006)Uploaded byManonVastine
- CT SyllabusUploaded byTammy Gya
- 0137048920 pp5Uploaded byapi-283916373
- Intro Comp Jun 2012Uploaded byAmir Fareez
- Fundamentals of Computer StudiesUploaded byADEBISI JELEEL ADEKUNLE
- 0611maythUploaded byMildred C. Walters
- 2.Computers and the InternetUploaded byforeveronline
- Computer Science and Information TechnologyUploaded byRajesh Bethu
- Computer Terminology--Types of ComputersUploaded byJonalyn Manangan
- Satellite A205-S4577 DatasheetUploaded bygnoqui

- gls_basUploaded byrodwellhead
- Computation of the Discrete Forms of the Laplace Integral OperatorsUploaded byrodwellhead
- GLS_T.FORUploaded byrodwellhead
- The Laplace Integral OperatorsUploaded byrodwellhead
- Representation of a Surface by Triangular PanelsUploaded byrodwellhead
- Numerical Solution of a General Linear System of Equations.pdfUploaded byrodwellhead
- gls.xlsUploaded byrodwellhead
- REGLS.FORUploaded byrodwellhead
- Outline of the Boundary Element MethodUploaded byrodwellhead
- GLS.FORUploaded byrodwellhead
- Discretization of the Laplace Integral OperatorsUploaded byrodwellhead
- Representation of a 2D Line by Straight Line ElementsUploaded byrodwellhead
- Boundary Representation in the Boundary Element MethodUploaded byrodwellhead
- Representation of an Axisymmetric Surface by Conical PanelsUploaded byrodwellhead
- regls_basUploaded byrodwellhead
- glt7.basUploaded byrodwellhead
- GEOM3D.FOR User GuideUploaded byrodwellhead
- Approximation of Integrals Over Rectangular RegionsUploaded byrodwellhead
- GLT7.FORUploaded byrodwellhead
- Polynomial Test Problems for Quadrature Rules on the Standard TriangleUploaded byrodwellhead
- GL8.FORUploaded byrodwellhead
- GL8TESTS.FORUploaded byrodwellhead
- gl8tests.basUploaded byrodwellhead
- gl8.basUploaded byrodwellhead
- Geometry codes in matlabUploaded byrodwellhead
- GLT7TESTS.FORUploaded byrodwellhead
- GEOM.xlsm User GuideUploaded byrodwellhead
- GEOM2D.FOR User GuideUploaded byrodwellhead
- glt7tests.basUploaded byrodwellhead
- CLUTESTS.FORUploaded byrodwellhead