You are on page 1of 38

Fundamentals of Algorithms

Presented by
JIMMY DE VERA ROLDAN, MSIT
CS202– Design and Analysis of Algorithms
Bachelor of Science in Computer Science

” Be a Gabrielian: We Care, your Legacy to Share”


What is an Algorithm?
An algorithm is a step-by-step problem-solving
procedure, especially an established, recursive
computational procedure for solving a problem in a
finite number of steps.
Algorithms are used in many activities and come in
many forms. These involve instructions for
assembling kits (e.g. furniture, toys), recipes, steps
for processing credit card approvals, or directions
to a destination.

” Be a Gabrielian: We Care, your Legacy to Share”


What is an Algorithm?
An algorithm is a well-defined procedure to solve a
problem and the study of algorithms is a
fundamental area of computer science. In writing a
computer program to solve a problem, a
programmer expresses in a computer language an
algorithm that solves the problem, thereby turning
the algorithm into a computer program.

” Be a Gabrielian: We Care, your Legacy to Share”


Algorithmic
Algorithmic is the study of algorithm and is more than a
branch of computer science. It is the core of
computer, and, in all fairness, can be said to be
relevant to most business and technology.

” Be a Gabrielian: We Care, your Legacy to Share”


Importance of Studying Algorithm

Studying algorithms becomes a necessity for more and


more people because it is essential in different
aspects of our professional and personal lives
through computer programs. Therefore, computer
programs would not exist without algorithms.
Another reason for studying algorithm is their
usefulness in developing analytical skills.
Algorithms can be seen as special kinds of solution
to problems – not answers but precisely defined
procedures for getting answers.

” Be a Gabrielian: We Care, your Legacy to Share”


Notion of Algorithm
The word “instructions” implies that there is something
capable of understanding and following the given
instructions.
Algorithms are essential to the way computers process
information, because a computer program is
essentially an algorithm that tells the computer
what specific steps to perform (in what specific
order) in order to carry out a specified task, such as
calculating employee‟s paychecks or printing
student‟s report cards.

” Be a Gabrielian: We Care, your Legacy to Share”


Notion of Algorithm
Problem

Algorithm

Computer

INPUT OUTPUT

” Be a Gabrielian: We Care, your Legacy to Share”


Notion of Algorithm
The notion of algorithm starts from defining a problem
cautiously by describing the set of instances it must
work on. Several algorithms for solving the same
problem can be identified because the same
problem may be based on different ideas.
Typically, when it is associated with processing
information, data is read from an input source or
device, written to an output device, and/or stored
for further use. Stored data is regarded as part of
the internal state of the entity performing the
algorithm and is stored in a data structure.

” Be a Gabrielian: We Care, your Legacy to Share”


Notion of Algorithm
Algorithms for making things will often be divided into
sections; the parts/components/ingredients (inputs)
required in accomplishing the task and the
actions/steps/methods (processing) in producing
the required outcome (output).

” Be a Gabrielian: We Care, your Legacy to Share”


Notion of Algorithm Process
Problem Algorithm
How to build Finite steps
a model car? in building a
model car

The parts The


needed to assembled
build a car
model car INPUT Computer OUTPUT

” Be a Gabrielian: We Care, your Legacy to Share”


Representation of Algorithm
It is important that the designed algorithms are
unambiguous and precise to make it easier to
follow. Mostly, similar layouts and terminologies are
being followed to produce a good one.
In a real world, we dealt with algorithm by giving
instructions going to a particular place or following
a recipe cook book.

” Be a Gabrielian: We Care, your Legacy to Share”


Representing Algorithm in
Programming
A flowchart is a diagrammatic representation that
illustrates the sequence of operations to be
performed to get the solution of a problem. It plays
a vital role in programming and quite helpful in
understanding the logic of complicated and lengthy
problems. Once a flowchart is drawn, it is easier to
write the program in any programming language.
Often, you see how flowcharts are helpful in
explaining the program to others.

” Be a Gabrielian: We Care, your Legacy to Share”


Representing Algorithm in
Programming
Pseudocode means fake code because it is not really
programming code, but it specifies the steps
required to accomplish the task. It is a type of
structured English that is used to specify an
algorithm.

” Be a Gabrielian: We Care, your Legacy to Share”


