0% found this document useful (0 votes)
15 views9 pages

Basic Fundamentals of Algorithms

The document provides an overview of algorithms, defining them as methods for problem-solving through a sequence of instructions. It outlines key characteristics of algorithms, the process of input, processing, and output, and introduces basic elements such as variables, constants, and data types. Additionally, it discusses arithmetic expressions, division operations, and internal functions used in programming.
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)
15 views9 pages

Basic Fundamentals of Algorithms

The document provides an overview of algorithms, defining them as methods for problem-solving through a sequence of instructions. It outlines key characteristics of algorithms, the process of input, processing, and output, and introduces basic elements such as variables, constants, and data types. Additionally, it discusses arithmetic expressions, division operations, and internal functions used in programming.
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/ 9

Catholic University of the Angels of Chimbote

School of Engineering
Professional School of Systems Engineering Algorithms and Programming

FUNDAMENTOS BÁSICOS DE ALGORITMOS

A computer does not have the capacity to solve problems except when it is given
they provide the successive steps to be taken, for this we prepared an algorithm.

What is an algorithm?
It is a method for solving a problem through a sequence of instructions, each one of
which specifies the operations that the computer must perform.

Characteristics of an algorithm
The fundamental characteristics that every algorithm must fulfill are:

It must be precise and indicate the order of completion of each step.


It must be defined. If an algorithm is followed two or more times, with the same values
The initials should yield the same result.
It must be finite. If an algorithm is followed, it must terminate at some point, that is,
it must have a finite number of steps.

It is also important to take into account in an algorithm:

The algorithm serves as the basis for generating a program, but it is not the program itself.
The algorithm is not directly intelligible by the computer.
The same algorithm can be implemented differently in various programs, it is
Say, two programmers can obtain different source codes from the same one.
algorithm.

The process of an algorithm


The definition of an algorithm must describe three parts: Input, process, and output.

Entry Exit
Process

The information provided to the algorithm constitutes its input, the procedure for the
The solution to the problem constitutes its subprocess and the information produced by the algorithm.
constitutes its exit.

Below are examples of algorithms for better understanding:

Example 01:
Read the base and height of a parallelogram. Calculate its area.

Input Data ---> base and height


Process ---> area = base x height
Output Data ---> The area of the parallelogram

1
Catholic University of the Angels of Chimbote
School of Engineering
Professional School of Systems Engineering Algorithms and Programming

Example 02:
Read the radius of a circle. Calculate its area and circumference.

Input Data ---> Radius of a circle.


Process ---> Area = ¶r2and Length = 2πr
Output Data ---> The area and length of a circumference.

Algorithm verification or desk test


Once the algorithm is written, it is necessary to ensure that it performs the tasks for which it was designed.
it has been designed, and therefore produces the correct and expected result.

The most common way to check an algorithm is by manually executing it using data.
significant that encompass the entire possible range of values and noting it down on a sheet of paper the
values that are taken in the different phases, the input or auxiliary data and, finally the
values of the results. This process is known as algorithm testing.
desk.

We will conduct a walkthrough of the two previous problems:

Elements Example 01 Example 02


