0% found this document useful (0 votes)
17 views6 pages

Algorithm Course

The algorithm is a method for solving a given problem in a finite amount of time. The document describes the key concepts related to algorithms and programming, including the difference between an algorithm and a program, the representations of algorithms, the steps to solve a problem, and the basics of an algorithmic language.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views6 pages

Algorithm Course

The algorithm is a method for solving a given problem in a finite amount of time. The document describes the key concepts related to algorithms and programming, including the difference between an algorithm and a program, the representations of algorithms, the steps to solve a problem, and the basics of an algorithmic language.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

National Institute Specialized in Vocational Training Batna2 algorithm

MQ1: Algorithm
The objective of this course is to answer these three questions:
• What is algorithmic?
• What is an algorithm?
• What are the different representations of an algorithm?
• What are the steps to solving a problem?
• What is a programming language?
• What are the basic concepts of the algorithm?
Introduction
A computer program allows the computer to solve a problem, but before...
to communicate to the computer how to solve this problem, it is first necessary to be able to
to solve it ourselves make an algorithm.
1.1. Algorithms
designates the discipline that studies algorithms and their applications in
computer science
1.2. An algorithm
is a method that allows to solve a given problem in finite time, it
represents a logically ordered sequence of instructions (action)

Problem
Result
algorithm
solution

provided

1.3. The program


it will only be the translation of the algorithm into a programming language,
that is to say, a language simpler than French in its syntax, without ambiguities, than the
machine can use and transform to perform the actions it can describe. Pascal, C,
Java … are names of programming languages.
1.4. Algorithm and program
• The algorithm is written in the user's language.
• The program is written in a language understood by the computer.
• A program is an algorithm translated into a programming language
• The development of an algorithm precedes the programming step.
• Writing an algorithm is an exercise of reflection that is done on paper.
• The algorithm is independent of the programming language, for example, one
use the same algorithm for an implementation in Java, or in C++
1.5.Representation of an algorithm
For computer program algorithms: there are two (2) main families.
to represent them:
1.5.1. Flowcharts (organizational chart):
It is a graphic representation with symbols (squares, diamonds, etc.).
are standardized and must comply with ISO 5807.

AMARA.A
National Institute Specialized in Professional Training Batna2 algorithm

Here are the main symbols that are used:


symbol Meaning
Indicate the beginning or the end of an algorithm

Perform an action

Carry out an interaction

Example:
Début

Read (a)

Read (b)

a a+b

Write (a)

fin

Logic diagrams have the advantage of being easy to understand; you just need to follow the thread.
nevertheless, they have two drawbacks:

• They are very space-consuming


