10 Feb 2016

School

Department

Course

Professor

Algorithm

An algorithm is a step-by-step process that will result in a desired outcome.

We get steps and the necessary input in order to resolve the issue by following the steps, and not

necessarily understand how it is being resolved.

A cooking recipe is a good example of this.

We need 3 things for an algorithm.

Input

The algorithm itself

Output

In addition, algorithms must be;

Ordered

Unambiguous

Clear

Automated Process

Clear and defined end – not continuous

In a math equation with variables, the algorithm would be the equation itself. The input would be the

valuables (a,b,c). The output would be the variable we need to find (x).

In order to automate a process for a computer, we need to clarify the task through an algorithm in

the simplest steps possible so that the computer can do the required task without having to work out

how on its own.

Tasks

Sequential Tasks

Steps that are executed in a sequence or in order.

The standard form for sequential tasks is 1?2?3

Another way to represent sequential tasks, or algorithms in general, is on a flow chart.

Example: Finding average kilometres driven in a week.

Input – Start and end KM

Algorithm – Calculate total KM and then average KM

Output – Average KM

1 – Get start KM

2 – Get end KM

3 – Calculate total KM (end KM minus start KM)

4 – Calculate average (total KM divided by 7)

5 – Display average

Conditional Tasks

Steps that are only executed if a condition is true.

Example: A store sells a variety of items with the same price

(2$ each, tax included). The manager offers a 10% discount to

customers who buy 10 or more items per transaction.

Input – Amount of items (8)

Algorithm – Discount cost (10%)