Input data ● base = 5 ● r (radio) = 3
● altura = 3 ● ¶ (pi) = 3.14 (We will only take up to
two decimal places
Process ● area = base x height ● area = π r2= 3.14 x (3)2
● area =5x3 ● length = 2πr = 2 x 3.14 x 3

Output data ● area = 15 ● area = 28.26


● longitud = 18.84

Basic elements of an algorithm

The basic elements that are an essential or fundamental part of an algorithm or program are:

Identifiers.
Variables.
Constants.
Instructions.
Reserved words.

Identifiers
These are names used to identify objects and other elements of a program: variables,
constants, operators, functions, procedures, etc. There are rules for building
valid identifiers are as follows:

● The first character must be a letter or an underscore.


● The following characters can be letters, numbers, or underscore symbols.
● Uppercase letters and lowercase letters are treated as distinct. Asísuma,Sumay
SUMA are three distinct identifiers.
● Theycannot be the same as any reserved word.

2
Catholic University of the Angels of Chimbote
Faculty of Engineering
Professional School of Systems Engineering Algorithms and Programming

Variables
A variable is an object to which a value is assigned and whose value can change during the
development of the algorithm or execution of the program. If a variable is composed of two
words, these can be together or connected by the underscore, hyphen, or subhyphen '_'.

Note:
Reserved words of the language should not be used as variable names (identifiers).
algorithm or programming language.

Examples:
● Note ● Last_name ● prices
● Name ● mother's last name ● hour
● Surnames ● Note 1 ● prom
● oral note ● Counter1 ● pi

The names of the chosen variables must be meaningful and related to the object that
they represent, such as the following cases:

name to represent people's names.


prices to represent the prices of different items.
notes to represent the grades of a class.

The following shows examples of inappropriate variable names because


they have another meaning than what was expressed:

sugar to represent the grade of a class.


pan to represent a person's age.

Constants
A constant takes or receives a value that does not change during the development of the algorithm or the
execution of the program.

Instructions
The instructions specify the operations or actions that must be performed or executed.

Reserved words
Words used by algorithms or programming languages to represent statements,
orders, etc.

Examples:
● start.
● end.
● to do.
● if–then–else.
● while.
● since.

CONCLUSION OF BASIC ELEMENTS OF AN ALGORITHM:

From Example 01, it is concluded that there are:


V ariables que son:base, altura y area.
From Example 02, it is concluded that there are:
Varaibles que son:radio, area y longitud.
Constants that are: pi.

3
Catholic University of the Angels of Chimbote
Faculty of Engineering
Professional School of Systems Engineering Algorithms and Programming

Data Types
The primary objective of any computer is the management of information or data. This data
They can be the sales figures of a winery, tickets for a sports event, daily income.
of a company or the grades of a classroom. The algorithms and programs
corresponding operate on data.

Data types define a set of values that a variable can store, along with a
set of operations that can be performed on that variable.

The simple data types are as follows:

Numerical (integers, real numbers).


Logical (boolean).
Character (char, string).

Numerical data
The numeric type is the set of numeric values. These can be represented in two
different forms:

Integer numeric type (int, integer)


Real numeric type (float, double)

Integer type
It is the finite subset of integers, which do not have fractional or decimal components.
and can be negative or positive.

Examples:
6 -9
-20 11
5 19
15 -1
16 0

Real types
Subset of real numbers, always has a decimal point and can be positive or
negatives. They consist of an integer and a decimal part.
Examples:
9.9 12.24
-123.11 0.89
1470.274 -0.99
54.77 3.0

Logical data
It is that data that can only take one of two values:

true y false

Example:
When asked if an integer is even, the answer will be true or false, depending on whether it is odd.
or the part.

4
Catholic University of the Angels of Chimbote
School of Engineering
School of Professional Systems Engineering Subject: Algorithms and Programming

Character type data and string type


A character type data contains a single character and is delimited by single quotes.

The characters recognized by different computers are not standard, however the
majority recognizes the following alphabetical, numerical, and special characters:

alphabetical characters : (a, b, c, ... ,z)


numeric characters : (1, 2, 3, ... ,9 ,0)
special characters : (+,-,*,/,{, }, ... ;,< ,> , ...)

A string of characters is a sequence of characters that is delineated.


by a single quote (apostrophe) or double quotes.
Examples:

Character : a ‘b’ 'm


'p' 'q' ‘M’
'Z' Y 'N'

Chain : Hello Peru


October 8, 1879
John Paul II

CONCLUSION ON DATA TYPES:

From Example 01, it is concluded that the existing data types are:
base
From Example 02, it is concluded that the existing data types are:
whole :radio.
real:area, length and pi.

Additional data to know:

There is a type of representation called scientific notation that is used


for very large or very small numbers.

Example: Given an arbitrary number:

367520100000000000000

it is represented in notation by breaking it down into groups of three digits:

367,520,100,000,000,000

and subsequently in the form of powers of 10, it is:

3.675201 x 1020

Examples:

2079546000000 = 2.079546 x 1012


8927645125 = 8.927645 x 109
0.000000032458 = 3.2458 x 10-8
0.0000000009284 = 9.284 x 10-10

5
Catholic University of the Angels of Chimbote
Faculty of Engineering
Professional School of Systems Engineering Subject: Algorithms and Programming

Expressions
They are combinations of constants, variables, operation symbols, parentheses, and names of
special functions that meet specific rules.

Examples:
.a+(b*3)/c
.5*a*b/(c+d)

1. ARITHMETIC EXPRESSIONS
They are analogous to mathematical formulas. The variables and constants are numerical (real or
whole) and the operations are the arithmetic ones.

Arithmetic Operators
Meaning Algebraic Operator Algorithmic Operator
Sum + +
Stay - -
Multiplication x *
Real division / /
Integer division / div
Exponentiation **,^
Modulo (remainder or mod
residue)
Table 1: Arithmetic Operators

The following will show the equivalences you should know between algebraic expressions and
arithmetic expressions.

Examples:

Algebraic Representation Algorithmic Representation


12 + 19 12 + 19
a-b a-b
35 5*7
6 + c (6 / 4) + c
4
37 3^7

Exercise 1: Convert the following expressions into algorithmic arithmetic expressions


algebraic:

7 ( a + b )
b) 8x + 9y + 3z
c) a2+ 2a - 3
d) x2- y2
e) p + q
r+s
t
f) a (cd)
bb

