Professional Documents
Culture Documents
Definition
An algorithm is a finite sequence of step by step
algorithm
input
computer
output
Definition
Problems can be in any form
Business
Get a part from Vancouver to Ottawa by morning Allocate manpower to maximize profit
Life
I am hungry. How do I order pizza? Explain how to tie shoelaces to a five year old child
Algorithms
An algorithm must specify every step completely,
so a computer can implement it without any further understanding An algorithm must work for all possible inputs of the problem. Algorithms must be:
Correct: For each input produce an appropriate output Efficient: run as quickly as possible, and use as little memory as possible more about this later
Storage
Store information
Process
Arithmetic Repeat instructions Branch conditionals
Output
Give information
Representation of Algorithms
Flowcharts
Pseudocodes
Programs
Flowchart
represents an algorithm, showing the steps as boxes of various kinds, and connecting these with arrows
Algorithm 1.1
NAME: SumTimes GIVENS:Num1, Num2 RESULTS: Total, Product DEFINITION: Total & Product := SumTimes(Num1, Num2)
Start SUMTIMES
Finish SUMTIMES
Pseudocode
high-level description of a computer programming algorithm. Pseudo-instructions are phrases written in ordinary natural language that a computer cannot understand. If student's grade is greater than or equal to 60 Print "passed" else Print "failed"
Program
A computer program (also a software program, or just a program) is a sequence of instructions written to perform a specified task for a computer. Computer programming is the iterative process of writing or editing source code. Editing source code involves testing, analyzing, and refining
#include <stdio.h> int main() { printf("Hello world!\n"); return 0; }
Data Types
BOOLEAN (2 bytes) Either True or False
INTEGER (2 bytes) Whole numbers (no decimals)
-32,768 32,767
Data Types
SINGLE (4 bytes) Real numbers
10^30 with 7 significant digits of accuracy
Data Types
DATE (8 bytes) Storage of specific dates
Jan 01, 100 to Dec 31, 9999
Use the * symbol to denote size Some numbers should be defined as strings
Student number, SIN, telephone number We do not perform arithmetic calculations on them
VARIANT (sized by Visual Basic as required) Default type, if type not defined Can be any type and type can vary as code is executing Not to be used