SlideShare a Scribd company logo
Course Name: Design and Analysis of Algorithm
Topic: Introduction to Algorithms, Specification of Algorithm
Course code : CS3102
Credits : 4
Mode of delivery : Hybrid (PowerPoint presentation)
Faculty : Dr. Ajit Noonia
Email-id : ajit.noonia@jaipur.manipal.edu
B.TECH V SEM CSE
ACADEMIC YEAR: 2024-2025
1
Assessment criteria’s
9/4/2024 2
Course Information
• Course Handout
• Communicate through eMail
• Office hours
• To be communicated
• Grading policy
• Will be communicated as per university guidelines
9/4/2024
CS3102 (DAA), Dept. of CSE
3
Syllabus
Introduction: Algorithm Definition and Criteria of Algorithms, Iterative and Recursive
Algorithms. Performance Analysis: Priori and Posteriori Analysis, Asymptotic Notations,
Space Complexity, Time Complexity, Performance measurement of iterative and recursive
algorithms. Solving Recurrence Relations: Substitution Method, Iterative Method, Recursive
Tree Method, Master Method. Divide and Conquer: Introduction, Binary Search, Finding
Maximum and Minimum, Merge Sort, Quick Sort, Randomized Quick Sort, Integer
Multiplication. Graph Search Algorithm: Graph representation, Breadth First Search, and
Depth First Search. Greedy Strategy: Introduction, Knapsack Problem, Job Sequencing with
Deadlines, Huffman Coding, Union and Find Operation (Set and Disjoint Set), Minimum Cost
Spanning Tree Algorithms (Prim’s and Kruskal’s), Optimal Merge Patterns, Single Source
Shortest Path (Dijkstra’s Algorithm). Dynamic Programming: Introduction, Single Source
Shortest Path (Bellman and Ford Algorithm), All Pair Shortest Path (Floyd Wrashal’s
Algorithm), Optimal Binary Search Trees, 0/1 Knapsack Problem, Travelling Salesperson
Problem, Longest Common Subsequence, Matrix Chain Multiplication, Edit distance.
Backtracking: Introduction, N-Queens Problem, Graph Colouring, and Hamiltonian Cycles.
Branch and Bound: Introduction, FIFO and LC Branch and Bound, 0/1 Knapsack Problem,
Travelling Salesman Problem. String Matching: Naïve String Matching, Rabin Karp Algorithm,
Knuth-Morris-Pratt Algorithm. Complexity Classes: NP, NP-Complete and NP-Hard Problems,
Cook’s Theorem, Polynomial-time reductions, Satisfiability, Reduction from Satisfiability to
Vertex Cover.
9/4/2024
CS3102 (DAA), Dept. of CSE
4
More Information
• Textbook
•Introduction to Algorithms 3rd, Cormen,
Leiserson, Rivest and Stein, The MIT Press,
• Fundamentals of Computer Algorithms, 2nd,
Sartaj Sahni, Ellis Horowitz, Sanguthevar
Rajasekaran
• Others
• Introduction to Design & Analysis Computer Algorithm 3rd,
Sara Baase, Allen Van Gelder, Adison-Wesley, 2000.
• Algorithms, Richard Johnsonbaugh, Marcus Schaefer, Prentice
Hall, 2004.
• Introduction to The Design and Analysis of Algorithms 2nd
Edition, Anany Levitin, Adison-Wesley, 2007.
9/4/2024
CS3102 (DAA), Dept. of CSE
5
Course Outcomes:
9/4/2024
CS3102 (DAA), Dept. of CSE
6
[CS3102.1] Analyze the running times of algorithms using asymptotic analysis. (Bloom’s Level: 4
Analyze).
[CS3102.2] Contrast and design algorithms using the divide-and-conquer and graph-searching
algorithms to solve business problems, hence enhancing analytical skills. (Bloom’s Level: 4 Analyze)
[CS3102.3] Apply the concept of greedy and dynamic programming approaches to solving real-life
problems to enhance entrepreneurship capabilities. (Bloom’s Level: 3 Apply)
[CS3102.4] Utilize the principles of backtracking and branch and bound algorithms to showcase their
functioning and problem-solving capabilities. (Bloom’s Level: 3 Apply)
[CS3102.5] Evaluate various advanced algorithm concepts such as string matching, approximation
algorithms, and complexity classes to enhance employability. (Bloom’s Level: 5 Evaluate)
Goal of the Course
9/4/2024
CS3102 (DAA), Dept. of CSE
7
Learning
Learning to solve real
problems that arise
frequently in computer
applications.
Learning
Learning the basic
principles and techniques
used for answering the
question: “How good, or,
how bad is the algorithm”
Getting
Getting to know a group
of “very difficult
problems” categorized as
“NP-Complete”
Introduction: Algorithm Definition
and Criteria of Algorithms,
Iterative and Recursive
Algorithms
9/4/2024 CS3102 (DAA), Dept. of CSE 8
What is an Algorithm?
A finite set of instructions that specifies a sequence of
operations to be carried out to solve a specific problem
or class of problems is called an Algorithm.
9/4/2024
CS3102 (DAA), Dept. of CSE
9
Characteristics of Algorithms
9/4/2024
CS3102 (DAA), Dept. of CSE
10
• It should externally supply zero or more quantities.
Input:
• It results in at least one quantity.
Output:
• Each instruction should be clear.
Definiteness:
• An algorithm should terminate after executing a finite
number of steps.
Finiteness:
• the algorithm must produce the correct output within
a reasonable amount of time and using an acceptable
number of resources (such as memory).
Effectiveness:
Advantages of an Algorithm
9/4/2024
CS3102 (DAA), Dept. of CSE
11
Effective Communication:
Since it is written in a natural language
like English, it becomes easy to
understand the step-by-step solution to
any problem.
Easy Debugging:
A well-designed algorithm facilitates easy
debugging to detect the logical errors
that occurred inside the program.
Easy and Efficient Coding:
An algorithm is nothing but a blueprint of
a program that helps develop a program.
Independent of Programming
Language:
Since it is language-independent, it can
be easily coded by incorporating any
high-level language.
Two Distinct Choices
9/4/2024
CS3102 (DAA), Dept. of CSE
12
How to write an Algorithm
Algorithm Swap(a, b)
{
temp = a;
a = b;
b = temp;
}
9/4/2024 CS3102 (DAA), Dept. of CSE 13
Probably the Oldest Algorithm
9/4/2024
CS3102 (DAA), Dept. of CSE
14
Euclid Algorithm: RecursiveVersion
9/4/2024
CS3102 (DAA), Dept. of CSE
15
Analysis of Algorithm
9/4/2024
CS3102 (DAA), Dept. of CSE
16
Space Complexity:
The space complexity can be
understood as the amount of space
required by an algorithm to run to
completion.
Time Complexity:
Time complexity is a function of input
size n that refers to the amount of time
needed by an algorithm to run to
completion.
The analysis is a process of estimating the efficiency of an algorithm. There
are two fundamental parameters based on which we can analyze the
algorithm:
How to Analyse an Algorithm
9/4/2024
CS3102 (DAA), Dept. of CSE
17
Algorithm Swap(a, b)
{
temp = a;
a = b;
b = temp;
}
Applications
9/4/2024
CS3102 (DAA), Dept. of CSE
18
Frequency Count Method
Algorithm Sum(A, n)
{
s = 0;
for(i=0; i<n; i++)
{
s = s + A[i];
}
return s;
}
Frequency Count Method (Example)
Algorithm Add(A, B, n)
{
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
C[i,j] = A[i,j] + B[i,j]
}
}
}
Frequency Count Method (Example)
Algorithm Multiply(A, B, n)
{
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
C[i,j] = 0;
for(k=0; k<n; k++)
{
C[i,j] = C[i,j] + A[i,k] * B[i,j];
}
}
}
}
Example
for(i=0; i<n; i++)
{
statement;
}
Example
for(i=n; i>0; i--)
{
statement;
}
Example
for(i=0; i<n; i=i+2)
{
statement;
}
Example
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
statement;
}
}
Example
for(i=0; i<n; i++)
{
for(j=0; j<i; j++)
{
statement;
}
}
Example
p=0;
for(i=1; p<=n; i++)
{
p=p+i;
}
Example
for(i=1; i<n; i=i*2)
{
statement;
}
Example
for(i=n; i>=1; i=i/2)
{
statement;
}
Example
for(i=1; i<n; i++)
{
statement;
}
for(j=1; j<n; j++)
{
statement;
}
Example
for(i=0; i<n; i++)
{
for(j=1; j<n; j=j*2)
statement;
}
Observations
1. for(i=0; i<n; i++) O(n)
2. for(i=0; i<n; i+2) n/2 O (n)
3. for(i=n; i>1; i--) O (n)
4. for(i=1; i<n; i=i*2) O(log n) Base 2
5. for(i=1; i<n; i=i*3) O(log n) Base 3
6. for(i=n; i>1; i=i/2) O(log n) Base 2
1. Introduction to Algorithms, Specification of Algorithm, Complexity.pdf
Compare Class of Functions
1<log n < √n < n < n*log n < n2 < n3 < - - - - - - -< 2n < 3n < ----<nn
log n n n^2 2^n
0 1 1 2
1 2 4 4
2
3
4
8
16
64
16
256
Compare Class of Functions

