0% found this document useful (0 votes)
6 views

Session 8 - Algorithms

Uploaded by

Brian Were
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Session 8 - Algorithms

Uploaded by

Brian Were
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

SESSION EIGHT

INTRODUCTION TO ALGORITHMS

1.1 Introduction to Algorithms


1.2 Summary

1.1 Introduction to Algorithms

Programming languages are used to communicate explicit instruction


between human beings and computer systems. These explicit instructions
which are often expressed in a computer implementable notation are called
algorithms.

Definition

Algorithm is a sequence of logical instructions for carrying


out a task.

Algorithms can be represented as pseudocode or a flowchart, and


programming is the translation of these into a computer program.

Definition

1 Pseudocode - also written as pseudo-code. A method of


writing up a set of instructions for a computer program
using plain English. This is a good way of planning a
program before coding.

2 Flowchart - a diagram that shows a process, made up of


boxes representing steps, decision, inputs and outputs.

Please note this two methods will be covered in depth in


another session.

1
Example of an algorithm and pseudocode is given below:

Problem: A cinema is offering discount tickets to anyone who is under 15.


Create an algorithm to represent the stated problem.

Solution: Decomposing this problem, gives this algorithm:

1. find out how old the person is


2. if the person is younger than 15 then say “You are eligible for a discount
ticket.”
3. otherwise, say “You are not eligible for a discount ticket.”

In pseudocode, the algorithm would look like this:

OUTPUT "How old are you?"

INPUT User inputs their age

STORE the user's input in the age variable

IF age < 15 THEN

OUTPUT "You are eligible for a discount."

ELSE

OUTPUT "You are not eligible for a discount."

To convert the flowchart or pseudocode into a program, look at each individual


step, and write an equivalent instruction. Sometimes the steps will not match
exactly, but they will be fairly close.

In a flowchart, this algorithm would look like this:

2
1.2 Summary

This session introduced you to algorithms. We have seen that there are two
ways of representing an algorithm namely; pseudocode and flowchart. In the
next session we shall look at each format in details.

You might also like