Data structures and algorithm, Study notes of Data Structures and Algorithms

this doc use for it students so every study well

Typology: Study notes

2021/2022

Uploaded on 05/21/2022

taniya-sharon
taniya-sharon 🇱🇰

1 document

1 / 18

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download Data structures and algorithm and more Study notes Data Structures and Algorithms in PDF only on Docsity!

HND in Computing and Software

Engineering

SEC5213: Data Structures and Algorithm

Level: 5 Credit Value: 20

Lesson 03 – Asymptotic analysis of algorithms

Lecturer: Ms. Sathananthy 1 05/21/

Learning Outcome 03

Evaluate algorithms and data structures in terms of

time complexity

2 05/21/

Asymptotic Notation A problem may have numerous algorithmic solutions. In order to choose the best algorithm for a particular task, you need to be able to judge how long a particular solution will take to run. Need a way to compare algorithms with one another. Asymptotic Complexity is a way of expressing the main component of the cost of an algorithm, using idealized units of computational work.

Asymptotic Analysis – contd. 5 05/21/ In mathematical analysis, asymptotic analysis of algorithm is a method of defining the mathematical bound of its run-time performance. Using the asymptotic analysis, we can easily conclude about the average case, best case and worst case scenario of an algorithm. It is used to mathematically calculate the running time of any operation inside an algorithm.  Example: Running time of one operation is x(n) and for another operation it is calculated as f(n^2 ). It refers to running time will increase linearly with increase in 'n' for first operation and running time will increase exponentially for second operation. Similarly the running time of both operations will be same if n is significantly small.

Asymptotic Analysis – contd. 7 Usually the time required by an algorithm comes under three types:  Worst case: It defines the input for which the algorithm takes the huge time.  Average case: It takes average time for the program execution.  Best case: It defines the input for which the algorithm takes the lowest time. 05/21/

Asymptotic Notations 8

The commonly used asymptotic notations used for calculating the

running time complexity of an algorithm is given below:

Big oh Notation (Ο)

Omega Notation (Ω)

Theta Notation (θ)

05/21/

Big O Notation

 Insert into an unordered array

Time taken to insert an item into an unordered array is

constant

The time does not depend on the number of items

Always time T=k

 Linear search

Proportional to number of items N

T∝ N

T=k*N

10

Big O Notation  Binary search  Proportional to log(N) T ∝log2(N) T= k* log2(N)  T=k*log(N) 11

Omega Notation (Ω)

13 05/21/

Theta Notation (θ) 14 05/21/ It is the formal way to express both the upper bound and lower bound of an algorithm running time. Consider the running time of an algorithm is θ (n) , if at once (n) gets large enough the running time is at most k2-n and at least k1? n for some constants k1 and k2. It is represented as shown below:

Exercises 16 05/21/

  1. Prove that running time T(n) = n 3 + 20n + 1 is O(n 3 )
  2. Prove that running time T(n) = n 3 + 20n + 1 is not O(n 2 )
  3. Prove that running time T(n) = n 3 + 20n + 1

Exercises 17 05/21/ Assume that each of the expressions gives the processing time T(n) spent by an algorithm for solving a problem of size n. Select the dominant term(s) having the steepest increase in n and specify the lowest Big-Oh complexity of