6
Catholic University of the Angels of Chimbote
School of Engineering
Professional School of Systems Engineering Algorithms and Programming

Note: Use a time of 5 minutes to solve parts a) to f) of the exercise.


1. Once you finish doing it, check your answers against the solution provided below.
presents.

Solution:

7 ( a + b ) 7 * (a + b)
b) 8x + 9y + 3z 8*x+9*y+3*z
c) a2+ 2a - 3 a squared plus 2 times a minus 3

d) x2- y2 x squared minus y squared

e) p + q (p + q) / (r + s / t)
r+s
t
f) a (cd) a/b*c*d
b

Exercise 2. Solve the following algorithmic arithmetic expressions:

a) 15 + 9 * 2 – 6 * 2 ^ 2
b) -8 / 4 * 6 + 3 ^ 2 * (10 / 5)

Note: To execute the steps on how to solve these arithmetic expressions, we must first
know the rules of priority

Priority rules
Expressions that have two or more operands in an expression are generally evaluated according to
the following order.

1. The operations that are enclosed in parentheses are evaluated first. If there are
different nested parentheses (one inside the other), the innermost expressions
they evaluate first.
2. Arithmetic operations within an expression usually follow the following order of
priority.

a. Exponential operator (^, ↑ or **)


b. Operators *, /
c. Div and mod operators
d. Operators + , -
Note:
In case several operators of equal priority coincide in an expression or subexpression
enclosed in parentheses, the order of priority in this case is from left to right.

Solution to exercise 2:

a) 15 + 18 - 24 b) -8 / 4 * 6 + 3 ^ 2 * (10 / 5)

15 + 9 * 2 – 6 * 4 -8 / 4 * 6 + 3 ^ 2 * 2

15 + 18 24 = 9 -8 / 4 * 6 + 9 2

-2 * 6 + 18 = 6

7
Catholic University of the Angels of Chimbote
Faculty of Engineering
Professional School of Systems Engineering Algorithms and Programming

Integer division (div)


It is the action of dividing two integers, one being the dividend and the other the divisor.
The result of the divisor operator is the value of the quotient. In this division, the importance of the
remainder. Remember that to use the divisor it applies to divisions of whole numbers, let’s see
the following example:

Example: 9 divided by 2 = 4

Dividend Divisor
9 2
84
1
Residue Quotient
Examples:
a. 15 divided by 6 equals 2 b. 14 divided by 2 = 7 c. 0 divided by 3 = 0
d. 7 divided by 9 = 0 e. 3 divided by 3 = 1 f. 2 divided by 5 = 0

Rules of real and integer division:


The operands can be integers (E) or reals (R).

Real division Integer division


Entero E/E=R E div E = E
E/R=R E div R = Not Valid
R/E=R results R div E = Not Valid
Real R/R=R R div R = Not Valid

operands

Residual (mod)
The modulus operator is used to obtain the remainder of an integer division. Just like for the
operator div, in order to find the remainder of a division using the operator mod, the
Operands must be exclusively integers.
Rules of the residue:
Residue
E mod E = E
E mod R = Not Valid
R mod E = Not Valid
R mod R = Not Valid

Examples:
15 mod 6 = 3 b. 14 mod 2 = 0 c. 19 mod 3 = 1
d. 7 mod 9 = 7 e. 3 mod 3 = 0 f. 2 mod 5 = 2

Internal functions
The operations required in the programs often demand, in addition to
the basic arithmetic operations, already addressed, a certain number of operators
special functions that are called internal, embedded or standard functions.

For example, the function raiz2 calculates the square root of a positive number, the function abs
returns the absolute value of a number, the square function returns the value of a number.
squared. There are other functions that are used to determine the functions
trigonometric.

8
Catholic University of the Angels of Chimbote
Faculty of Engineering
Professional School of Systems Engineering Algorithms and Programming

The following table collects the most common internal functions in algorithms, with 'x' being the
function argument.

The functions accept real or integer arguments and their results depend on the task that
perform the function:

Examples:

Table 5: Examples

You might also like