0% found this document useful (0 votes)
25 views77 pages

COSC 90 Lecture2A

lecture on the spot on the spot that I was thinking of you and the kids in the morning and I
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)
25 views77 pages

COSC 90 Lecture2A

lecture on the spot on the spot that I was thinking of you and the kids in the morning and I
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/ 77

DESIGN AND ANALYSIS OF

ALGORITHM
COSC 90

GRACE S. IBANEZ
Instructor
LESSON 2:
Fundamentals of the Analysis of
Algorithm
TOPICS:
◦ Review on Fundamentals of Data Structure
◦ Performance Analysis of Algorithm
◦ Time and Space Complexity
◦ Time Complexity of Loops
◦ Cost Method of Computing Time Complexity
◦ Worst, Best and Average Cases of Algorithm
OBJECTIVES:
To understand the field and goal of Data
Structures
Decide on the suitability of a specific
algorithm design technique for a given
problem
Learn how to analyze algorithms and
estimate their worst-case and average-case
behavior
WHAT IS DATA STRUCTURE?
Data Structure is a branch of Computer
Science. The study of data structure allows us
to understand the organization of data and the
management of the data flow in order to
increase the efficiency of any process or
program.
Data Structure is a particular way of storing and
organizing data in the memory of the computer
so that these data can easily be retrieved and
efficiently utilized in the future when required.
The data can be managed in various ways, like
the logical or mathematical model for a
specific organization of data is known as a data
structure.
Data Structures are the main part of many
Computer Science Algorithms as they allow the
programmers to manage the data in an
effective way. It plays a crucial role in
improving the performance of a program or
software, as the main objective of the software
is to store and retrieve the user's data as fast as
possible.
Non-
Data Structures and Algorithms are two of the
key aspects of Computer Science.

Data Structures allow us to organize and store


data, whereas Algorithms allow us to process
that data meaningfully.
Running Time
Measuring the Running
Time
Performance and Analysis of
Algorithm
An Algorithm is said to be efficient and fast if
it takes less time to execute and consume
less memory space.
In order to analyze the performance of an
algorithm:
◦ Time Complexity
◦ Space Complexity
TIME COMPLEXITY
The amount of time that an algorithm
requires of its execution if known as Time
Complexity
◦ 3 types of Time Complexity
● Best Case Time Complexity
● Worst Cast Time Complexity
● Average Case Time Complexity
Best Case Time Complexity
o If an algorithm requires minimum amount of
time for its execution then it is known as Best
Case Time Complexity.
Worst Case Time Complexity
o if an algorithm requires a maximum amount of
time for its execution then its is known as
Worst Case Time Complexity.
Average Case Time Complexity
o If an algorithm requires average amount of time
for its execution then it is known as Average
Case Time Complexity.
Linear search – example of Time
Complexity
Linear searching – process of searching an
element one by one until the key element is
found.
10 20 30 40 50
Best Case

10 20 30 40 50
Average Case

10 20 30 40 50

Worst Case
2 components to calculate Time Complexity
◦ Frequency count or Step count
◦ Asymptotic Notation
Components of Time Complexity
Capacity of the system
o If the speed of a computer is fast then output
generated is also fast
o If speed of the computer is slow then output will be
generated slowly
Computer contains processor/s
o If the computer contains only single processor then the
output is generated slowly
o If the computer contains multiple processors then the
output that will be generated is also fast.
Data Analysis
Experimental Algorithms
Algorithm Analysis
An important part of computational
complexity theory, which provides theoretical
estimation for the required resources of an
algorithm to solve a specific computational
problem.
Complexity Theory
Also called Computational complexity
It means the amount of computing resources
(time and space) that a particular algorithm
consumes when it runs.
TIME COMPLEXITY
▪ It is most commonly expressed using
the Big Oh-Notation
TIME COMPLEXITY
Mathematical Models for
Running Times
Theoretical Analysis of Time
Efficiency
Calculating Time
Complexity
1. Break the algorithm/function into individual
operations
2. Calculate the Big-O of each operation
3. Add up the Big-O of each operation
together.
4. Remove the constants
5. Find the highest order term
Space Complexity
The amount of working storage an algorithm
needs
SPACE COMPLEXITY
SPACE COMPLEXITY
SPACE COMPLEXITY
ORDER OF GROWTH
Order of growth of an algorithm is a way of
saying/predicting how execution time of a program
and the space/memory occupied by it changes with the
input size.
The most famous way is the Big-Oh notation. It gives
the worst case possibility for an algorithm.
For example a program takes O(n) time means it takes
at most n operations to compute the answer. Now if
your input for n is 10^6 , it takes 10^6 operations,
while a O(n^2) algorithm takes 10^12 operations for
the same input.
For finding the order of growth of a program : The part
of the program which takes the most amount of time is
generally assumed to be the order of growth in case of
the Big-Oh notation.
Quiz#2
I. Identify if directed or undirected graph
1. 2.

3. 4.
5. V = { }
6. E = { }
What are the degrees and neighborhoods of
the vertices in this graph?

7. deg(e) = ?

8. N(b) =?
9. Primary Operations of a Stack

10. Primary Operations of a Queue

11. If elements A, B, C, D are placed in a


queue, and are deleted one at a time. In what
order will they be removed?

12. If elements A, B, C, D are placed in a Stack,


and are deleted one at a time. In what order
will they be removed?
13. What is the Big-O of this expression.

14. What is the Big-Oh of a constant time?


15. What is the space complexity of this
algorithm?

You might also like