Fundamentals of Algorithmic
Problem Solving
Algorithms are procedural solutions to different types of
problems. These solutions are not answers but
specific instructions for getting answers. Analyzing
and designing algorithm is said to be effective if it
follows the algorithm design and analysis process
which is consists of well-defined constructive
procedures in designing good algorithm.

” Be a Gabrielian: We Care, your Legacy to Share”


Phases of the Design and Analysis
of Algorithms
1. Understanding the problem.
2. Deciding on the computational means, data
structures and algorithm design technique.
3. Designing an algorithm.
4. Proving the correctness of algorithm.
5. Analyzing the algorithm
6. Coding the program for implementation.

” Be a Gabrielian: We Care, your Legacy to Share”


Understanding the Problem
From a practical perspective, the first thing you need to
do before designing an algorithm is to understand
the problem completely. Read the problem‟s
description carefully and ask questions if you have
any doubts about the problem, do a few small
examples by hand, think about special cases, and
ask questions again if needed.

” Be a Gabrielian: We Care, your Legacy to Share”


Understanding the Problem
An input to an algorithm specifies an “instance” of the
problem the algorithm solves. It is very important to
specify exactly the range of instances the algorithm
needs to handle. If you fail to do this, your
algorithm may work correctly for a majority of
inputs, but may crush on some “boundary” value.
Remember that a correct algorithm is not the one
that works most of the time, sometimes it depends
on the type of input the user provides.

” Be a Gabrielian: We Care, your Legacy to Share”


Ascertaining the Capabilities of a
Computational Device
Once you completely understand a problem, you need
to establish the capabilities of the computational
device the algorithm is intended for.
The essence of this architecture is captured by the
random-access machine (RAM) where all
instructions are executed one after another, one
operation at a time. Accordingly, algorithms
designed to be executed on such machines are
called sequential algorithms.

” Be a Gabrielian: We Care, your Legacy to Share”


Ascertaining the Capabilities of a
Computational Device
The central assumption of the RAM model does not
hold for some newer computers that can execute
operations concurrently. Algorithms that take
advantage of this capability are called parallel
algorithms.
In designing an algorithm applying scientific exercises,
the speed and amount of a computer‟s memory for
disposal is not really an issue. Most computer
scientists prefer to study algorithms in terms
independent of specification parameters for a
particular computer.

” Be a Gabrielian: We Care, your Legacy to Share”


Ascertaining the Capabilities of a
Computational Device
But, if in designing an algorithm as a practical tool, it
may depend on the problem that needs to be
solved because “slow” computers of today are
almost imaginably fast

” Be a Gabrielian: We Care, your Legacy to Share”


Choosing Between Exact and
Approximate Problem Solving
The next principal decision is to choose between
solving the problem exactly and solving it
approximately.
Exact algorithm - algorithms used to find exact
solutions.
Approximation algorithm - algorithms used to find
approximate solutions.

” Be a Gabrielian: We Care, your Legacy to Share”


Reasons for not considering an
approximation algorithm
1. There are important problems imply that cannot be
solved exactly for most of their instances like
extracting square roots, and evaluating definite
integrals.
2. Algorithms for solving problem exactly can be
unacceptably slow because of the problems intrinsic
complexity. This happened in particular, for many
problems involving very large number of choices.
3. An approximation algorithm can be part of a more
sophisticated algorithm that solves a problem
exactly.
” Be a Gabrielian: We Care, your Legacy to Share”
Deciding on Appropriate Data
Structures
As with all the problems in computer science, there is
more than one solution to which data structure
should be used. Some are clearly better than
others, but sometimes the distinction may not be so
clear. Before choosing a data structure, it is
important to work out what the priorities should be.

” Be a Gabrielian: We Care, your Legacy to Share”


Algorithm Design Techniques
Algorithm design technique is a general approach to
solving problems algorithmically that is applicable to
a variety of problems from different areas of
computing.
Algorithm design technique is important because of the
following reasons:
• It provides guidance for designing algorithms for
new problems.
• It makes it possible to classify algorithms
according to an underlying design idea;
therefore, it can serve as a natural way to both
categorized and studied algorithm.
” Be a Gabrielian: We Care, your Legacy to Share”
Methods of Specifying an
Algorithm
Common methods of specifying an algorithm include:
• Pseudocode
• Flowchart

” Be a Gabrielian: We Care, your Legacy to Share”


