Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng...

26
Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng [email protected]

Transcript of Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng...

Page 1: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se.

Algorithms and Data types: Introduction

Dr. Andrew Wallace PhD BEng(hons) EurIng

[email protected]

Page 2: Algorithms and Data types: Introduction Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

Questions?