0% found this document useful (0 votes)
13 views17 pages

Daa L1

Uploaded by

gitu0744548
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views17 pages

Daa L1

Uploaded by

gitu0744548
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Apex Institute of Technology

Department of Computer Science & Engineering

Bachelor of Engineering (Computer Science & Engineering)

Design and Analysis of Algorithms– (21CSH-282)

12/09/2024 DISCOVER . LEARN . EMPOWER


1
Content

Analysis Framework: Worst case analysis.

Analysis Framework: Average case analysis

Analysis Framework: Best case analysis

2
Definition
What is an Algorithm?
• An algorithm is a well-defined procedure that allows a computer to solve a problem.
• An algorithm is a sequence of unambiguous instructions.
 An algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem.
 The word derived by the mathematician Mohammad Ibn-Musa-al-Khwarizmi, around 850 AD.
Al Khwarizmi’s work is the likely source for the word algebra as well.
• A sequence of instructions
• no of sequence or steps should be finite
• Initial instructions acquire valid input
• Intermediate instructions perform processing
• Final instructions produce valid output for the problem
• Algorithm terminates after a finite number of steps

3
Properties of Algorithm

• An algorithm must have five properties:


Input specified.
Output specified.
Definiteness.
Effectiveness.
Finiteness.

4
ANALYZING AN ALGORITHM

• Why is it important?
• Predict the feasibility requirement of your code (algorithm).
• Usual requirements
• Execution time
• Memory space
• The complexity of the algorithm is determined in terms of space and time.
• Space complexity ← memory space
• Time complexity ← execution time

5
ANALYZING AN ALGORITHM

Understand the problem

Decide on computational means


Exact vs approximate solution
Data structures
Algorithm design technique

Design an algorithm

Prove correctness

Analyze the algorithm

Code the algorithm


6
ANALYZING AN ALGORITHM

PROBABILISTIC ANALYSIS

Probabilistic analysis of algorithms is an approach to


estimating the computational complexity of an algorithm or
a computational problem. It starts from an assumption
about a probabilistic distribution of the set of all possible
inputs. This assumption is then used to design an efficient
algorithm or to derive the complexity of a known
algorithm.

7
ANALYZING AN ALGORITHM

AMORTIZED ANALYSIS

•Amortized analysis is a method of analyzing


algorithms that consider the entire sequence of operations
of the program. It allows for the establishment of a worst-
case bound for the performance of an algorithm irrespective
of the inputs by looking at all of the operations. This
analysis is most commonly discussed using big O notation.

8
Asymptotic analysis

 Asymptotic Notation is used to describe the running time of an algorithm -


how much time an algorithm takes with a given input, n. There are three
different notations: big O, big Theta (Θ), and big Omega (Ω).
 Asymptotic analysis of an algorithm refers to defining the mathematical
boundation/framing of its run-time performance.
 Using asymptotic analysis, we can very well conclude the best case, average
case, and worst case scenario of an algorithm.
 Asymptotic analysis is input bound i.e. if there's no input to the algorithm, it is
concluded to work in a constant time. Other than the "input" all other factors are
considered constant.
 Asymptotic analysis refers to computing the running time of any operation in
mathematical units of computation. For example, the running time of one
operation is computed as f(n), and maybe for another operation, it is computed
as g(n2). This means the first operation’s running time will increase linearly with
the increase in n and the running time of the second operation will increase 9
ANALYZING AN ALGORITHM

Usually, the time required by an algorithm falls under three types −


· Best Case − Minimum time required for program execution.

10
ANALYZING AN ALGORITHM

Average Case − Average time required for program execution.

11
ANALYZING AN ALGORITHM

Worst Case − Maximum time required for program execution.

12
Algorithm design techniques

• Divide and conquer algorithms.


• Greedy algorithms.
• Dynamic programming algorithms.
• Backtracking algorithms.
• Branch and bound algorithm

13
Example

Write an algorithm to determine a student’s final grade and indicate whether it


is passing or failing. The final grade is calculated as the average of four marks.
Algorithm:
• Input a set of 4 marks.
• Calculate their average by summing and dividing by 4.
• if the average is below 50
• Print “FAIL”
• else
• Print “PASS”

14
Example

Psuedocode:
• Step 1: Input M1,M2,M3,M4 .
• Step 2: GRADE (M1+M2+M3+M4)/4 .
• Step 3: if (GRADE < 50)
• then
• Print “FAIL”
• else
• Print “PASS”
• End if
15
References
• Fundamentals of Computer Algorithms 2nd Edition (2008) by Horowitz, Sahni
and Rajasekaran
• Introduction to Algorithms 3rd Edition (2012) by Thomas H Cormen, Charles E
Lieserson, Ronald

16
THANK YOU

For queries
Email: [email protected]

12/09/2024 17

You might also like