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

Introduction A L'algorithmique

This document provides information about an introductory course on algorithms being taught at Constantine 2 University. It includes the course title, instructor details, goals of the course, and summaries of the first two chapters which introduce basic concepts like the components of a computer and the definition of an algorithm. Sample programs are described to demonstrate simple algorithm executions. Pseudo code is presented as an equivalent way to write algorithms compared to programming languages like Visual Basic, C, and C++.

Uploaded by

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

Introduction A L'algorithmique

This document provides information about an introductory course on algorithms being taught at Constantine 2 University. It includes the course title, instructor details, goals of the course, and summaries of the first two chapters which introduce basic concepts like the components of a computer and the definition of an algorithm. Sample programs are described to demonstrate simple algorithm executions. Pseudo code is presented as an equivalent way to write algorithms compared to programming languages like Visual Basic, C, and C++.

Uploaded by

anes skills
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Course : Introduction to algorithms Constantine 2 University – Abdelhamid Mehri

Dr. Mohamed BADECHE Common Core – MI, NICT Faculty – 1st year (2023-2024)

Constantine 2 University – Abdelhamid Mehri


2022-2023. Semester 1

Introduction to algorithms

Chapter 1 & 2 : Introduction and Basic Concepts

Chargé de cours
Name Grade Faculty/Institute E-mail
mail address
BADECHE Mohamed MCB New technologies [email protected]
algo.assistance

Etudiants concernés
Faculty/Institute Department Year Speciality
New technologies MI License 1 Common Core

Goals :
Introduce the concept of algorithm.
State syntactic conventions.
Become familiar with the basic instructions.
Getting started with conditional and repetitive processing.
Course : Introduction to algorithms Constantine 2 University – Abdelhamid Mehri
Dr. Mohamed BADECHE Common Core – MI, NICT Faculty – 1st year (2023-2024)

Sommaire
Chapter 1: Introduction .......................................................................................................................................................... 1
1.1. Components of a computer ......................................................................................................................................... 1
Chapter 2: Algorithm .............................................................................................................................................................. 2
2.1. Introduction to the concept of algorithm .................................................................................................................... 2
2.1.1. Simple examples of program execution ............................................................................................................... 2
2.1.2. Algorithm example................................................................................................................................................ 3
2.1.3. Definition of an algorithm..................................................................................................................................... 3
2.1.4. Structure of an algorithm ..................................................................................................................................... 4
2.1.5. Basic instructions (‘Read’, ‘Write’ and assignment) ............................................................................................. 4
2.1.6. Algorithm vs Program ........................................................................................................................................... 5
2.1.7. User vs Programmer (Developer) ......................................................................................................................... 5
Course : Introduction to algorithms Constantine 2 University – Abdelhamid Mehri
Dr. Mohamed BADECHE Common Core – MI, NICT Faculty – 1st year (2023-2024)

Chapter 1: Introduction

1.1. Components of a computer


The word computing is made up of the two terms: information and automatic. Computer science is the science
of automatic information processing.
Computer science can be seen in two aspects: hardware and software.
The following diagram summarizes the hardware and software components of a computer:

Computer science

Hardware Software

Central Unit (CPU) Peripheral devices Operating systems Programs

Keyboard Mouse Word Calculator


Motherboard Windows Linux
Screen Paint
Microprocessor Memories Mac Os
I5 2.5 GHz

RAM Hard Disk


(Volatile) (Permanent)
8 GO 500 GO

1
Course : Introduction to algorithms Constantine 2 University – Abdelhamid Mehri
Dr. Mohamed BADECHE Common Core – MI, NICT Faculty – 1st year (2023-2024)

Chapter 2: Algorithm

2.1. Introduction to the concept of algorithm


In order to introduce the notion of algorithm, we will present two very simple programs and describe their
executions on a machine.

2.1.1. Simple examples of program execution


Consider the following two simple programs, the first in Visual Basic and the second in C language. The
following table describes the execution, from the user's point of view, of the two programs on the machine, step
by step:

Description of
Running a program in Visual Basic (VB) Executing a program in C language
execution steps
Private Sub Form_Load() int main()
{
Dim a, b, c As Integer int a, b, c;
a = InputBox("") scanf("%d",&a);
Program code
b = InputBox("") scanf("%d ",&b);
c=a*b c = a*b;
MsgBox (c) printf("%d", c);
End sub }

The program displays


the cursor to allow
the user to enter a
value

The user enters the


value: 100

The program displays


the cursor again

2
Course : Introduction to algorithms Constantine 2 University – Abdelhamid Mehri
Dr. Mohamed BADECHE Common Core – MI, NICT Faculty – 1st year (2023-2024)

the user enters a


second value: 5

The program displays


the result of
multiplying the two
values entered by the
user: 500

2.1.2. Algorithm example


An algorithm is the equivalent of a program, it is written in pseudo code. The following algorithm is the pseudo
code equivalent of the two programs in the previous section:

Visual Basic code C code C++ code Pseudo Code


