You are on page 1of 15

1

Algorithms and
Data Structures

Course 1
Algorithms

1 11/6/2017 9:18 PM
2 2

Objectives of this course

Objectives:
 to design "good" algorithms and "good" data:
– algorithm – a step-by-step procedure for performing
some task in a finite amount of time
– data structure – a systematic way of organizing and
accessing data
Recommended resources:
 Anil Bikas Chaudhuri, "The Art of Programming through
Flowcharts & Algorithms", Publisher: Firewall, 2005
 Sanjay Pahuja, "A Practical Approach to Data Structures
and Algorithms", Publisher: New Age International, 2010
3 3

Programming (1)

 The programming activity is the process of designing,


writing, testing and debugging a program for solving a
problem or a class of problems.
 A computer program (also software, or just a program)
is a sequence of instructions written in a programming
language (C++, C#, Java, Visual Basic etc.), in order to
perform a specified task with a computer.
 The process of writing source code often requires
expertise in many different subjects, including knowledge
of the application domain, specialized algorithms and
formal logic.
4 4

Programming (2)

 In the programming activity we can identify the following


steps:
– formulating the problem
– developing and describing the algorithm to solve the
given problem
– writing the program
– testing the program
– creating, completing and finalizing the documentation of
the program
– current exploitation and utilization of the program
5 5

Algorithms (1)

 The notion of algorithm, taken from mathematics, is


fundamental to programming.
 While there is no generally accepted formal definition of
the term algorithm, an informal definition could be as
follows: a set of rules that precisely defines a
sequence of operations necessary for solving a
problem or a class of problems.
 Any algorithm starts from some initial data, which it
processes according to certain rules specified by the
algorithm itself, it passes through a series of intermediary
data, in order to obtain the final information.
6 6

Algorithms (2)

 In other words, an algorithm is a sequence of


unambiguous instructions for solving a problem
– it should obtain a required output for any valid input in a
finite amount of time
– the range of inputs must be specified precisely
– each step of the algorithm must be unambiguous
– it is not a solution to the problem, but a method for
finding a solution
– it doesn’t necessarily require implementation in software
– the same algorithm can be represented in different ways
– several algorithms for solving the same problem may exist
7 7

Algorithms (3)

problem

algorithm

input program output


8 8

Properties of algorithms (1)

 Each algorithm must satisfy some fundamental


properties:
– generality
– finiteness
– determinism
– uniqueness
– clarity, precision
9 9

Properties of algorithms (2)

 Generality – commonly the algorithm does not solve a


single problem or a particular one, but a class of
problems of the same type. In other words, the algorithm
can be applied to initial data that can vary within certain
specified limits.
 Finiteness – the final solution can be obtained after
executing a number of transformations on the initial data.
Otherwise, the algorithm will allow for the infinite
processing of initial or intermediate data (we say that the
algorithm loops, consequently it is incorrect).
10 10

Properties of algorithms (3)

 Determinism – the algorithm must cover all possible


cases that may occur in solving that class of problems.
In this way we will be removing any ambiguities and
uncertainties.
 Uniqueness – the transformations that are used for
obtaining the final data starting from the initial ones, and
their order, are uniquely determined by the algorithm. In
other words, if we apply the same algorithm to the same
data several times, it is not acceptable to get different
results.
11 11

Properties of algorithms (4)

 Clarity, Precision – the algorithm must clearly and


accurately specify, at every moment, which is the next
step in solving the given problem. Also, the steps must
be sufficiently simple, basic, and, most important,
unambiguous. Therefore, we cannot use ambiguous
expressions in describing the algorithm, and we must
ensure that the implemented operations can be
executed​​.
12 12

The structure of an algorithm (1)

 In terms of structure, an algorithm consist of the following


phases:
 Initialization – this phase aims to provide (read) the
initial data that will be processed, and to assign the initial
values of some variables that will change during the
execution.
The inputs are variables that can take values ​from a
well-defined set of values.
The assignment of the inputs is done, usually, in one of
the early stages of the algorithm.
13 13

The structure of an algorithm (2)

 Processing – it is the actual transformation of the initial


data (calculations, decisions and other operations), in
order to obtain the final solution.
 Presentation of the final solution – this consists in
presenting, displaying or transmitting the final results
obtained after the specified processing.
The outputs are variables which keep the results of the
calculation. They will be then displayed or stored in the
desired format.
14 14

Expressing algorithms

 An algorithm must be presented in a form which is


accepted by other programmers or by a computer.
 Algorithms can be expressed in many kinds of notation,
including:
– natural language
– flowcharts
– pseudocode
– programming languages
15 15

The END

You might also like