COSC 90 Lecture2A
COSC 90 Lecture2A
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.
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