Professional Documents
Culture Documents
Muhammad Naman
Objectives
Design algorithms using different
algorithms design techniques i.e. Divide
and Conquer, Dynamic Programming,
Greedy Algorithms & Backtracking etc for
different problem areas (sorting, pattern
matching, graphs, compression, encryption
etc.)
Analyse Algorithms (estimate upper &
lower bounds without coding and running
the algorithms) and compare the efficiency
of more than one algorithm for a problem.
Logically think and develop problem solving
skills
Read and understand research papers in
this area
What is an Algorithm?
Although there is no universally
agreed-on wording to describe this
notion, there is general agreement
about what the concept means:
An algorithm is a sequence of
unambiguous instructions for solving
a problem, i.e., for obtaining a
required output for any legitimate
input in a finite amount of time.
What is an Algorithm?
What is an Algorithm?
The reference to "instructions" in the
definition implies that there is something or
someone capable of understanding and
following the instructions given.
We call this a "computer," keeping in mind
that before the electronic computer was
invented, the word "computer" meant a
human being involved in performing
numeric calculations.
Nowadays, of course, "computers" are
those ubiquitous electronic devices that
have become indispensable in almost
everything we do.
illustrate several important points
As examples illustrating the notion of
algorithm, we consider three methods
for solving the same problem (detail
in Lecture 02):
Computing the greatest common
divisor of two integers.
These examples will help us to
illustrate several important points:
The non-ambiguity requirement for
each step of an algorithm cannot be
compromised.
illustrate several important points
The range of inputs for which an
algorithm works has to be specified
carefully.
The same algorithm can be
represented in several different ways.
Several algorithms for solving the
same problem may exist.
Algorithms for the same problem can
be based on very different ideas and
can solve the problem with
dramatically different speeds.
Process to Solve a Problem
Understand the problem
Formulate a solution / algorithm
Design a program
Implement the program
Execute the code
Measure the performance
See if the solution is ok
Sorting Problem
Consider the problem of sorting
numbers.
INPUT: Sequence of n numbers
<a1,a2,a3, ….an>
OUTPUT: Permutation (reordering)
<a1`,a2`,a3`,….an`> of the input
sequence such that
a1`<a2`<a3`<…..<an`
Many algorithms are available.
Selection Sort
700
600
Execution time in seconds
500
200
100
0
n
n
K
o
La
75
10
30
illi
illi
illi
M
M
2
M
2
10
Data Size
Process to Solve a Problem
Understand the problem
Formulate a solution / algorithm
Analyze the algorithm
Design a program
Implement the program
Execute the code
Measure the performance
Memory
Communications Bandwidth
m
Tn ti
i 1
Sequence
Selection
Iterations
Recursion
Algorithm Analysis
Sequence Statements: Just add the running time of
the statements
If-Then-Else: if (condition) S1 else S2
Running time of the test plus the larger of the
running times of S1 and S2.
Iteration is at most the running time of the statements
inside the loop, (including tests) times the number
of iterations.
Nested Loops: Analyze these inside out. The total
Running time of a statement inside a group of nested
loops is the running time of the statement multiplied
by the product of the size of all the loops.
Function Calls: Analyzing from inside to out. If
there are function calls, these must be analyzed first.
Home Work
Read Mathematics Revision Handouts
available at photocopy shop
Assignment # 1
Due date Wednesday (27 August 2019) at
Commencement of Class.