Computer Architecture and Algorithms Guide
Computer Architecture and Algorithms Guide
Architecture of
computers & Algorithms
Algorithmics
3
Architecture of Computers & Algorithms @ ENSA - BM Teacher: Mohammed Boutalline
1
29/11/2021
What is an algorithm?
4
Architecture of Computers & Algorithms @ ENSA - BM Teacher: Mohammed Boutalline
What is an algorithm?
5
Architecture of Computers & Algorithms @ ENSA - BM, Teacher: Mohammed Boutalline
2
29/11/2021
What is an algorithm?
For 6 people:
200 g of dark chocolate
4 eggs
150 g of sugar
80 g of flour
200 g of butter
Entrance Exit
mix the egg yolks
...
put in the oven for 20 minutes at 180
6
Architecture of Computers & Algorithms @ ENSA - BM Enseignant :Mohammed Boutalline
What is an algorithm?
then repeat:
Note the units digit
Retain the tens digit, if there is one
Add the following two digits of n1and n2
and the retention
7
Arch. of Computers & Algorithms @ ENSA - BM, Teacher: Mohammed Boutalline
3
29/11/2021
What is an algorithm?
then repeat:
Note the units digit
Retain the tens digit, if there is one.
Add the two following digits of n1and n2
and the retention
8
Architecture of Computers & Algorithms @ ENSA - BM, Teacher: Mohammed Boutalline
Write an algorithm
Il n'est pas nécessaire de choisir un langage de
programming
We do not want to depend on the specifics of a language.
we write in pseudo-code also called LDA (Language of
Description of Algorithms
9
Architecture of Computers & Algorithms @ ENSA - BM Teacher: Mohammed Boutalline
4
29/11/2021
Write an algorithm
Problem: finding the minimum in an array of integers
données:un tableau d'entiersrésultat:l’élémentminimum du
table
6193 7 11 9 215 5
min 6
min 3
min 2
At the end of the journey, we obtain the minimum
10
Architecture of Computers & Algorithms @ ENSA - BM Teacher: Mohammed Boutalline
Write an algorithm
Problem: find the minimum in an array of integers
data: an array of integers
result: the minimum element of the array
array: a table of n integers
beginning
min tab[1] we initialize the minimum to the first entry of the array
For i from 1 to n Then we go through the other entries of the
one by one
if min > tab[i]
min tab[i] updating the minimum if necessary
Until yes
End for
Show min At the end of the course, we obtain the minimum.
End
11
Architecture of Computers & Algorithms @ ENSA - BM, Teacher: Mohammed Boutalline
5
29/11/2021
Write an algorithm
Problem: searching for the element x in an array of integers
données:un tableau d'entiers n et un entier
résultat:l'indice de l'entier recherché dans le tableau s'il s'y
find, -1 otherwise
How?
12
Architecture of Computers & Algorithms @ ENSA - BM Teacher: Mohammed Boutalline
Write an algorithm
Note:
When you are well acquainted with an algorithm to solve a
problem, we can deduce others to solve others
similar problems by making small changes
13
Architecture of Computers and Algorithms @ ENSA - BM Teacher: Mohammed Boutalline
6
29/11/2021
Write an algorithm
Problem: find the minimum in an array of integers
data: an array of integers
result: the minimum element of the array
Principle: divide and conquer
6 19 3 7 11 9 2 15 5
6 3 9 2 5
if T has more than one element
Divide the table in two
sub-arrays T1and T2
calculate the minimum, min1of T1 9 2
calculate the minimum, min2from T2
return the minimum of min1and
min2 3 2
otherwise return the unique element of T
2
14
Architecture of Computer Systems & Algorithms @ ENSA - BM Teacher: Mohammed Boutalline
7
29/11/2021
Khouribga
Casablanca
Settat
the shortest round passing
through all the villages?
Marrakech
Khénifra
Tadla
Azilal
No other known algorithm than to
calculate all possible rounds!
No effective solution!
16
Computer Architecture & Algorithms @ ENSA - BM Teacher: Mohammed Boutalline
Data size
And there are problems that we do not know how to solve with a
algorithm!
17
Computer Architecture & Algorithms @ ENSA - BM Enseignant :Mohammed Boutalline
8
29/11/2021
Un+1=1/2*(Un+a/Un)
with Un1
18
Architecture of Computers & Algorithms @ ENSA - BM Teacher: Mohammed Boutalline
19
Architecture of Computers & Algorithms @ ENSA - BM Teacher: Mohammed Boutalline
9
29/11/2021
20
Architecture of Computers & Algorithms @ ENSA - BM, Teacher: Mohammed Boutalline
Exercise
Write an algorithm that asks for a starting number, and
who calculates its factorial.
10
29/11/2021
Structure of an algorithm
22
Arch. of Computers & Algorithms @ ENSA - BM Teacher: Mohammed Boutalline
Structure of an algorithm
Algorithmics
Programming Compilation
(Analysis
(Language of +
+
programming Execution
Conception
23
Architecture of Computers & Algorithms @ ENSA - BM Enseignant :Mohammed Boutalline
11
29/11/2021
Structure of an algorithm
24
Computer Architecture and Algorithms @ ENSA - BM Enseignant :Mohammed Boutalline
Structure of an algorithm
The header
25
Architecture of Computers & Algorithms @ ENSA - BM Enseignant :Mohammed Boutalline
12
29/11/2021
Structure of an algorithm
Example:
VariablesRayon, Surface:Réel;
Declaration Party
ConstantPi 3.14
Start
ReadRayon
End
Basic instructions
Data Affectation
Entrées Outputs
Type
Real
27
Architecture of Computers & Algorithms @ ENSA - BM Teacher: Mohammed Boutalline
13
29/11/2021
Data
28
Architecture of Computers & Algorithms @ ENSA - BM Teacher: Mohammed Boutalline
Data
29
Architecture of Computers & Algorithms @ ENSA - BM Teacher: Mohammed Boutalline
14
29/11/2021
Affectation
Algorithmic Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
mod Remainder of the integer division
30
Architecture of Computers & Algorithms @ ENSA - BM Teacher: Mohammed Boutalline
Comparison
Algorithmics Meaning
= Equal
<> Different
< Inferior
> Superior
<= Less than or equal to
31
Architecture of Computers & Algorithms @ ENSA - BM, Teacher: Mohammed Boutalline
15
29/11/2021
Logical operator
Algorithmics Meaning
No Negation
OU Or logic
ET And Logic
32
Computer Architecture and Algorithms @ ENSA - BM Teacher: Mohammed Boutalline
Lecture
Simply put, for which user among the (new)
value of the radius, we will put:
Read (Radius);
33
Computer Architecture and Algorithms @ ENSA - BM Teacher: Mohammed Boutalline
16
29/11/2021
Writing
In the opposite direction, to write something on the screen, it is
as simple as:
Write (Rayon);
34
Architecture of Computers & Algorithms @ ENSA - BM, Teacher: Mohammed Boutalline
Exercise
Write an algorithm that asks for the Excluding Tax Price (PHT)
of an item, calculate and display the price to pay (including taxes) knowing
17
29/11/2021
1. Conditional operator
36
Arch. of Computers & Algorithms @ ENSA - BM, Teacher: Mohammed Boutalline
Conditional operator
minor";
18
29/11/2021
There are only two possible forms for a test; the first
is the simplest, the second the most complex.
SibooléenThen SibooléenThen
Instructions Instructions 1
Finally yes Otherwise
Instructions 2
End if
This calls for some explanations.
Boolean is an expression whose value is TRUE or FALSE.
So it can be (there are only two possibilities):
a variable (or an expression) of boolean type
a condition
It would thus be much more rational to intertwine the tests
38
Architecture of Computers and Algorithms @ ENSA - BM Teacher: Mohammed Boutalline
Exercise
Write an algorithm (a program in C language) that
solve the second degree equation (a.x2+b.x+c=0)
in IR.
19
29/11/2021
valeur 1: instruction 1;
valeur 2: instruction 2;
valeur 2: instruction 3;
value n: instruction n;
otherwise instruction n+1;
End according to
40
Architecture of Computers & Algorithms @ ENSA - BM, Teacher: Mohammed Boutalline
Exercise
Write an algorithm that displays the corresponding day for
the integer entered via the keyboard.
20
29/11/2021
More Logic
42
Architecture of Computers and Algorithms @ ENSA - BM Teacher: Mohammed Boutalline
21