SlideShare a Scribd company logo
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

PPTX
Data structures algorithms basics
PPTX
Unit 1, ADA.pptx
PPTX
2. Introduction to Algorithm.pptx
PPTX
daa18d8d-d333-4398-94dd-a46802d88d79.pptx
PDF
UNIT-1-PdjfjfjfjfjfjfjfjfjfjfjPTS-DAA.pdf
PDF
UNIT-1-PPTS-DAA_cofjfjvjcjcncnfncmpressed.pdf
PPT
UNIT-1-PPTS-DAA INTRO WITH DIVIDE AND CONQUER
PPT
UNIT 1- Design Analysis of algorithms and its working
Data structures algorithms basics
Unit 1, ADA.pptx
2. Introduction to Algorithm.pptx
daa18d8d-d333-4398-94dd-a46802d88d79.pptx
UNIT-1-PdjfjfjfjfjfjfjfjfjfjfjPTS-DAA.pdf
UNIT-1-PPTS-DAA_cofjfjvjcjcncnfncmpressed.pdf
UNIT-1-PPTS-DAA INTRO WITH DIVIDE AND CONQUER
UNIT 1- Design Analysis of algorithms and its working

Similar to Algorithms.pdf (20)

PPT
UNIT-1-PPTS-DAA.ppt
PPT
Introduction to Design Algorithm And Analysis.ppt
PPT
UNIT-1-PPTS-DAA.ppt
PPT
UNIT-1-PPTS-DAA_INTRODUCTION_TO_DAA_GH.ppt
PPT
UNIT-2-PPTS-DAA.ppt
PDF
2-Algorithms and Complexit data structurey.pdf
PDF
Logic Development and Algorithm.
PPTX
Unit i basic concepts of algorithms
PPTX
Design Analysis of Alogorithm 1 ppt 2024.pptx
PPTX
Analysis of Algorithm full version 2024.pptx
PDF
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
PPTX
Module 1_ Introduction.pptx
PDF
Performance Analysis,Time complexity, Asymptotic Notations
PPTX
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
PPTX
Design and Analysis of Algorithm ppt for unit one
PDF
DSA
PDF
ppts foe design and analysis of algorithm
PPT
UNIT-1-PPT-DESIGN AND ANALYSIS OF ALGORITHMS
PPTX
design analysis of algorithmaa unit 1.pptx
PPTX
Algorithm.pptx
UNIT-1-PPTS-DAA.ppt
Introduction to Design Algorithm And Analysis.ppt
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA_INTRODUCTION_TO_DAA_GH.ppt
UNIT-2-PPTS-DAA.ppt
2-Algorithms and Complexit data structurey.pdf
Logic Development and Algorithm.
Unit i basic concepts of algorithms
Design Analysis of Alogorithm 1 ppt 2024.pptx
Analysis of Algorithm full version 2024.pptx
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
Module 1_ Introduction.pptx
Performance Analysis,Time complexity, Asymptotic Notations
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
Design and Analysis of Algorithm ppt for unit one
DSA
ppts foe design and analysis of algorithm
UNIT-1-PPT-DESIGN AND ANALYSIS OF ALGORITHMS
design analysis of algorithmaa unit 1.pptx
Algorithm.pptx
Ad

Recently uploaded (20)

PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Lesson notes of climatology university.
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Presentation on HIE in infants and its manifestations
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Cell Types and Its function , kingdom of life
PPTX
Pharma ospi slides which help in ospi learning
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Computing-Curriculum for Schools in Ghana
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Classroom Observation Tools for Teachers
PPTX
master seminar digital applications in india
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Lesson notes of climatology university.
Chinmaya Tiranga quiz Grand Finale.pdf
Presentation on HIE in infants and its manifestations
O7-L3 Supply Chain Operations - ICLT Program
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
VCE English Exam - Section C Student Revision Booklet
Cell Types and Its function , kingdom of life
Pharma ospi slides which help in ospi learning
102 student loan defaulters named and shamed – Is someone you know on the list?
Computing-Curriculum for Schools in Ghana
Anesthesia in Laparoscopic Surgery in India
Microbial diseases, their pathogenesis and prophylaxis
Pharmacology of Heart Failure /Pharmacotherapy of CHF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Classroom Observation Tools for Teachers
master seminar digital applications in india
Ad

Algorithms.pdf

  • 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.