SlideShare a Scribd company logo
1 of 24
Download to read offline
CSC 102 : Introduction to Algorithm Techniques
Department of Computer Science
College of Physical Sciences
Federal University of Agriculture, Abeokuta.
WEEK 2
2019/2020 session
DR. O.E OJO
Steps involved in algorithm development
■ Step1. Identification of input: For an algorithm, there are
quantities to be supplied called input and these are fed
externally. The input is to be identified first for any specified
problem.
■ Step2: Identification of output: From an algorithm, at least
one quantity is produced, called for any specified problem.
■ Step3 : Identification the processing operations : All the
calculations to be performed in order to lead to output from
the input are to be identified in an orderly manner.
Steps involved in algorithm development
■ Step4 : Processing Definiteness : The instructions
composing the algorithm must be clear and there should not
be any ambiguity in them.
■ Step5 : Processing Finiteness : If we go through the
algorithm, then for all cases, the algorithm should terminate
after a finite number of steps.
■ Step6 : Possessing Effectiveness : The instructions in the
algorithm must be sufficiently basic and in practice they can
be carries out easily.
Method for developing an algorithm
■ 1. Define the problem: State the problem that you are trying
to solve in clear and concise terms.
■ 2. List the inputs (information needed to solve the problem)
and the outputs (what the algorithm will produce as a result)
■ 3. Describe the steps needed to convert or manipulate the
inputs or produce the outputs. Start at a high level first and
keep refining the steps until they are effectively computable
operations.
■ 4. Test the algorithm: Choose data sets and verify that your
algorithm works.
Example of an Algorithm
Write an algorithm to find the area of a Circle of radius r.
Inputs to the algorithm: Radius r of the Circle.
Expected output: Area of the Circle
Algorithm:
Step1: Start
Step 2: Input the Radius r and PI of the Circle
Step3: PI 3.142
Step4: Area PI * r * r
Step5: Output Area
Step6: Stop
Example of an Algorithm
Write an algorithm to find the Sum of two numbers
Initialization
Inputs to the algorithm: First number = A. Second number = B
Expected output: Sum of A and B
Algorithm:
Step 1: Start
Step 2: Sum = 0
Step 3: Input the value of A
Step 4: Input the value of B
Step 5: Sum = A + B
Step 6: Output Sum
Step 7: End
Example
■ Design an algorithm to add these test scores: 26, 49, 98,
87, 62, 75 and obtain the Average score
1.Start
2. Sum 0
3. Input 26, 49, 98, 87, 62, 75
4. Sum 26+49+98+87+62+75
5. Average Sum/6
6. Output Average
7. Stop
Properties of Algorithm
■ Correctness
Correctness is the property reflecting the extent to which the
algorithm is able to reach a solution without errors.
■ Efficiency
The efficiency of an algorithm is the property that regards the
rapidity by which a solution is reached.
■ Generality
This means that it must solve every instance of the problem.
For example, a program that computes the area of a rectangle
should work on all possible dimensions of the rectangle.
■ Effectiveness
This means that an algorithm must provide the correct
answer to the problem.
■ Comprehensible
Finally the algorithm must be comprehensible by the
one who performs it.
It must describe in all details, the actions and the
entities necessary for the resolution of a problem.
Categories of Algorithm
■ From data structure point of view, following are
some important categories of algorithms −
■ Search − Algorithm to search an item in a data structure.
■ Sort − Algorithm to sort items in certain order
■ Insert − Algorithm to insert item in a data structure
■ Update − Algorithm to update an existing item in a data structure
■ Delete − Algorithm to delete an existing item from a data structure
One problem(multiple solutions)
■ We design an algorithm to get solution of a given problem. A
problem can be solved in more than one ways.
Algorithm Analysis
■ In computer science, the analysis of algorithms is the
determination of the amount of computing resources (such as time
and space) necessary to execute them.
■ We want to be able to consider two algorithms and say that one
is better than the other because it is more efficient in its use of
those resources or perhaps because it simply uses fewer.
Algorithm Analysis
■ Algorithm analysis deals with the execution or
running time of various operations involved.
■ Running time of an operation can be defined as no.
of computer instructions executed per operation.
Algorithm Analysis
■ Efficiency of an algorithm can be analyzed at two
different stages,
■ before implementation(priori analysis)
■ and after implementation(posterior analysis).
Algorithm Analysis
■ It is important to consider the amount of space or
memory an algorithm requires to solve the problem.
■ The amount of space required by a problem solution is
typically dictated by the problem instance itself.
Priori Analysis
■ This is theoretical analysis of an algorithm.
■ Efficiency of algorithm is measured by assuming
that all other factors (e.g. Processor speed), are
constant and have no effect on
implementation.
Posterior Analysis
■ This is empirical analysis of an algorithm.
■ The selected algorithm is implemented using programming
language.
■ This is then executed on target computer machine.
■ In this analysis, actual statistics like running time and space
required, are collected.
■ Our focus in this course is priori algorithm analysis
ALGORITHM COMPLEXITY
■ Suppose X is an algorithm and
■ n is the size of input data,
■ the time and space used by the Algorithm X are the
two main factors which decide the efficiency of X.
■ Time Factor − The time is measured by counting
the number of key operations such as
comparisons in sorting algorithm
ALGORITHM COMPLEXITY
■ Space Factor − The space is measured by
counting the
maximum memory space required by the
algorithm.
■ The complexity of an algorithm f(n) gives the
running time
and / or storage space required by the algorithm in
terms of
n as the size of input data.
SPACE COMPLEXITY
■ Space complexity of an algorithm represents
the amount of memory space required by the
algorithm in its life cycle.
■ Space required by an algorithm = Fixed Part +
Variable Part.
SPACE COMPLEXITY
■ A fixed part is a space required to store certain
data and variables, that are independent of the size
of the problem. Eg: Simple variables & constant
used, program size etc.
■ A variable part is a space required by variables,
whose size depends on the size of the problem.
Eg. Dynamic memory allocation, recursion stack
space etc.
SPACE COMPLEXITY
■ Space complexity S(P) of any algorithm P is,
S(P) = C + SP(I)
■ Where C is the fixed part and
■ S(I) is the variable part of the algorithm which
depends on instance characteristic I.
SPACE COMPLEXITY
■ Example
Algorithm: SUM (A, B)
Step 1 – START
Step 2 - C ← A + B + 10
Step 3 – Stop.
■ Here we have three variables A, B and C and
one constant.
■ Hence S(P) = 1+3.
■ Therefore, space depends on data types of
given variables and constant types.
CLASS WORK 2
■ Question: Find the space complexity in the
algorithm given below:
Algorithm: Addition of numbers
Step 1 – START
Step 2 – a = 40
Step 3- M← a + b +c+ d
Step 4 – Stop.

