DAA Lecture 1
DAA Lecture 1
Algorithm
By: Hafsa Zaman
1. Start 1. Start
2. Generate a random number. 2. Input the first number. (num1)
3. Output a random number. 3. Input the second number.
4. Stop. (num2)
4. Add num1 & num2.
5. Output the result of addition.
6. Stop.
Characteristics of an Algorithm
1. Outputs: An Algorithm must produce at least one output.
Algorithm with one output Algorithm with two outputs
1. Start. 1. Start.
2. Input two numbers a & b. 2. Input two numbers a & b.
3. Perform some operations on a 3. Calculate the sum of a & b and
& b. store it n a variable sum.
4. Output the result. 4. Output the value of sum.
5. Stop. 5. Stop.
Characteristics of an Algorithm
1. Effectiveness: An Algorithm should take less time and space to
execute.
Less Effective Algorithm More Effective Algorithm
Number of Instructions = 2 + 4 + 1 = 7
Significance of Algorithm(Good Algorithm)
• Assume that a computer takes 1 second to execute y instructions, &
y = 100000000
time to run y instructions = 1 sec
Time to run 1 instruction = 1/y sec
Time to run x instruction = x/y sec
Time to run 7 instructions = 7/100000000
Total Time = 0.00000007 sec
Decidable Algorithms
• The Problem for which an efficient algorithms exist.
• Takes Polynomial Time or Less time to execute.
Terminates in
Decidable
Finite Input Polynomial
Algorithm
Time or Less
Undecidable Algorithms
• The Problem for which no efficient algorithms exist.
• Takes Exponential Time to execute.
Terminates in
Undecidable
Finite Input Exponential
Algorithm
Time
Polynomial Time vs Exponential Time
Polynomial Growth:
• Increases at a slower rate than exponential growth. Polynomial-
time algorithms are considered efficient and can perform
mathematical operations like addition, subtraction, and
multiplication.
Exponential Growth:
• Increases rapidly as input size increases. Exponential-time
algorithms are considered inefficient and can become infeasible
as the input size increases.
Example:
• An algorithm with polynomial time complexity might run in
O(n^2), while an algorithm with exponential complexity could
run in O(2^n).
Nature of Undecidable Problems
• Consider the world’s fastest computer is capable of executing 2^20
instructions per second.
2^45 = 1 year
2^100 = 2^100 / 2^45 = 2^55 years
Introduction to Analysis of Algorithm
• Study of an algorithm’s performance based on time and memory
space consumption.
• The algorithm taking least time and space is preferred.
• Independent of programming
• Dependent of programming language
language