Proving an Algorithm’s
Correctness
Proving the correctness of an algorithm is similar to
proving a mathematical theorem; fundamentally, it’s
algorithm-dependent. Once an algorithm has been
specified, you have to prove its correctness. That is,
you have to prove that the algorithm yields a
required result for every legitimate input in a finite
amount of time.
If an algorithm is incorrect, you need just one instance of
its input for which the algorithm fails. If the algorithm
is found to be incorrect, you need to either redesign
it under the same decisions regarding the data
structures, the design technique etc.
” Be a Gabrielian: We Care, your Legacy to Share”
Analyzing an Algorithm
In analyzing an algorithm, several qualities should be
considered such as:
• Correctness.
✔ Generates correct output.
• Efficiency.
✔ Time efficiency indicates how fast the
algorithms run.
✔ Space efficiency indicates how much extra
memory the algorithm needs.

” Be a Gabrielian: We Care, your Legacy to Share”


Analyzing an Algorithm
• Simplicity
✔ Easier to understand
✔ Easier to program
✔ Fewer errors
✔ More efficient than more complicated
alternatives
• Generality
✔ Easier to design an algorithm for a problem in a
general form

” Be a Gabrielian: We Care, your Legacy to Share”


Coding an Algorithm
Algorithms are created to be implemented as computer
programs. The validity is established by testing and
debugging programs thoroughly since it is the main
consideration whenever you implement an
algorithm.
A running program provides an additional opportunity in
allowing practical analysis of the underlying
algorithm. The analysis is based on timing the
program on several inputs and then analyzing the
results.

” Be a Gabrielian: We Care, your Legacy to Share”


Important Problem Types
The following are the different types of problems
encountered in designing and analyzing algorithms:
• Sorting
• Searching
• String processing
• Graph problems
• Combinatorial problems
• Geometrical problems
• Numerical problems

” Be a Gabrielian: We Care, your Legacy to Share”


Sorting
The sorting problem asks to rearrange the items of a
given list in ascending order.
Sorting is important in answering different questions
about a list because it puts elements of a list in a
particular order, may it be numerical or alphabetical
order, which is essential in order to optimize the use
of other algorithms such as search and merge
algorithms that require sorted lists to work correctly.
With sorting, you can search the meaning of the
word in a dictionary, look for a student name in the
class list or even find the contact numbers of a
friend in a telephone directory easily.
” Be a Gabrielian: We Care, your Legacy to Share”
Searching
The searching problem deals with finding a given value
called the key in a given list or set.
Searching algorithm is important in real-life applications
because they are necessary for storing and
retrieving information from large databases.

” Be a Gabrielian: We Care, your Legacy to Share”


String Processing
A string processing problem deals with non-numerical
that intensifies the interest of researchers and
computing practitioners in string-handling
algorithms.

” Be a Gabrielian: We Care, your Legacy to Share”


Graph Problems
Graph problems deal with objects and their connections
like determining whether all of the locations are
connected, visiting all of the locations that can be
reached from a given location, or finding the
shortest path from one location to another.

” Be a Gabrielian: We Care, your Legacy to Share”


Combinatorial Problems
Combinatorial problems are the most difficult problems
in computing that ask (explicitly or implicitly) to find
a combination of an object such as permutation,
combination or a subset that satisfies certain
constraints and has some desired property.

” Be a Gabrielian: We Care, your Legacy to Share”


Geometrical Problems
The Geometrical problems deal with geometric objects
such as points, lines, and polygons. Ancient Greeks
were very much interested in developing
procedures for solving a variety of geometric
problems including constructing simple geometrical
shapes – triangles, circles etc. with an unmarked
ruler or compass.
Nowadays, people are interested in geometric
algorithms with quite different applications in mind,
such as computer graphics, robotics and
tomography.

” Be a Gabrielian: We Care, your Legacy to Share”


Numerical Problems
Numerical problems involve mathematical objects of
continuous nature such as solving equations,
system equations, computing definite integrals,
evaluating functions etc.

” Be a Gabrielian: We Care, your Legacy to Share”


Fundamentals of Algorithms

Presented by
JIMMY DE VERA ROLDAN, MSIT
CS202– Design and Analysis of Algorithms
Bachelor of Science in Computer Science

” Be a Gabrielian: We Care, your Legacy to Share”

You might also like