More Related Content

Similar to The space complexity of the given algorithm is:S(P) = C + SP(I) = 1 + 4 = 5Where C is 1 (for constant 40) and SP(I) is 4 (for variables a, b, c, d).Therefore, the space complexity is 5

Logic Development and Algorithm.
Logic Development and Algorithm.Logic Development and Algorithm.
Logic Development and Algorithm.NandiniSidana
 
Unit i basic concepts of algorithms
Unit i basic concepts of algorithmsUnit i basic concepts of algorithms
Unit i basic concepts of algorithmssangeetha s
 
Analysis of Algorithm full version 2024.pptx
Analysis of Algorithm  full version  2024.pptxAnalysis of Algorithm  full version  2024.pptx
Analysis of Algorithm full version 2024.pptxrajesshs31r
 
Design Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxDesign Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxrajesshs31r
 
Module 1_ Introduction.pptx
Module 1_ Introduction.pptxModule 1_ Introduction.pptx
Module 1_ Introduction.pptxnikshaikh786
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...AntareepMajumder
 
Design and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit oneDesign and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit onessuserb7c8b8
 
01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptxssuser586772
 
Basics of Algorithm Unit 1 part 1 algorithm
Basics of Algorithm Unit 1 part 1  algorithmBasics of Algorithm Unit 1 part 1  algorithm
Basics of Algorithm Unit 1 part 1 algorithmJIMS LAJPAT NAGAR
 
Algorithm analysis and design
Algorithm analysis and designAlgorithm analysis and design
Algorithm analysis and designMegha V
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdfNayanChandak1
 
Introduction to Data Structures Sorting and searching
Introduction to Data Structures Sorting and searchingIntroduction to Data Structures Sorting and searching
Introduction to Data Structures Sorting and searchingMvenkatarao
 

Similar to The space complexity of the given algorithm is:S(P) = C + SP(I) = 1 + 4 = 5Where C is 1 (for constant 40) and SP(I) is 4 (for variables a, b, c, d).Therefore, the space complexity is 5 (20)

Logic Development and Algorithm.
Logic Development and Algorithm.Logic Development and Algorithm.
Logic Development and Algorithm.
 
