Algorithm CH 1 Best
Algorithm CH 1 Best
Algorithm CH 1 Best
– Introduction to Algorithm
– How to analyze algorithm?
– Characteristics algorithms
– Algorithm Design – Asymptotic Notations
An algorithm is:
should not run for infinity, i.e., an algorithm must end at some point
problem.
better benefit
Design of Algorithm
Involves:
The description of the algorithm at an abstract level by
means of speudo-language.
Proof of correctness(Algorithm validation). The algorithm
should solve the given problem.
The important aspects of algorithm design include creating an
efficient algorithm to solve a problem in an efficient way using
minimum time and space.
Design of Algorithm…
However, one has to keep in mind that both time consumption and
Problem definition
Development of a model
Specification of an Algorithm
Designing an Algorithm
Analysis of an Algorithm
Implementation of an Algorithm
Program testing
Documentation
Exercise #1
1. What is Pseudocode ?
2. What are the difference between Algorithm and Pseudocode
3. Write an algorithms for the following questions
a) Roots of a quadratic equation ax2 + bx + c = 0
b) Check whether a number is a prime number or not
c) find the largest number among three different numbers
Analysis of algorithms
In theoretical analysis of algorithms, it is common to estimate their
complexity in the asymptotic sense, i.e., to estimate the complexity
function for arbitrarily large input.
The term "analysis of algorithms" was coined by Donald Knuth.
Algorithm analysis is an important part of computational
complexity theory, which provides theoretical estimation for the
required resources of an algorithm to solve a specific computational
problem.
Most algorithms are designed to work with inputs of arbitrary
length.
Analysis of algorithms…
and space resources required to execute it. i.e. predicting the resources
time complexity, or
mathematical skill.
CASE:PROBLEM
different algorithms?
For example, we know that a set of numbers can be sorted using different
algorithms.
for the same input. Hence, time complexity of those algorithms may differ.
At the same time, we need to calculate the memory space required by each
algorithm.
The Need for Analysis…
an algorithm.
algorithms are in terms of time, but some forms of analysis could be done
This space complexity analysis was critical in the early days of computing when
"Time" can mean the number of memory accesses performed, the number of
comparisons between integers, the number of times some inner loop is executed, or
some other natural unit related to the amount of real time the algorithm will take.
ii. Space Complexity
The space complexity of an algorithm is the amount of space (or memory) taken by
Space complexity includes both auxiliary space and space used by the input.
• Auxiliary space is the temporary or extra space used by the algorithm while it is being
executed.
•
i. O:Big Oh notations
‘O’ (Big Oh) -pronounced “big-oh of g of n”
To denote asymptotic upper bound(at most) i.e. maximum time complexity
•
Recurrences and Running Time
•Recurrences arise when an algorithm contains recursive calls to itself (i.e the way of
solving a problem by having a function call itself.)
– Recursive algorithm that loops through the input to eliminate one item
– Recursive algorithm that halves the input but must examine every item
in the input
– Recursive algorithm that splits the input into 2 halves and does a
constant amount of other work
Example #2- Recursive formula for factorials number
•
Assignment 1 (10%)
a. Master method
b. Recursion tree method
c. Iteration method
d. Substitution method