100% found this document useful (2 votes)
797 views12 pages

P6 Discuss How Asymptotic Analysis Can Be Used To Assess The Effectiveness of An Algorithm

Asymptotic analysis can be used to assess the effectiveness of an algorithm by analyzing its time and space complexity under different conditions. It determines the best, average, and worst case running times using mathematical notation like Big O, Ω, and Θ. These notations describe how an algorithm's running time increases with the input size to determine if it is efficient. Time complexity is assessed by calculating the number of operations, while space complexity considers memory usage like variables, instructions, and execution space. Together, complexity analysis provides a way to compare algorithms and better understand their performance.

Uploaded by

Raisha
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
100% found this document useful (2 votes)
797 views12 pages

P6 Discuss How Asymptotic Analysis Can Be Used To Assess The Effectiveness of An Algorithm

Asymptotic analysis can be used to assess the effectiveness of an algorithm by analyzing its time and space complexity under different conditions. It determines the best, average, and worst case running times using mathematical notation like Big O, Ω, and Θ. These notations describe how an algorithm's running time increases with the input size to determine if it is efficient. Time complexity is assessed by calculating the number of operations, while space complexity considers memory usage like variables, instructions, and execution space. Together, complexity analysis provides a way to compare algorithms and better understand their performance.

Uploaded by

Raisha
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/ 12

P6 Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm.

Asymptotic Analysis

Asymptotic analysis of an algorithm is defining the mathematical framing its run-time


performance. Using asymptotic analysis, we can conclude the best case, average case and worst-
case scenario of an algorithm. The big idea that can handles above issues in analyzing
algorithms. In Asymptotic Analysis, we evaluate the performance of an algorithm in terms of
input size but we don’t measure the actual running time. We calculate, how does the time or
space take by an algorithm increases with the input size.

For example, the running time of one operation is computed as f(n) and may be for another
operation it is computed as g(n2). This means the first operation running time will increase
linearly with the increase in n and the running time of the second operation will increase
exponentially when n increases. Similarly, the running time of both operations will be nearly the
same if n is significantly small.

(GeeksforGeeks, 2019)
How it can be used to find effectiveness of an algorithm

They are finding out more effectiveness of an algorithm can be used so we time required by
algorithm falls under the three types: Worst case maximum time required by an algorithm and it
is mostly or done while analyzing the algorithm.

The commonly used notation for calculating the running time complexity of the algorithm as
follows:

 Big O notation
 Big θ notation
 Big notation

Big Oh Notation, O

Big O is used to measure the performance or complexity of an algorithm. In mathematical term it


is upper bound of growth rate of a function, or that if a function g(x) grows no faster than a
function f(x), then g is said to be member of O(f). In general, it used to express the upper bound
of an algorithm and which gives the measure for the worst time complexity or the longest time
an algorithm possibly takes to complete. Big-oh is the formal method of mention the upper
bound of an algorithm’s running time. It is the measure of the longest amount of time. The
function f (n) = O (g (n)) [read as “f of n is big-oh of g of n”] if and only if exist positive
constant c and such that

(DataCamp Community, 2019)

F(n) ⩽K.g (n)f(n) ⩽K.g(n) for n>n0n>no in all case

Hence, function g (n) is upper bound for function f (n), as g (n) grows faster than f (n)
For Example:

1. 3n+2=O(n) as 3n+2≤4n for all n≤2


2. 3n+3=O(n) as 3n+3≤4n for all n>3

Hence, the complexity of f(n) can be represented as O (g (n))

Big Omega Notation, Ω

The notation Ω (n) is the formal way to express the lower bound of an algorithm’s running
time. It measures the best-case time complexity or the best amount time an algorithm can
possibly take to complete. The function f (n) = Ω (g (n)) [“f of n is omega of g of n”] if and
only if there exists positive constant c and no such that

(DataCamp Community, 2019)

F (n) ≥ k * g (n) for all n, n ≥ no


For Example:

F (n) = 8n2 + 2n – 3 ≥ 8n2 – 3

= 7n2 + (n2 - 3) ≥ 7n2 (g(n))

K1 = 7

Big Theta Notation, θ

The notation θ (n) us the formal way to express the lower bound of an algorithm running time.
It measures the best-case time complexity or the best amount of time an algorithm can possibly
take to complete. The function f (n) = θ (g (n)) [“f is the theta of g of n”] if and only if there
exists positive constant k1, k2 and k0 such that (DataCamp Community, 2019)
For Example:

3n + 2 = θ (n) as 3n + 2 ≤ 3n and 3n + 2 ≤ 4n, for n

