Vous êtes sur la page 1sur 21

Algorithms - Intro

Steps to a Solution
What is an Algorithm?

During your professional careers you will be


given different computer related problems to
solve

This will often result in the development of an


Algorithm

a well defined procedure to solve your problems or


accomplish tasks in a limited number of steps.

In many cases, the algorithms involve repeating the


same steps which are very precise and can be
carried out by a computer.
What is an Algorithm?
An algorithm lists the steps involved in
accomplishing a task

It can be defined in programming terms as


a set of detailed ordered instructions..
developed to describe the processes
necessary
to produce the desired output from a given
input
What is an Algorithm?
In todays world the meaning of the
algorithm is also similar to method,
recipe, process, procedure,
technique, routine etc.
What is an Algorithm?

An algorithm must:
be lucid, precise, and unambiguous
give the correct solution in all cases
eventually end
Developing an Algorithm?
Define the problem
It is important to clearly define the
problem

then

Design a Solution Algorithm


Defining the Problem
To help with this initial analysis, the
problem should be divided into three
separate components:
1. Output:
a list of the outputs required
2. Input:
a list of the source data provided to the
problem
3. Processing:
a list of actions needed to produce the
required outputs from the inputs provided
Defining the Problem
(Problem Statement)
When dividing a problem into its three
different components, you should simply
analyze the actual words used in the
specification, and divide them into those
which are descriptive and those which imply
actions
In some problems, the inputs, processes, and
outputs may not be clearly defined
It is best to concentrate on the outputs
required first
Example: Add Three Numbers

A solution is required to read three


numbers, add them together, and print their
total

Output:
Print total
Input:
Read 3 numbers
Processing:
Add numbers together as they are input
Designing a Solution Algorithm

After a problem has been clearly stated, we


need to figure out the best solution
If the algorithm is not correct, the final solution will
never be correct either

We can use some basic methods to design


a good algorithm:
Break down our problem into a sequence of small
parts and organize their solutions into the main
picture.
Start at the goal and work backward toward the initial
statement of the problem.
Solution Algorithm Example

READ number_1
ADD to total
READ number_2
ADD to total
READ number_3
ADD to total
PRINT total
Implementing a Solution

After an algorithm has been stated and


corrected
It is then implemented/coded into a
computer program.
Program Testing
After the code is implemented, the actual
program testing is a verification that the
algorithm/program is doing what it
should.
Many programs do not work well with all
input cases
they must be tested to ensure that all types of
data works with the program designed

The RIGHT data, the WRONG data, NO DATA


Documentation
To enable people to understand your
solution/program code
Documentation usually shows the input-
output descriptions, flowcharts/pseudo code,
test results, etc
A complete documentation includes correct
and informative comments with the code,
plus the external information about the
program
Example #1
Lamp Doesnt Work

IF Lamp Not Plugged in?


PLUG in lamp
ENDIF
IF still not working
Replace bulb
ELSE IF still not working
BUY new lamp
ENDIF
Example #2
Baking Bread Algorithm

ADD ingredients
MIX ingredients
ADD water
KNEAD
LET RISE
BAKE
Example #3
Sorting Mail

#Get all the mail from mailbox and put it on the table.

WHILE more mail to sort:


GET piece of mail from table.
IF piece is personal THEN
READ it
ELSE IF piece is magazine THEN
PUT in magazine rack.
ELSE (piece is junk mail)
THROW it in the wastebasket.
ENDIF
ENDWHILE
More Everyday Algorithms ..
More Everyday Algorithms ..
Conclusion

an algorithm is a sequence of instructions


that helps you solve a particular problem
it takes input
shows an effective number of processing steps
Produces output

algorithms are used in computer programs


but can also be seen in everyday life
Algorithms - Intro

Steps to a Solution

Vous aimerez peut-être aussi