Textbook Notes (280,000)

CA (170,000)

Ryerson (10,000)

ITM (900)

ITM 200 (20)

Vikraman Baskaran (20)

Chapter 2

School

Ryerson UniversityDepartment

Information Technology ManagementCourse Code

ITM 200Professor

Vikraman BaskaranChapter

2This

**preview**shows pages 1-2. to view the full**8 pages of the document.**Chapter 2 – Algorithms and programs

2.1 Problem solving

•Programming is all about solving problems

•Program is just a set of instructions that describe how to solve a particular problem

•It is written in a language that a computer can understand

•There are 4 steps to solve a problem

oUnderstand the problem

oWork out a plan

oSort out the details

oTest and evaluate

2.2 The pizza eater’s problem

•Programming is all about developing plans

•Problem solving is an cyclic process

•First step is to understand the problem

•Rough out the general outline of the solution

•Always test and evaluate your solution

2.3 Algorithms

•Algorithm is a set of instructions for solving a problem

•It consists of the actions to do and the order in which to do them

•An algorithm should at least be

oComplete (cover all the parts)

It shouldn’t be possible to get into a situation where the algorithm does not

tell you what to do

oUnambiguous (there is no doubt about what it does)

www.notesolution.com

Only pages 1-2 are available for preview. Some parts have been intentionally blurred.

Everyone should agree on what each instruction means and the order in

which they are to be carried out – there should be no dispute

oDeterministic (only one possible result)

If the same data is input, the same result should be obtained

For example, tossing a dice is non-determistic, as you get different results

each time

oFinite (it should finish)

When following the algorithm, you should eventually finish and not end

up following instructions for ever

•Some examples of algorithm are

oSet of instructions for getting from one place to another

oA musical score

oA recipe

2.4 Developing algorithms by refinement

•1 solution to the “eat pizza” problem was to make a pizza, using a recipe (ex. algorithm)

from a book of pizza recipes

•When planning an algorithm, you will first express it using instructions at a high level of

abstraction (idea)

•For the pizza recipe, a first attempt might be

oMake the base

oMake the topping

oPut the topping on the base

oCook it

•This algorithm has only 4 instructions, each of which represents a sub-problem of the

original problem

oSo you now have 4 smaller problems to solve, but should be easier to solve

www.notesolution.com

###### You're Reading a Preview

Unlock to view full version

Only pages 1-2 are available for preview. Some parts have been intentionally blurred.

oInstructions are not yet sufficiently detailed to allow a cook to make the pizza by

following them

oThe detailed algorithm is said to be more specific or at a lower level of abstraction

than the original attempt

•When developing a computer program, the “high-level” instructions will probably be

written in pseudocode

•Final modification of the algorithm will be written in the notation of a particular

programming language, and therefore ready to use with a computer

•You need to create a list of ingredients (data) for the algorithm to operate on

Data

•There is a set of items which are operated on by the algorithm

oIn the recipe algorithm, these are the ingredients

oIn computer program algorithm, these will be integers, characters etc

oThese items are the input to the algorithm

Process

•There is a list of instructions which, if carried out will achieve the desired result

Output

•There is an output from the execution of the algorithm

oIn the recipe algorithm, this is the actual pizza

•For example, a program to compute the average (mean) of a set of input numbers might

have

oInput : 2 4 6 8

oOutput : 5

2.5 Subprograms

•Recipe algorithm also illustrates another important feature found in computer programs

which is subprograms

www.notesolution.com

###### You're Reading a Preview

Unlock to view full version