Lecture Notes IT Unit1 - Mod3 Obj 07-10
Lecture Notes IT Unit1 - Mod3 Obj 07-10
Information Technology –
UNIT 1
Module 03 – Objective 07 - 10
• Explain the concept of an algorithm;
• Identify the necessary properties of ‘well designed’ algorithms;
• Identify ways of representing algorithms;
• Develop algorithms to represent problem solution;
Introducing Algorithms
One main type of problem-solving is algorithmic, i.e. working out all
possible alternative steps towards the problem solution.
An algorithm is a problem-solving strategy that guarantees
that you will arrive at a solution - a precise systematic
method for producing a specified result.
It involves systematically exploring and evaluating all possible solutions
until the correct one if found.
Though time-consuming, an algorithm is a method that always
produces a solution to a problem sooner or later.
Introducing Algorithms
Algorithms generate a correct solution, if you are aware of all the
possibilities - but in real life, that is a big "IF". Often algorithms simply
require too much effort.
This strategy originated in the field of mathematics, where its
application can produce guaranteed solutions. They are, therefore,
well-suited to computers.
Computers can rapidly sort through hundreds, thousands, and
even millions of possible solutions without growing tired or suffering
from boredom.
But algorithms aren’t restricted to computers…
If you've ever baked a cake or followed a recipe of any kind, then you've
used an algorithm. In fact, we use them in every day life:
Some algorithms are learned—arithmetic.
Some we figure out ourselves—looking up a phone number.
Others require written instructions—recipe, assembly
instructions, driving directions.
Here’s an example:
“Suppose that you want to determine your car’s mileage. You probably would
do this by filling the tank and noting your mileage. The next time you get gas,
you note the mileage again, determine the number of miles you drove, and then
divide the miles driven by the amount of gas you put in. The result tells you your
car’s gas mileage, which you generated by using a simple algorithm.”
Importance of Algorithms in Problem-Solving
The algorithm is used in every area of computer science:
It is used to make robots move on Mars, assemble cars and assist with operations.
They are what make it possible for antilock brakes in your car to work
by reacting to your foot on the brake pedal and regulating the automatic pumping of
your brakes to maintain control of the vehicle.
Many algorithms are used in your favourite video games to add realism, make your
characters move, and react to your cat-like movements!
1. Input specified
Data to be transformed during the computation to
produce the output.
Must specify type, amount, and form of data.
2. Output specified
Data resulting from the computation—intended result
It is possible to have no output.
Six Essential Properties of ‘Well-Designed’ Algorithms
3. Definiteness
Specify the sequence of events
Details of each step, including how to handle
errors.
4. Effectiveness
The operations are doable.
Six Essential Properties of ‘Well-Designed’ Algorithms
5. Finiteness
Must eventually stop.
On the left side of the equal sign is the variable, and on the right
side is the expression that performs the computation using
standard mathematical notation.
Algorithm Development – Arithmetic Assignments
The left side is where the result of the computation is held for
further processing.
Developing Algorithms –
Control Structures
Control Structures
The flow of control of an algorithm conforms to one of three control
structures:
Sequence – Sequential statements are executed in order,
one after the other. You don't have to make decisions.
Selection – Selection statements (aka conditional statements) are decision-
making statements that alter the flow of execution in the algorithm,
depending on the conditions that control their execution.
Looping and Iteration – (aka repetitive statements) these statements enable
an algorithm to repeat until a certain condition is met or a count is
reached.
Control Structures
The flow of control of an algorithm conforms to one of three control
structures:
IF carrots are tender crisp and they have been simmering for close to
20 minutes, THEN stop simmering; otherwise keep simmering.
Control Structures – Selection
The second example is where you are to cook the final mixture until the sugar
is dissolved.
Now you can see that there are options in both cases to either continue the
cooking process or stop it.
These are not sequential statements because there are two possible
actions based on an observed condition.
Control Structures – Selection
In pseudocode, there will be two types of conditional statements:
the IF-THEN statement and
the IF-THEN-ELSE statement
which are responsible to selecting the next action to control
the flow of the algorithm, based on the satisfaction of a condition.
Control Structures – Selection
In pseudocode, sequence is In flowcharts, sequence is
expressed as in the following expressed as in the following
illustration: illustration:
IF condition
THEN
process 1
ENDIF
Control Structures – Selection
In pseudocode, sequence can In flowcharts, sequence can
also be expressed as in the also be expressed as in the
following illustration: following illustration:
IF condition
THEN
process 1
ELSE
process 2
ENDIF
Control Structures – Selection
In a flowchart it is most important to indicate which path is to be followed
when the condition is true, and which path to follow when the
condition is false. Without these indications the flowchart is open
to more than one interpretation.
There are two acceptable ways to represent a decision in all of the
structures:
The condition is expressed as a statement and the
two possible outcomes are indicated by True, False.
The condition is expressed as a question and the two
possible outcomes are indicated by Yes, No.
BRAIN CHALLENGE #1
PROBLEM:
An algorithm to express the
A lift remains positioned at the ground logic of controlling a lift:
floor level of a building with the doors
shut whenever it is not in use. When a call START
button is pressed on any floor, the lift REPEAT
Check all buttons
moves to the required floor and the lift UNTIL a button is pressed
doors open. Move to the required floor
Open the doors
STOP
Write an algorithm to express the logic of
controlling the lift.
BRAIN CHALLENGE #3