Unit i basic concepts of algorithms
Unit i basic concepts of algorithmsUnit i basic concepts of algorithms
Unit i basic concepts of algorithms
 
Analysis of Algorithm full version 2024.pptx
Analysis of Algorithm  full version  2024.pptxAnalysis of Algorithm  full version  2024.pptx
Analysis of Algorithm full version 2024.pptx
 
Design Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxDesign Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptx
 
Module 1_ Introduction.pptx
Module 1_ Introduction.pptxModule 1_ Introduction.pptx
Module 1_ Introduction.pptx
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
 
Design and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit oneDesign and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit one
 
DSA
DSADSA
DSA
 
Algorithm.pptx
Algorithm.pptxAlgorithm.pptx
Algorithm.pptx
 
Algorithm.pptx
Algorithm.pptxAlgorithm.pptx
Algorithm.pptx
 
Unit ii algorithm
Unit   ii algorithmUnit   ii algorithm
Unit ii algorithm
 
01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx
 
Python algorithm
Python algorithmPython algorithm
Python algorithm
 
U nit i data structure-converted
U nit   i data structure-convertedU nit   i data structure-converted
U nit i data structure-converted
 
Introduction to algorithms
Introduction to algorithmsIntroduction to algorithms
Introduction to algorithms
 
Unit 2 algorithm
Unit   2 algorithmUnit   2 algorithm
Unit 2 algorithm
 
Basics of Algorithm Unit 1 part 1 algorithm
Basics of Algorithm Unit 1 part 1  algorithmBasics of Algorithm Unit 1 part 1  algorithm
Basics of Algorithm Unit 1 part 1 algorithm
 
Algorithm analysis and design
Algorithm analysis and designAlgorithm analysis and design
Algorithm analysis and design
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdf
 
Introduction to Data Structures Sorting and searching
Introduction to Data Structures Sorting and searchingIntroduction to Data Structures Sorting and searching
Introduction to Data Structures Sorting and searching
 

Recently uploaded

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 

Recently uploaded (20)

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 