More Related Content

Similar to 1. Introduction to Algorithms, Specification of Algorithm, Complexity.pdf (20)

Types of Algorithms.ppt
Types of Algorithms.ppt
ALIZAIB KHAN
 
L1_Welcome Lecture.pptx for introduction
L1_Welcome Lecture.pptx for introduction
RaviSharma633042
 
Lecture 1 (bce-7)
Lecture 1 (bce-7)
farazahmad005
 
Cs6402 scad-msm
Cs6402 scad-msm
Jai Ram
 
Introduction to Algorithms Introduction to Algorithms.pptx
Introduction to Algorithms Introduction to Algorithms.pptx
ArjayBalberan1
 
DAA Notes.pdf
DAA Notes.pdf
SauravPawar14
 
complexity analysis.pdf
complexity analysis.pdf
pasinduneshan
 
UNIT-1-PPTS-DAA INTRO WITH DIVIDE AND CONQUER
UNIT-1-PPTS-DAA INTRO WITH DIVIDE AND CONQUER
Salini P
 
UNIT 1- Design Analysis of algorithms and its working
UNIT 1- Design Analysis of algorithms and its working
Bobby Pra A
 
daa18d8d-d333-4398-94dd-a46802d88d79.pptx
daa18d8d-d333-4398-94dd-a46802d88d79.pptx
yvtinsane
 