k1 = 3, k2 = 4 and n0 = 2

Hence, the complexity of f (n) can be represented as θ (g (n)).

The Theta Notation is precise than both the big – oh and Omega notation. The function f (n) =
function f (n) = θ (g (n)) if g(n) is both an upper and lower bound.

They more efficiency of an algorithm can be measured can performs better than second so inputs
second perform better. They can work better on machine in inputs such as

1. Time complexity
2. Space complexity
3. Complexity theory

Time complexity

Time complexity of algorithm is commonly used big O notation. It is an asymptotic notation to


represent of time complexity. Time complexity estimates how an algorithm performs anyhow
kind of machine it runs on. We can get the time complexity by counting the number of operations
can performed in code. This time complexity is defined as function of the input size n using Big-
O notation n indicates the magnitude of input while O is growth rate in function. Big-) notation
based in running time or space (memory used) as input grow rate. The O function is growth rate
in function of input size n.

(Adrian Mejia | JavaScript, Algorithms and Web development Tutorials, 2019)

Example

Here

In this case, in each assign the number, light, iteration of i, inner loop is executed 'n' times. The
time complexity of a loop is equal to the number of times the innermost statement is to be
executed. Additionally, we will stir this up with one more addition at the end. So, this is how we
stand at the moment: 2 declarations, 2 assignments, n comparisons, n additions, n assignments, 1

addition, 1 assignment and 1 method call.

Cost Number of Time


1 1
1 1
1 n
1 n
1 n
2 n+1
1 n

Total cost = 1 + 1 + n + n + n+ n + 1 + n

= 4n + 3

T(n) = 4n + 3 = O(n)

Space complexity

Space complexity is an algorithm is total space take by algorithm with regard to input size. Space
complexity both auxiliary space and space used by input. They execute an algorithm can be
loaded in memory. The memory can be used in different forms are

1. Variable
2. Program instruction
3. Execution

Memory usage during program execution

1. Instruction Space can used to store the addresses while a module calls another module or
functions during execution
2. Data space can use to store data, variables and constants which ae stored by the program
and updated during execution.

(Tutorialspoint.com, 2019)

Example

Instance of RoadRunnable () three parameter are store variable: roadNumber, TraffcLight aLight

To store queue = 3

To store i = n

Space complexity = n + 3

Complexity theory

Complexity theory is direct application to computability theory and use of computation model
such as Turing machines to help test the complexity. Complexity theory helps for programmer
relate and group problems together into complexity classes. If one problem can solve, it opens a
way to solve a particular problem. For example, some problems can solve in polynomial amounts
of time and others take exponential amounts of time to the input the size.

They more efficiency of an algorithm can be measured can performs better than second so inputs
second perform better. They can work better on machine in inputs such as

1. Time complexity
2. Space complexity
3. Complexity theory

Time complexity

Time complexity of algorithm is commonly used big O notation. It is an asymptotic notation to


represent of time complexity. Time complexity estimates how an algorithm performs anyhow
kind of machine it runs on. We can get the time complexity by counting the number of operations
can performed in code. This time complexity is defined as function of the input size n using Big-
O notation n indicates the magnitude of input while O is growth rate in function. Big-) notation
based in running time or space (memory used) as input grow rate. The O function is growth rate
in function of input size n.

(Adrian Mejia | JavaScript, Algorithms and Web development Tutorials, 2019)

Example
Here

In this case, in each assign the number, light, iteration of i, inner loop is executed 'n' times. The
time complexity of a loop is equal to the number of times the innermost statement is to be
executed. Additionally, we will stir this up with one more addition at the end. So, this is how we
stand at the moment: 2 declarations, 2 assignments, n comparisons, n additions, n assignments, 1

addition, 1 assignment and 1 method call.

Cost Number of Time


1 1
1 1
1 n
1 n
1 n
2 n+1
1 n
Total cost = 1 + 1 + n + n + n+ n + 1 + n

= 4n + 3

T(n) = 4n + 3 = O(n)

Space complexity

Space complexity is an algorithm is total space take by algorithm with regard to input size. Space
complexity both auxiliary space and space used by input. They execute an algorithm can be
loaded in memory. The memory can be used in different forms are

1. Variable
2. Program instruction
3. Execution

Memory usage during program execution

1. Instruction Space can used to store the addresses while a module calls another module or
functions during execution
2. Data space can use to store data, variables and constants which ae stored by the program
and updated during execution.

(Tutorialspoint.com, 2019)

Example
Instance of RoadRunnable () three parameter are store variable: roadNumber, TraffcLight aLight

To store queue = 3

To store i = n

Space complexity = n + 3

You might also like