The space complexity of the given algorithm is:S(P) = C + SP(I) = 1 + 4 = 5Where C is 1 (for constant 40) and SP(I) is 4 (for variables a, b, c, d).Therefore, the space complexity is 5

  • 1. CSC 102 : Introduction to Algorithm Techniques Department of Computer Science College of Physical Sciences Federal University of Agriculture, Abeokuta. WEEK 2 2019/2020 session DR. O.E OJO
  • 2. Steps involved in algorithm development ■ Step1. Identification of input: For an algorithm, there are quantities to be supplied called input and these are fed externally. The input is to be identified first for any specified problem. ■ Step2: Identification of output: From an algorithm, at least one quantity is produced, called for any specified problem. ■ Step3 : Identification the processing operations : All the calculations to be performed in order to lead to output from the input are to be identified in an orderly manner.
  • 3. Steps involved in algorithm development ■ Step4 : Processing Definiteness : The instructions composing the algorithm must be clear and there should not be any ambiguity in them. ■ Step5 : Processing Finiteness : If we go through the algorithm, then for all cases, the algorithm should terminate after a finite number of steps. ■ Step6 : Possessing Effectiveness : The instructions in the algorithm must be sufficiently basic and in practice they can be carries out easily.
  • 4. Method for developing an algorithm ■ 1. Define the problem: State the problem that you are trying to solve in clear and concise terms. ■ 2. List the inputs (information needed to solve the problem) and the outputs (what the algorithm will produce as a result) ■ 3. Describe the steps needed to convert or manipulate the inputs or produce the outputs. Start at a high level first and keep refining the steps until they are effectively computable operations. ■ 4. Test the algorithm: Choose data sets and verify that your algorithm works.
  • 5. Example of an Algorithm Write an algorithm to find the area of a Circle of radius r. Inputs to the algorithm: Radius r of the Circle. Expected output: Area of the Circle Algorithm: Step1: Start Step 2: Input the Radius r and PI of the Circle Step3: PI 3.142 Step4: Area PI * r * r Step5: Output Area Step6: Stop
  • 6. Example of an Algorithm Write an algorithm to find the Sum of two numbers Initialization Inputs to the algorithm: First number = A. Second number = B Expected output: Sum of A and B Algorithm: Step 1: Start Step 2: Sum = 0 Step 3: Input the value of A Step 4: Input the value of B Step 5: Sum = A + B Step 6: Output Sum Step 7: End
  • 7. Example ■ Design an algorithm to add these test scores: 26, 49, 98, 87, 62, 75 and obtain the Average score 1.Start 2. Sum 0 3. Input 26, 49, 98, 87, 62, 75 4. Sum 26+49+98+87+62+75 5. Average Sum/6 6. Output Average 7. Stop
  • 8. Properties of Algorithm ■ Correctness Correctness is the property reflecting the extent to which the algorithm is able to reach a solution without errors. ■ Efficiency The efficiency of an algorithm is the property that regards the rapidity by which a solution is reached. ■ Generality This means that it must solve every instance of the problem. For example, a program that computes the area of a rectangle should work on all possible dimensions of the rectangle.
  • 9. ■ Effectiveness This means that an algorithm must provide the correct answer to the problem. ■ Comprehensible Finally the algorithm must be comprehensible by the one who performs it. It must describe in all details, the actions and the entities necessary for the resolution of a problem.
  • 10. Categories of Algorithm ■ From data structure point of view, following are some important categories of algorithms − ■ Search − Algorithm to search an item in a data structure. ■ Sort − Algorithm to sort items in certain order ■ Insert − Algorithm to insert item in a data structure ■ Update − Algorithm to update an existing item in a data structure ■ Delete − Algorithm to delete an existing item from a data structure
  • 11. One problem(multiple solutions) ■ We design an algorithm to get solution of a given problem. A problem can be solved in more than one ways.
  • 12. Algorithm Analysis ■ In computer science, the analysis of algorithms is the determination of the amount of computing resources (such as time and space) necessary to execute them. ■ We want to be able to consider two algorithms and say that one is better than the other because it is more efficient in its use of those resources or perhaps because it simply uses fewer.
  • 13. Algorithm Analysis ■ Algorithm analysis deals with the execution or running time of various operations involved. ■ Running time of an operation can be defined as no. of computer instructions executed per operation.
  • 14. Algorithm Analysis ■ Efficiency of an algorithm can be analyzed at two different stages, ■ before implementation(priori analysis) ■ and after implementation(posterior analysis).
  • 15. Algorithm Analysis ■ It is important to consider the amount of space or memory an algorithm requires to solve the problem. ■ The amount of space required by a problem solution is typically dictated by the problem instance itself.
  • 16. Priori Analysis ■ This is theoretical analysis of an algorithm. ■ Efficiency of algorithm is measured by assuming that all other factors (e.g. Processor speed), are constant and have no effect on implementation.
  • 17. Posterior Analysis ■ This is empirical analysis of an algorithm. ■ The selected algorithm is implemented using programming language. ■ This is then executed on target computer machine. ■ In this analysis, actual statistics like running time and space required, are collected. ■ Our focus in this course is priori algorithm analysis
  • 18. ALGORITHM COMPLEXITY ■ Suppose X is an algorithm and ■ n is the size of input data, ■ the time and space used by the Algorithm X are the two main factors which decide the efficiency of X. ■ Time Factor − The time is measured by counting the number of key operations such as comparisons in sorting algorithm
  • 19. ALGORITHM COMPLEXITY ■ Space Factor − The space is measured by counting the maximum memory space required by the algorithm. ■ The complexity of an algorithm f(n) gives the running time and / or storage space required by the algorithm in terms of n as the size of input data.
  • 20. SPACE COMPLEXITY ■ Space complexity of an algorithm represents the amount of memory space required by the algorithm in its life cycle. ■ Space required by an algorithm = Fixed Part + Variable Part.
  • 21. SPACE COMPLEXITY ■ A fixed part is a space required to store certain data and variables, that are independent of the size of the problem. Eg: Simple variables & constant used, program size etc. ■ A variable part is a space required by variables, whose size depends on the size of the problem. Eg. Dynamic memory allocation, recursion stack space etc.
  • 22. SPACE COMPLEXITY ■ Space complexity S(P) of any algorithm P is, S(P) = C + SP(I) ■ Where C is the fixed part and ■ S(I) is the variable part of the algorithm which depends on instance characteristic I.
  • 23. SPACE COMPLEXITY ■ Example Algorithm: SUM (A, B) Step 1 – START Step 2 - C ← A + B + 10 Step 3 – Stop. ■ Here we have three variables A, B and C and one constant. ■ Hence S(P) = 1+3. ■ Therefore, space depends on data types of given variables and constant types.
  • 24. CLASS WORK 2 ■ Question: Find the space complexity in the algorithm given below: Algorithm: Addition of numbers Step 1 – START Step 2 – a = 40 Step 3- M← a + b +c+ d Step 4 – Stop.