Algo_lecture1-3.pptx
Algo_lecture1-3.pptx
ssuserb14922
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
SamridhiGulati4
 
Introduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.ppt
BhargaviDalal4
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
racha49
 
Lecture 1.pptx
Lecture 1.pptx
ALIZAIB KHAN
 
chapter 1
chapter 1
yatheesha
 
UNIT-1-PdjfjfjfjfjfjfjfjfjfjfjPTS-DAA.pdf
UNIT-1-PdjfjfjfjfjfjfjfjfjfjfjPTS-DAA.pdf
NagendraK18
 
UNIT-1-PPTS-DAA_cofjfjvjcjcncnfncmpressed.pdf
UNIT-1-PPTS-DAA_cofjfjvjcjcncnfncmpressed.pdf
NagendraK18
 
Algorithms.pdf
Algorithms.pdf
OluwafolakeOjo
 
Ds03 part i algorithms by jyoti lakhani
Ds03 part i algorithms by jyoti lakhani
jyoti_lakhani
 
Types of Algorithms.ppt
Types of Algorithms.ppt
ALIZAIB KHAN
 
L1_Welcome Lecture.pptx for introduction
L1_Welcome Lecture.pptx for introduction
RaviSharma633042
 
Cs6402 scad-msm
Cs6402 scad-msm
Jai Ram
 
Introduction to Algorithms Introduction to Algorithms.pptx
Introduction to Algorithms Introduction to Algorithms.pptx
ArjayBalberan1
 
