algorithms and data types: introduction dr. andrew wallace phd beng(hons) euring...
TRANSCRIPT
Overview
• Algorithms
• Data types
• Program design
• Writing code
• Testing code
Algorithms
• What is an algorithm?• Set of instructions for calculating / doing something.
• Examples• Sorting• Path finding• Item finding• Controlling
Algorithms
• History• Abū ʿAbdallāh Muḥammad ibn Mūsā al-Khwārizmī
• Brahmagupta 0628 • Algoritmi de numero Indorum.
• Anthyphairesis• Euclidean algorithm
• Euclid's Elements -0299
• Gottfried Wilhelm von Leibniz• Calculus ratiocinator 1680
• Augusta Ada King, Countess of Lovelace 19th Cent.
Algorithms
• Time and space complexity• Analysis
• Pseudocode
• Design
Data Types
• What is a data type?• A way of classifying pieces of information• Useful for computers
• Examples• Primitive
• Integers, reals, boolean(?)
• Composite• Arrays, struct, unions
• Abstract• Stacks, queues, heaps, trees
Data Types
• Integersint nVar;short int nVar;long int lVar;unsigned int lVar;int nArray[nSize];
Data Types
• Floats / doublesfloat fVar;double dVar;long double dVar;
Data Types
• Charchar cVar;signed char cVar;char strArray[nSize];
Data Types
• Voidvoid* pVar;void *pVar;
Program design
• The ideal way:• Customer specification• Program / top level specification• Top level design• Low level design• Implementation
Program design
• Customer specification• From the users point of view• What to do but not how
• Program / top level specification• Technical • What to do but not how!!!
Program design
• Top level design• Modelling the system• What data?• What functions / methods?
• How to solve the problem?
Program design
• Top level design• Structured Analysis / Structured design
• Data flow
• Object orientated• Encapsulation
• Agents design• Task orientated
Program design
• Low level design• Function design
• KISS• Does one thing!
• Algorithm design• Pseudocode
Program design
• Program boundary
Program
Input
Output
check
function
Program design
int function (n)check nif error
return errorelse
do something cleverreturn 0
Program design
int function (n)ASSERT(n)do something cleverreturn 0
Writing code
• Hungarian notation
• Block structure
Writing code
• n – integer nVar
• l – long lVar
• f – float fVar
• d – double dVar
• b – Boolean bVar
• m_ - member m_nVar
• o – Object oVar
• fp, i, j
Writing code
• Blocks
• { }
• Indentation• if … else• while ..• for …
Testing code
• Does it meet the requirements?• Time constraints• Space constraints
• Does it work (bugs?)
• Usability
Testing code
• Block / function test
• Assembly / integration test
• Customer / validation testing
function function function
Assembly Assembly
system
Testing code
• Static• Asymptotic analysis• Logical proof• checking
• Dynamic• Running the code• debugger
Testing code
• Debugging
• Break points
• Check variables
• Change variables
• Jump in and out of code
• Step through code
• Look at the memory
Questions?