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

Algorithm

The document discusses algorithms and provides examples. It defines an algorithm, lists characteristics of a good algorithm, and gives recipes and calculating rectangle surface as examples. Instructions for writing algorithms are provided, including naming the algorithm, defining inputs and outputs, and listing the step-by-step process.

Uploaded by

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

Algorithm

The document discusses algorithms and provides examples. It defines an algorithm, lists characteristics of a good algorithm, and gives recipes and calculating rectangle surface as examples. Instructions for writing algorithms are provided, including naming the algorithm, defining inputs and outputs, and listing the step-by-step process.

Uploaded by

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

CHAPTER : INITIATION TO ALGORITHMIC THINKING

Objectives:
- Writing basic solution procedure to problems
- Ordering solution steps
Lesson : Introductive Activity; Cook recipe INTRODUCTION
Algorithm is a part of our daily life. We accomplish any task by following an algorithm. For example
making a cake, Computing rectangle surface.
Computer science is based in programs or applications whose execution can be summarized as:
problem posed – analysis – algorithm – program – compilation – execution.
An Algorithm is a well-defined step by steps instructions specifying how to complete a task.
1 DEFINITION
An algorithm is a well-defined set of step-by-step instructions for solving a problem in a finite
amount of time. A set of instructions is not an algorithm if there is no definite stopping place, or if
the instructions are too vague to be followed clearly. An algorithm cannot be directly executed by a
computer, but it has to be translated into a program using a programming language.
2 CHARACTERISTICS OF A GOOD ALGORITHM A good algorithm:

- should be explicit (i.e. clear and obvious)


- should be precise (i.e. exact and accurate)
- should be unambiguous (i.e. no doubts about what to do/ only one way of interpreting the
instructions)
- should be effective (i.e. produce good results)
- should be finite (i.e. have a definite stopping place)
3 INTRODUCE ACTIVITY: COOK RECIPE
1. PROBLEM TO SOLVE OR TASK TO PERFORM: state the step by step instructions to follow in order
to obtain at the end the pineapple juice. Specify the input elements, the result or the output of your
algorithm.
2. SOLUTION
- This define the problem to solve: how to make pineapple juice
- The definite stopping point: when the juice is done
- The above activity is an algorithm to prepare a pineapple juice.
- Pineapple juice is the output
- The ingredients constitute the Input
- The cooking steps represents the instructions steps.

RECIPE
- 1 lemon- 1 orange- 1 pineapple- 1 litter of water- 3 eating spoon
INGREDIENTS (inputs)
of sugar- 1 eating spoon of grated ginger
- Wash lemon and orange- Cut them into small pieces and put
COOKING(set of them to the fridge- Peel the pineapple and cut them into small
instructions) pieces- Mix the pieces of lemon, orange, pineapple, water, grated
(processes) ginger;- Grind them- Sleeve it to extract the juice- Then put the
juice into the fridge

Output PINEAPPLE JUICE (Output)

EXERCISE: write and algorithm to make a cup of tea Solution: Algorithm Making _ a_cup_ of_ tea
Inputs: Sugar, water, ovaltin, milk, fire Set of instructions:
1- Prepare the Fire

2- Put the pot on the fire


3- Boil water
4- Put the milk, Ovaltin, sugar inside the tea cup
5- Add the boil water to it
6- Stir to make sure that it is uniform
7- Test the tea if it is not OK perform step 4 Else END Drink your tea

Lesson 2 : Examples of Algorithms


1 Structure of an Algorithm
To write an algorithm, you have to specify:
- The name of the algorithm which has to be clear and explicit. It should clearly present the problem
to be solve.
- The inputs that represents data we need to solve the problem.
- The set of instructions : that explains how to solve the problem
- The Output: That represents the final result we should obtain.
2 Example of algorithm: Calculating the surface of a rectangle PROBLEM: Write an algorithm that
calculate the surface of a rectangle SOLUTION:
Algorithm : Surface_of_a_Rectangle;
INPUTS: Width: W;
Height: H;
Begin(SET OF INSTRUCTIONS:)
1. PROMPT USER TO ENTER WIDTH AND HEIGHT
2. READ THE WIDTH AS W AND THE HEIGHT AS H
3. COMPUTE THE SURFACE BY MULTIPLYING THE HEIGHT H BY THE WIDTH W
4. STORE THE RESULT AS S=H×W
PRINT THE SURFACE S
END.
1- Exercise: Write an algorithm to calculate the surface of a square.

You might also like