complexity analysis.pdf
complexity analysis.pdf
pasinduneshan
 
UNIT-1-PPTS-DAA INTRO WITH DIVIDE AND CONQUER
UNIT-1-PPTS-DAA INTRO WITH DIVIDE AND CONQUER
Salini P
 
UNIT 1- Design Analysis of algorithms and its working
UNIT 1- Design Analysis of algorithms and its working
Bobby Pra A
 
daa18d8d-d333-4398-94dd-a46802d88d79.pptx
daa18d8d-d333-4398-94dd-a46802d88d79.pptx
yvtinsane
 
Algo_lecture1-3.pptx
Algo_lecture1-3.pptx
ssuserb14922
 
Introduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.ppt
BhargaviDalal4
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
racha49
 
UNIT-1-PdjfjfjfjfjfjfjfjfjfjfjPTS-DAA.pdf
UNIT-1-PdjfjfjfjfjfjfjfjfjfjfjPTS-DAA.pdf
NagendraK18
 
UNIT-1-PPTS-DAA_cofjfjvjcjcncnfncmpressed.pdf
UNIT-1-PPTS-DAA_cofjfjvjcjcncnfncmpressed.pdf
NagendraK18
 
Ds03 part i algorithms by jyoti lakhani
Ds03 part i algorithms by jyoti lakhani
jyoti_lakhani
 

Recently uploaded (20)

FLOURISHING THROUGH SENSES: FROM Ab‘SENSE’ to Pre‘SENSE’ to Es‘SENSE’ to Re-...
FLOURISHING THROUGH SENSES: FROM Ab‘SENSE’ to Pre‘SENSE’ to Es‘SENSE’ to Re-...
Samuel Thuo
 
最新版西班牙拉蒙鲁尔大学毕业证(URL毕业证书)原版定制
最新版西班牙拉蒙鲁尔大学毕业证(URL毕业证书)原版定制
Taqyea
 
Midwifery_Led_Care_Units_Presentation.pptx
Midwifery_Led_Care_Units_Presentation.pptx
rajanirprasadkrishna
 
User Persona for a fitness CEO Founder
User Persona for a fitness CEO Founder
modele dawodu
 
Chromatic house a case study presentation arch.pptx
Chromatic house a case study presentation arch.pptx
maheshwarigarvit2006
 
Crochet Pig Pattern Step-By-Step Tutorial
Crochet Pig Pattern Step-By-Step Tutorial
ytour882
 
Radiation_Pollution_eLearning_Module.pptx
Radiation_Pollution_eLearning_Module.pptx
kanishkaarora1496
 
DOC-20250504-WA0015.design for shirts be
DOC-20250504-WA0015.design for shirts be
peh1seguv0z2
 
AUTOMATIC NUMBER PLATE RECOGNITION 1.pptx
AUTOMATIC NUMBER PLATE RECOGNITION 1.pptx
ABHISHEKCHAKRABORTY931369
 
proposed bubble diagram caloocan city jail-Model.pdf
proposed bubble diagram caloocan city jail-Model.pdf
GilBambilla
 
Turquesa e Íconos de Salud Médico Tríptico Folleto_20250428_004458_0000.pdf
Turquesa e Íconos de Salud Médico Tríptico Folleto_20250428_004458_0000.pdf
GloriaYolandaDoderoT
 
presentatin format for submissionof.pptx
presentatin format for submissionof.pptx
Natashakarki1
 
Formal Informal Apology letter.pptxvvvvv
Formal Informal Apology letter.pptxvvvvv
iqlimajurayeva
 
Cora Bisignano PPH Presentation (1).pdf
Cora Bisignano PPH Presentation (1).pdf
corabisi
 
(18+ CLIP!) Sophie Rain Spiderman Viral Video Clip Sophie Rain Original Video
(18+ CLIP!) Sophie Rain Spiderman Viral Video Clip Sophie Rain Original Video
jamesfolkner123
 
Villa de'Urgell X -.pdf A single family two-story residence to be built in tw...
Villa de'Urgell X -.pdf A single family two-story residence to be built in tw...
Manny Vesa
 
