algorithms and data types: introduction dr. andrew wallace phd beng(hons) euring...
TRANSCRIPT
![Page 2: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/2.jpg)
Overview
• Algorithms
• Data types
• Program design
• Writing code
• Testing code
![Page 3: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/3.jpg)
Algorithms
• What is an algorithm?• Set of instructions for calculating / doing something.
• Examples• Sorting• Path finding• Item finding• Controlling
![Page 4: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/4.jpg)
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.
![Page 5: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/5.jpg)
Algorithms
• Time and space complexity• Analysis
• Pseudocode
• Design
![Page 6: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/6.jpg)
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
![Page 7: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/7.jpg)
Data Types
• Integersint nVar;short int nVar;long int lVar;unsigned int lVar;int nArray[nSize];
![Page 8: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/8.jpg)
Data Types
• Floats / doublesfloat fVar;double dVar;long double dVar;
![Page 9: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/9.jpg)
Data Types
• Charchar cVar;signed char cVar;char strArray[nSize];
![Page 10: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/10.jpg)
Data Types
• Voidvoid* pVar;void *pVar;
![Page 11: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/11.jpg)
Program design
• The ideal way:• Customer specification• Program / top level specification• Top level design• Low level design• Implementation
![Page 12: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/12.jpg)
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!!!
![Page 13: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/13.jpg)
Program design
• Top level design• Modelling the system• What data?• What functions / methods?
• How to solve the problem?
![Page 14: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/14.jpg)
Program design
• Top level design• Structured Analysis / Structured design
• Data flow
• Object orientated• Encapsulation
• Agents design• Task orientated
![Page 15: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/15.jpg)
Program design
• Low level design• Function design
• KISS• Does one thing!
• Algorithm design• Pseudocode
![Page 16: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/16.jpg)
Program design
• Program boundary
Program
Input
Output
check
function
![Page 17: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/17.jpg)
Program design
int function (n)check nif error
return errorelse
do something cleverreturn 0
![Page 18: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/18.jpg)
Program design
int function (n)ASSERT(n)do something cleverreturn 0
![Page 19: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/19.jpg)
Writing code
• Hungarian notation
• Block structure
![Page 20: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/20.jpg)
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
![Page 21: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/21.jpg)
Writing code
• Blocks
• { }
• Indentation• if … else• while ..• for …
![Page 22: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/22.jpg)
Testing code
• Does it meet the requirements?• Time constraints• Space constraints
• Does it work (bugs?)
• Usability
![Page 23: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/23.jpg)
Testing code
• Block / function test
• Assembly / integration test
• Customer / validation testing
function function function
Assembly Assembly
system
![Page 24: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/24.jpg)
Testing code
• Static• Asymptotic analysis• Logical proof• checking
• Dynamic• Running the code• debugger
![Page 25: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/25.jpg)
Testing code
• Debugging
• Break points
• Check variables
• Change variables
• Jump in and out of code
• Step through code
• Look at the memory
![Page 26: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se](https://reader038.vdocuments.net/reader038/viewer/2022103022/56649cdf5503460f949a8be6/html5/thumbnails/26.jpg)
Questions?