Professional Documents
Culture Documents
Measurement of Time Complexity of An Algorithm
Measurement of Time Complexity of An Algorithm
02
Objective(s): Upon completion of this lab session, Student will be able to
understand the following concepts
1 Analysis of an algorithm
2 Time Complexity
3 Difference between two algorithms
LabTask(s):
Write programs for following two different algorithm for finding that given number is
1 prime or not
2 Calculate times taken by these program for given values and conclude which
algorithm is better than other
i. n = 11
ii. n = 101
iii. n=1000003
iv. n = 10000000019
Note: Let’s assume computer takes 1 mili-second for division operation. In the worst
case first algorithm loop will exactly (n-2) times or (n-2) division and in second
algorithm (√n – 1) times
LAB ACTIVITIES RELATED THEORY
Algorithms and Its Analysis
An algorithm is a finite set of precise instructions for performing a computation or for solving a
problem.
Departemnent of Computer Sciences 2/3 Semester Spring 2016
CSL-221: Data Structures & Algorithms Lab 02: Time Complexity
Time Complexity
In computer science, the time complexity of an algorithm quantifies the amount of time taken
by an algorithm to run as a function of the length of the string representing the input
(Wikipedia)
Example:
Example Continue…
--------------------------------------------------------------END-----------------------------------------------------------