Internet Download Manager (IDM) Crack Free Download 2025
Internet Download Manager (IDM) Crack Free Download 2025
Designer
 
Styled_Soyabean_Milk_Presentation (1).pptx
Styled_Soyabean_Milk_Presentation (1).pptx
ssuser1abcd4
 
Digital Poster PPT.pptx..............................
Digital Poster PPT.pptx..............................
AhmedAboElSeoud3
 
Narrative research for qualitative research
Narrative research for qualitative research
gameghor1591
 
FLOURISHING THROUGH SENSES: FROM Ab‘SENSE’ to Pre‘SENSE’ to Es‘SENSE’ to Re-...
FLOURISHING THROUGH SENSES: FROM Ab‘SENSE’ to Pre‘SENSE’ to Es‘SENSE’ to Re-...
Samuel Thuo
 
最新版西班牙拉蒙鲁尔大学毕业证(URL毕业证书)原版定制
最新版西班牙拉蒙鲁尔大学毕业证(URL毕业证书)原版定制
Taqyea
 
Midwifery_Led_Care_Units_Presentation.pptx
Midwifery_Led_Care_Units_Presentation.pptx
rajanirprasadkrishna
 
User Persona for a fitness CEO Founder
User Persona for a fitness CEO Founder
modele dawodu
 
Chromatic house a case study presentation arch.pptx
Chromatic house a case study presentation arch.pptx
maheshwarigarvit2006
 
Crochet Pig Pattern Step-By-Step Tutorial
Crochet Pig Pattern Step-By-Step Tutorial
ytour882
 
Radiation_Pollution_eLearning_Module.pptx
Radiation_Pollution_eLearning_Module.pptx
kanishkaarora1496
 
DOC-20250504-WA0015.design for shirts be
DOC-20250504-WA0015.design for shirts be
peh1seguv0z2
 
proposed bubble diagram caloocan city jail-Model.pdf
proposed bubble diagram caloocan city jail-Model.pdf
GilBambilla
 
Turquesa e Íconos de Salud Médico Tríptico Folleto_20250428_004458_0000.pdf
Turquesa e Íconos de Salud Médico Tríptico Folleto_20250428_004458_0000.pdf
GloriaYolandaDoderoT
 
presentatin format for submissionof.pptx
presentatin format for submissionof.pptx
Natashakarki1
 
Formal Informal Apology letter.pptxvvvvv
Formal Informal Apology letter.pptxvvvvv
iqlimajurayeva
 
Cora Bisignano PPH Presentation (1).pdf
Cora Bisignano PPH Presentation (1).pdf
corabisi
 
(18+ CLIP!) Sophie Rain Spiderman Viral Video Clip Sophie Rain Original Video
(18+ CLIP!) Sophie Rain Spiderman Viral Video Clip Sophie Rain Original Video
jamesfolkner123
 
Villa de'Urgell X -.pdf A single family two-story residence to be built in tw...
Villa de'Urgell X -.pdf A single family two-story residence to be built in tw...
Manny Vesa
 
Internet Download Manager (IDM) Crack Free Download 2025
Internet Download Manager (IDM) Crack Free Download 2025
Designer
 
Styled_Soyabean_Milk_Presentation (1).pptx
Styled_Soyabean_Milk_Presentation (1).pptx
ssuser1abcd4
 
Digital Poster PPT.pptx..............................
Digital Poster PPT.pptx..............................
AhmedAboElSeoud3
 
Narrative research for qualitative research
Narrative research for qualitative research
gameghor1591
 
Ad