• They are far from most programming languages.
1.5.2. Pseudocode:
It is a textual representation with a series of instructions resembling a
programming language (it is an informal language close to natural language
and independent of any programming language
• It is more practical for writing an algorithm
• Its representation is widely used

It is a textual representation with a series of instructions resembling a language of


programming (this is an informal language close to natural language and independent of
any programming language)

AMARA.A
National Institute Specialized in Vocational Training Batna2 algorithm

Example
addition algorithm
variables a, b as integer
read
read (b)
a a+b
write (a)
end

1.6. The steps to solve a problem:

The resolution of a given problem involves a succession of steps namely:

problem
Understand and analyze the statement of the problem

Models
Specify the resolution model: The necessary data and
The resulting data and the mathematical formulas

algorithm Write an algorithm

program Translate the algorithm into a program

result Run the program on a computer to obtain results

But during the writing of a program, one may encounter 2 types of errors:
• Syntax errors: they are noticed at compilation and are the result
of a bad
writing in the programming language.
• Semantic errors: they become apparent during execution and are the result of a
poor analysis. These errors are much more serious because they can lead to
trigger during the operation of the program.

1.7. Programming languages (computer languages)


A programming language is a code of communication, allowing a human being
to dialogue with a machine by submitting instructions and analyzing the
material data provided by the system. The programming language is
the intermediary between the programmer and the machine. It allows writing programs
(consecutive sequence of instructions) intended to perform a given task.
Two types of languages are distinguished:

AMARA.A
National Institute Specialized in Vocational Training Batna2 algorithm

• Procedural languages: the program is divided into small parts called


procedures or functions. As its name suggests, programming
procedural contains a step-by-step procedure to execute. So the problems
are broken down into small parts and then, to solve each part, one or
several functions are used.
Example: Pascal, C, ...
• Object-oriented languages: the program is divided into parts called objects.
Object-oriented programming is a programming concept that focuses on
on the object rather than on actions and data rather than on logic.
Example: C++, Java, C#,…
Choosing a programming language is not easy, each has its own specifics and
better suits certain types of uses.

The Basics of an Algorithmic Language


2.1. Basic Structure
In pseudo-code, the general structure of an algorithm is as follows:
Algorithm of the algorithm
CONSTANT {Definition of constants}
TYPE{Definition of types} they are optional (if there is no variable or
VARIABLE{Variable declaration} constant or type we do not write them)
DEBUT
{Sequence of instructions}
FIN.
• Header part: it is the first line of the algorithm, it starts with the word
algorithm followed by a space and then the name of the algorithm.
• Declaration part: it is a memory space reservation for variables,
constants and types, in this part, all objects used in the resolution of
problems must be declared.
• Processing section: this part starts with the word Start and ends with the word
In the end, it contains the actions used in solving the problem.
2.2. Basic Instructions
An algorithm is composed of four types of instructions considered as small
basic bricks:
1. Variable assignment
2. Reading and/or writing
3. The tests
4. The loops
Before describing these instructions, we first present the concept of a variable and
constant.
2.2.1. Constants and variables
Objects are divided into two classes: constants and variables.
2.2.1.1. Notion of variable
The data manipulated in an algorithm are called variables. A variable is used to
store the value of a data in a programming language. It refers to a
memory location whose content can change during a program (hence the
variable name). Each memory location has a number that allows access to it.
unique reference: it is the memory address of this cell.
Rule: The variable must be declared before it is used, it must be characterized.
by :

AMARA.A
National Institute Specialized in Vocational Training Batna2 algorithm

• A name (Identifier)
• A type that indicates the set of values that the variable can take (integer,
real, boolean, character, string, ...
• A value
Identifiers: rules
The choice of a variable name is subject to some rules that vary depending on the language.
but in general:
• A name must start with an alphabetical letter. Example: E1 (1E is not)
valid)
• Must consist only of letters, numbers, and underscores (' _ ')
Avoidpunctuationcharactersandspaces.Examples:SMI2008,SMI_2008.
(SMP 2008, SMP-2008, SMP;2008: are not valid)
• Must be different from the reserved words of the language (for example in Pascal: integer,
real, char, program, if, for...
• The length of the name must be less than the maximum size specified by the language
used
Advice: for code readability, choose meaningful names that describe the data.
manipulated.
StudentGrade
Note: in algorithmic pseudo-code, we will follow the mentioned rules, even if we
is free in the syntax

Types of variables
The type of a variable determines the set of values it can take. The types
offered by most languages are:
• Numeric type (integer or real)
• Byte (coded on 1 byte): from [-27,27[ or [0, 28[
• Short integer (coded on 2 bytes): [-215, 215[
• Long integer (coded on 4 bytes): [-231, 231[
• Simple real precision (encoded in 4 bytes): precision of order 10-7
• Double precision real (encoded on 8 bytes): precision of the order of 10-14
• Logical or boolean type: two values TRUE or FALSE
• Character type: uppercase letters, lowercase letters, numbers, symbols, ... . Examples: 'A',
'b', '1', '?', ...
• String type: any sequence of characters. Examples: " ", " Last name, First name"
postal code: 1000
A) Integer: To represent integers, the operations usable on integers
are:
• All basic elementary operations are allowed: +, -, *, /
• The classic comparison operators: <, >, =, ...
• The division / is the Euclidean (or integer) division. E.g. 11 / 4 = 2 and not 2.75!)
• There is the modulo operator %, which gives the remainder of the Euclidean division. Example:
11%4 = 3
B) Real: To represent real numbers, the operations usable on reals are:
• The classic arithmetic operations: + (addition), - (subtraction), * (product), / (division)
division
• The classic comparison operators: <, >, =, ...
• The division gives a decimal result
C) Boolean: A variable of logical type (boolean) can take two values: TRUE or
FALSE. The most commonly used main operations are:

AMARA.A
National Specialized Institute for Professional Training Batna2 algorithm

• Logical operators: NOT, AND, OR


• Opérateurs de comparaison : =, ≤, ≥, ≠
Truth tables:
A B A and B A or B
Fake Fake False Fake
Fake True false True
True Fake Fake True
True True True True
D) Character
This is the domain consisting of alphabetic and numeric characters. A variable of
this type can only contain a single unique character.
The basic operations that can be performed are comparisons: <, >, =, ...
E) String
A string is an object that can contain multiple characters in a way
ordered.

2.2.1.2. Notion of constant


A constant is a variable whose value does not change during execution.
program, it can be a number, a character, or a string of characters. In
pseudo-code, Constant identifier=value (by convention, constant names are
(IN UPPERCASE)
Example: to calculate the area of circles, the value of pi is a constant but the radius
is a variable.
• Constant PI=3.14
• A constant must always receive a value upon its declaration.

AMARA.A

You might also like