Private Sub Form_Load() main() main() Algo Exo1 Head
{ {
Dim a, b, c As Integer int a, b, c; int a, b, c; Var Statement
a,b,c : entier
Début Announce start of instructions.
a = InputBox("") scanf("%d",&a); cin >> a ; Lire(a) Allow the user to enter the value
of a.
b = InputBox("") scanf("%d",&b); cin >> b ; Lire(b) Allow the user to enter the value
of b.
Multiply a by b and put the result
c=a*b c = a*b; c = a*b; c a*b
in c.
MsgBox (c) printf("%d", c); cout >> c ; Ecrire(c) Show result stored in c.
End sub } } Fin Announce the End.

2.1.3. Definition of an algorithm


The word algorithm comes from the name of Al-Khwarizmî ( ‫ارز‬ ‫)ا‬, great mathematician of the 9th century.
Definition 1: An algorithm is a finite and unambiguous sequence of operations or instructions used to solve a
problem1.
Definition 2: An algorithm is a general method for solving a type of problem. It is said to be correct when, for
each instance of the problem, it ends producing the correct output. That is to say it solves the problem posed1.
Definition 3: An algorithm is simply a way of describing down to the smallest details how to proceed to do
something2.

1
Wikipedia
2
Philippe Flajolet, Étienne Parizot, « Qu'est ce qu'un algorithme ? », interstices.fr, 2004.
3
Course : Introduction to algorithms Constantine 2 University – Abdelhamid Mehri
Dr. Mohamed BADECHE Common Core – MI, NICT Faculty – 1st year (2023-2024)

2.1.4. Structure of an algorithm


The algorithm generally consists of three blocks:
Algo Exo1 Head
Var
… Statement
Début
… Body (Series of instructions)
Fin
1. In the header block, we give a name to the algorithm. This name can be composed of letters and numbers
and must begin with a letter, and must not contain punctuation letters, in particular spaces.
2. In the declaration block, we declare the types of variables used. A variable is the association of an identifier
(a variable name) with data. A variable can be of the type Integer like the introductory example, Real like
the example in section 2.1.5, Character and string like the example in section 2.3, and other types that we
will see as we go on. and as you progress in this course.
3. The body block contains the instructions themselves, to be executed in order.

2.1.5. Basic instructions (‘Read’, ‘Write’ and assignment)


In almost all algorithms, we find the three basic instructions: the Read instruction, the Write instruction and
the assignment instruction.
- The Read instruction gives control (allows) the user to enter one or more data.
- The Write instruction allows you to display (print) results or messages on screen.
- The assignment instruction ( ) allows you to save (store) a value in a variable.
Example :
Consider the following algorithm which allows you to calculate the area (surface) of a circle from its radius.
Algo Area
Var
R, A : Real
Début
Read(R)
A 3.14 * R * R
Write(A)
Fin
Note that the type of variables declared in this algorithm is Real, since the radius can be in comma like 2.5, and
the result is necessarily in comma due to the multiplication by 3.14.
This algorithm allows you to:
1. Give the user hand to enter an actual value for the radius of a circle.
2. Calculate the area (surface) from the formula πR2, and store the result in the variable A through the
assignment instruction ( ) which we read: receives (A receives 3.14 times R times R).
3. Display the result (the calculated area of the circle).
The Read instruction can give control to the user to enter multiple values. The following two entries are
correct:
Lire(a)
Lire(a,b)
Lire(b)

4
Course : Introduction to algorithms Constantine 2 University – Abdelhamid Mehri
Dr. Mohamed BADECHE Common Core – MI, NICT Faculty – 1st year (2023-2024)

The assignment instruction always has a variable in its left part and can have in its right part, either a constant
(A 3.14), or a variable which has a value (A B), or an evaluable expression (A B*2+3). Writings like:
3.14 A, A + 2 B and A B 5 are syntactically incorrect.
The Write instruction displays either variable values: Write(A), or messages: Write("Hello"), or a combination
of messages and variables: Write("the area of the circle is ", A, " cm2").
By convention in this course, the Write instruction displays and jumps to the line.

2.1.6. Algorithm vs Program


The goal behind writing an algorithm is to transform it (translate it) into a program executable on a machine.
Algorithmic pseudo code allows you to write algorithms by hand in order to focus on ideas and reasoning, it is
not supposed to be executed directly on a machine, except after having transformed (translated) it into code
written in a programming language like C language, Visual Basic, Java, Python…
So it is the algorithm that was created in the service of programming and not the other way around.

Algorithm Program
Pseudo code Code
Not directly executable on machine 3 Executable directly on machine
It was created for the programming service

2.1.7. User vs Programmer (Developer)


We must distinguish the two roles: user and programmer. A programmer (or developer) designs programs
intended for use by users.
When we write algorithms, we play the role of programmer who writes an algorithm in order to subsequently
transform (translate) it into an executable program. The user, for his part, does not see the sequence of
instructions that a programmer has written, but only sees the inputs (that the programmer asks him to give) and
the outputs that the programmer displays to him. For him, what happens between inputs and outputs is a black
box.

Inputs Outputs
Treatment

The programmer must sometimes put himself in the user's shoes to test his program himself, and thus plays
both roles.

3
The case of applications like 'AlgBox' on PC or 'Algo' on Smartphone, which in appearance allow you to execute algorithms, are in
reality only educational tools for simulating the execution of an algorithm on a machine.
5

You might also like