1. Introduction to Algorithms, Specification of Algorithm, Complexity.pdf

  • 1. Course Name: Design and Analysis of Algorithm Topic: Introduction to Algorithms, Specification of Algorithm Course code : CS3102 Credits : 4 Mode of delivery : Hybrid (PowerPoint presentation) Faculty : Dr. Ajit Noonia Email-id : [email protected] B.TECH V SEM CSE ACADEMIC YEAR: 2024-2025 1
  • 3. Course Information • Course Handout • Communicate through eMail • Office hours • To be communicated • Grading policy • Will be communicated as per university guidelines 9/4/2024 CS3102 (DAA), Dept. of CSE 3
  • 4. Syllabus Introduction: Algorithm Definition and Criteria of Algorithms, Iterative and Recursive Algorithms. Performance Analysis: Priori and Posteriori Analysis, Asymptotic Notations, Space Complexity, Time Complexity, Performance measurement of iterative and recursive algorithms. Solving Recurrence Relations: Substitution Method, Iterative Method, Recursive Tree Method, Master Method. Divide and Conquer: Introduction, Binary Search, Finding Maximum and Minimum, Merge Sort, Quick Sort, Randomized Quick Sort, Integer Multiplication. Graph Search Algorithm: Graph representation, Breadth First Search, and Depth First Search. Greedy Strategy: Introduction, Knapsack Problem, Job Sequencing with Deadlines, Huffman Coding, Union and Find Operation (Set and Disjoint Set), Minimum Cost Spanning Tree Algorithms (Prim’s and Kruskal’s), Optimal Merge Patterns, Single Source Shortest Path (Dijkstra’s Algorithm). Dynamic Programming: Introduction, Single Source Shortest Path (Bellman and Ford Algorithm), All Pair Shortest Path (Floyd Wrashal’s Algorithm), Optimal Binary Search Trees, 0/1 Knapsack Problem, Travelling Salesperson Problem, Longest Common Subsequence, Matrix Chain Multiplication, Edit distance. Backtracking: Introduction, N-Queens Problem, Graph Colouring, and Hamiltonian Cycles. Branch and Bound: Introduction, FIFO and LC Branch and Bound, 0/1 Knapsack Problem, Travelling Salesman Problem. String Matching: Naïve String Matching, Rabin Karp Algorithm, Knuth-Morris-Pratt Algorithm. Complexity Classes: NP, NP-Complete and NP-Hard Problems, Cook’s Theorem, Polynomial-time reductions, Satisfiability, Reduction from Satisfiability to Vertex Cover. 9/4/2024 CS3102 (DAA), Dept. of CSE 4
  • 5. More Information • Textbook •Introduction to Algorithms 3rd, Cormen, Leiserson, Rivest and Stein, The MIT Press, • Fundamentals of Computer Algorithms, 2nd, Sartaj Sahni, Ellis Horowitz, Sanguthevar Rajasekaran • Others • Introduction to Design & Analysis Computer Algorithm 3rd, Sara Baase, Allen Van Gelder, Adison-Wesley, 2000. • Algorithms, Richard Johnsonbaugh, Marcus Schaefer, Prentice Hall, 2004. • Introduction to The Design and Analysis of Algorithms 2nd Edition, Anany Levitin, Adison-Wesley, 2007. 9/4/2024 CS3102 (DAA), Dept. of CSE 5
  • 6. Course Outcomes: 9/4/2024 CS3102 (DAA), Dept. of CSE 6 [CS3102.1] Analyze the running times of algorithms using asymptotic analysis. (Bloom’s Level: 4 Analyze). [CS3102.2] Contrast and design algorithms using the divide-and-conquer and graph-searching algorithms to solve business problems, hence enhancing analytical skills. (Bloom’s Level: 4 Analyze) [CS3102.3] Apply the concept of greedy and dynamic programming approaches to solving real-life problems to enhance entrepreneurship capabilities. (Bloom’s Level: 3 Apply) [CS3102.4] Utilize the principles of backtracking and branch and bound algorithms to showcase their functioning and problem-solving capabilities. (Bloom’s Level: 3 Apply) [CS3102.5] Evaluate various advanced algorithm concepts such as string matching, approximation algorithms, and complexity classes to enhance employability. (Bloom’s Level: 5 Evaluate)
  • 7. Goal of the Course 9/4/2024 CS3102 (DAA), Dept. of CSE 7 Learning Learning to solve real problems that arise frequently in computer applications. Learning Learning the basic principles and techniques used for answering the question: “How good, or, how bad is the algorithm” Getting Getting to know a group of “very difficult problems” categorized as “NP-Complete”
  • 8. Introduction: Algorithm Definition and Criteria of Algorithms, Iterative and Recursive Algorithms 9/4/2024 CS3102 (DAA), Dept. of CSE 8
  • 9. What is an Algorithm? A finite set of instructions that specifies a sequence of operations to be carried out to solve a specific problem or class of problems is called an Algorithm. 9/4/2024 CS3102 (DAA), Dept. of CSE 9
  • 10. Characteristics of Algorithms 9/4/2024 CS3102 (DAA), Dept. of CSE 10 • It should externally supply zero or more quantities. Input: • It results in at least one quantity. Output: • Each instruction should be clear. Definiteness: • An algorithm should terminate after executing a finite number of steps. Finiteness: • the algorithm must produce the correct output within a reasonable amount of time and using an acceptable number of resources (such as memory). Effectiveness:
  • 11. Advantages of an Algorithm 9/4/2024 CS3102 (DAA), Dept. of CSE 11 Effective Communication: Since it is written in a natural language like English, it becomes easy to understand the step-by-step solution to any problem. Easy Debugging: A well-designed algorithm facilitates easy debugging to detect the logical errors that occurred inside the program. Easy and Efficient Coding: An algorithm is nothing but a blueprint of a program that helps develop a program. Independent of Programming Language: Since it is language-independent, it can be easily coded by incorporating any high-level language.
  • 12. Two Distinct Choices 9/4/2024 CS3102 (DAA), Dept. of CSE 12
  • 13. How to write an Algorithm Algorithm Swap(a, b) { temp = a; a = b; b = temp; } 9/4/2024 CS3102 (DAA), Dept. of CSE 13
  • 14. Probably the Oldest Algorithm 9/4/2024 CS3102 (DAA), Dept. of CSE 14
  • 16. Analysis of Algorithm 9/4/2024 CS3102 (DAA), Dept. of CSE 16 Space Complexity: The space complexity can be understood as the amount of space required by an algorithm to run to completion. Time Complexity: Time complexity is a function of input size n that refers to the amount of time needed by an algorithm to run to completion. The analysis is a process of estimating the efficiency of an algorithm. There are two fundamental parameters based on which we can analyze the algorithm:
  • 17. How to Analyse an Algorithm 9/4/2024 CS3102 (DAA), Dept. of CSE 17 Algorithm Swap(a, b) { temp = a; a = b; b = temp; }
  • 19. Frequency Count Method Algorithm Sum(A, n) { s = 0; for(i=0; i<n; i++) { s = s + A[i]; } return s; }
  • 20. Frequency Count Method (Example) Algorithm Add(A, B, n) { for(i=0; i<n; i++) { for(j=0; j<n; j++) { C[i,j] = A[i,j] + B[i,j] } } }
  • 21. Frequency Count Method (Example) Algorithm Multiply(A, B, n) { for(i=0; i<n; i++) { for(j=0; j<n; j++) { C[i,j] = 0; for(k=0; k<n; k++) { C[i,j] = C[i,j] + A[i,k] * B[i,j]; } } } }
  • 25. Example for(i=0; i<n; i++) { for(j=0; j<n; j++) { statement; } }
  • 26. Example for(i=0; i<n; i++) { for(j=0; j<i; j++) { statement; } }
  • 31. Example for(i=0; i<n; i++) { for(j=1; j<n; j=j*2) statement; }
  • 32. Observations 1. for(i=0; i<n; i++) O(n) 2. for(i=0; i<n; i+2) n/2 O (n) 3. for(i=n; i>1; i--) O (n) 4. for(i=1; i<n; i=i*2) O(log n) Base 2 5. for(i=1; i<n; i=i*3) O(log n) Base 3 6. for(i=n; i>1; i=i/2) O(log n) Base 2
  • 34. Compare Class of Functions 1<log n < √n < n < n*log n < n2 < n3 < - - - - - - -< 2n < 3n < ----<nn log n n n^2 2^n 0 1 1 2 1 2 4 4 2 3 4 8 16 64 16 256
  • 35. Compare Class of Functions