Daa L1
Daa L1
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
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
Design an algorithm
Prove correctness
PROBABILISTIC ANALYSIS
7
ANALYZING AN ALGORITHM
AMORTIZED ANALYSIS
8
Asymptotic analysis
10
ANALYZING AN ALGORITHM
11
ANALYZING AN ALGORITHM
12
Algorithm design techniques
13
Example
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