SlideShare a Scribd company logo
P.Prathibha
Lecturer
Topics
Introduction to Algorithms
Characteristics of an Algorithm
Analysis of Algorithms
Asymptotic Analysis
What is Algorithm ?
 An algorithm is a finite set of instructions or logic, written in order, to accomplish a
certain predefined task.
 Algorithm is not the complete code or program, it is just the core logic(solution) of a
problem, which can be expressed either as an informal high level description
as pseudocode or using a flowchart.
 Algorithm is a step-by-step procedure, which defines a set of instructions to be executed
in a certain order to get the desired output.
 Algorithms are generally created independent of underlying languages, i.e. an algorithm
can be implemented in more than one programming language.
Introduction to Algorithms
Introduction to algorithms
An algorithm should have the following characteristics −
 Unambiguous − Algorithm should be clear and unambiguous. Each of its steps
(or phases), and their inputs/outputs should be clear and must lead to only one
meaning.
 Input − An algorithm should have 0 or more well-defined inputs.
 Output − An algorithm should have 1 or more well-defined outputs, and should match
the desired output.
 Finiteness − Algorithms must terminate after a finite number of steps.
 Feasibility − Should be feasible with the available resources.
 Independent − An algorithm should have step-by-step directions, which should be
independent of any programming code.
Characteristics of an Algorithm
Introduction to algorithms
Characteristics of a good and correct Alg
orithm
 Has a set of inputs
 Steps are uniquely defined
 Has finite number of steps
 Produces desired output
Example of a real-life situation for creating algorithm
Algorithm is for going to the market to purchase a pen.
Algorithm to add 3 numbers and print their sum:
1. START
2. Declare 3 integer variables num1, num2 and num3.
3. Take the three numbers, to be added, as inputs in
variables num1, num2, and num3 respectively.
4. Declare an integer variable sum to store the resultant
sum of the 3 numbers.
5. Add the 3 numbers and store the result in the variable
sum.
6. Print the value of variable sum
7. END
• Efficiency of an algorithm can be analyzed at two different stages,
before implementation and after implementation. They are −
1. A Priori Analysis :
 “Priori” means “before”.
 Hence Priori analysis means checking the algorithm before its
implementation.
 In this, the algorithm is checked when it is written in the form of
theoretical steps. i.e., This is a theoretical analysis of an algorithm.
 Efficiency of an algorithm is measured by assuming that all other
factors,
 for example, processor speed, are constant and have no effect on the
implementation.
Algorithm Analysis
2. A Posterior Analysis :
 “Posterior” means “after”. Hence Posterior analysis means c
hecking the algorithm after its implementation.
 In this, the algorithm is checked by implementing it in any
programming language and executing it.i.e., This is an
empirical analysis of an algorithm.
 This analysis helps to get the actual and real analysis report
about correctness, space required, time consumed etc.
(contd..)
 A measure of the average execution time necessary for an
algorithm to complete work on a set of data.
 Algorithm efficiency is characterized by its order.
 The complexity of an algorithm is a function describing the e
fficiency of the algorithm in terms of the amount of data the al
gorithm must process.
 Usually there are natural units for the domain and range of this
function.
 There are two main measures of the efficiency of an algorithm.
1. Time Complexity
2. Space Complexity
Time Complexity
 Time complexity of an algorithm represents the amount
of time required by the algorithm to run to completion.
 The time complexity of an algorithm is also calculated
by determining following 2 components:
 Constant time part: Any instruction that is executed just o
nce comes in this part. For example, input, output, if-else,
switch, etc.
 Variable Time Part: Any instruction that is executed more t
han once, say n times, comes in this part. F
or example, loops, recursion, etc.
 Time requirements can be defined as a numerical functio
n T(n), where T(n) can be measured as the number of ste
ps, provided each step consumes constant time.
For example, addition of two n-bit integers takes n steps.
Consequently, the total computational time is T(n) = c ∗ n, wh
ere c is the time taken for the addition of two bits. Here, we o
bserve that T(n) grows linearly as the input size increases.
Space Complexity
 Space complexity of an algorithm refers to the amount of memory that this algorithm requires to
execute and get the result.
 This can be for inputs, temporary operations, or outputs.
 The space complexity of an algorithm is calculated by determining following 2 components:
 Fixed Part: This refers to the space that is definitely required by the algorithm.
For example, input variables, output variables, program size, etc.
 Variable Part: This refers to the space that can be different based on the implementation
of the algorithm. For example, temporary variables, dynamic memory allocation, recursion
stack space, etc.
The two popular tools used in the representation of algorithms a
re the following:
1. Pseudocode
2. Flowchart
Algorithm Design Tools
 An algorithm can be written in any of the natural languages such as English, German,
French, etc.
 One of the commonly used tools to define algorithms is the pseudocode.
 Pseudocode is one of the tools that can be used to write a preliminary plan that can be
developed into a computer program.
 A pseudocode is an English-like presentation of the code required for an algorithm.
 Pseudocode is a generic way of describing an algorithm without use of any specific p
rogramming language syntax.
 It is, as the name suggests, pseudo code —it cannot be executed on a real computer, but it
models and resembles real programming code, and is written at roughly the same level
of detail.
Pseudocode
Flowchart
 A very effective tool to show the logic flow of a program is the flowchart.
 A flowchart is a pictorial representation of an algorithm.
 It hides all the details of an algorithm by giving a picture; it shows how the algorithm f
lows from beginning to end.
 A flowchart is a schematic representation of an algorithm or a stepwise process, showing
the steps as boxes of various kinds, and their order by connecting these with arrows.
 Flowcharts are used in designing or documenting a process or program.
 Flowcharts are usually drawn using some standard symbols; however, some special
symbols can also be developed when required.
Flowchart Symbols
Flowchart Symbols
Symbol Symbol Name Purpose
Start / Stop Used at the beginning and end of the algorithm to
show start and end of the program.
Process Indicates processes like mathematical operations.
Input/ Output Used for denoting program inputs and outputs.
Decision Stands for decision statements in a program,
where answer is usually Yes or No.
Arrow Shows relationships between different shapes.
On-page Connector Connects two or more parts of a flowchart, which
are on the same page.
Off-page Connector Connects two parts of a flowchart which are s
pread over different pages.
Flowchart to calculate the average of two numbers
 Asymptotic analysis of an algorithm refers to defining the mathematical boundation/ framing
of its run-time performance.
 Using asymptotic analysis, we can very well conclude the best case, average case, and worst case
scenario of an algorithm.
 Asymptotic analysis is input bound i.e., if there's no input to the algorithm, it is concluded to w
ork in a constant time.
 Other than the "input" all other factors are considered constant.
 Asymptotic analysis refers to computing the running time of any operation in mathematical
units of computation.
 The time required by an algorithm falls under three types −
 Best Case − Minimum time required for program execution.
 Average Case − Average time required for program execution.
 Worst Case − Maximum time required for program execution.
Asymptotic Analysis
Commonly used asymptotic notations to calculate the running time complexity
of an algorithm.
1. Ο Notation
2. Ω Notation
3. θ Notation
Asymptotic Notations
• The notation Ο(n) is the formal way to express the
upper bound of an algorithm's running time.
• It measures the worst case time complexity or the
longest amount of time an algorithm can possibly
take to complete.
For example, for a function f(n)
Ο(f(n)) = { g(n) : there exists c > 0 and n0
such that f(n) ≤ c.g(n) for all n > n0. }
Big Oh Notation, Ο
Omega Notation, Ω
 The notation Ω(n) is the formal way to express the l
ower bound of an algorithm's running time.
 It measures the best case time complexity or the
best amount of time an algorithm can possibly take
to complete.
For example, for a function f(n)
Ω(f(n)) ≥ { g(n) : there exists c > 0 and n0 such that
g(n) ≤ c.f(n) for all n > n0. }
Theta Notation, θ
• The notation θ(n) is the formal way to express b
oth the lower bound and the upper bound of
an algorithm's running time.
θ(f(n)) = { g(n) if and only if g(n) = Ο(f(n)) and g(n) = Ω(f(n
))
for all n > n0. }
 Introduction to Algorithms
 Characteristics of an Algorithm
 Algorithms Analysis
 Algorithms Efficiency
 Algorithms Design Tools
 Asymptotic Analysis
Summary
Introduction to algorithms

More Related Content

PPTX
Algorithm
PDF
Introduction To Computer
PPTX
Professional Ethics
PDF
PYTHON PROGRAMS
PDF
Algorithms Lecture 1: Introduction to Algorithms
PPTX
Professional ethics
PPTX
Software project management
PPTX
Asymptotic Notation
Algorithm
Introduction To Computer
Professional Ethics
PYTHON PROGRAMS
Algorithms Lecture 1: Introduction to Algorithms
Professional ethics
Software project management
Asymptotic Notation

What's hot (20)

PPTX
Parsing LL(1), SLR, LR(1)
PPTX
Interrupts and types of interrupts
PDF
Syntax analysis
PPTX
Compiler vs interpreter
PPTX
Compiler design syntax analysis
PPTX
A simple approach of lexical analyzers
PPTX
Lexical analyzer generator lex
PPTX
Analysis and Design of Algorithms
PPTX
Unit 3. Input and Output
PPTX
Time space trade off
PPTX
Single pass assembler
PPTX
Nested loops
PPT
Classical problem of synchronization
PPTX
Arrays in Data Structure and Algorithm
PPTX
Analysis of algorithm
PPTX
Data Types - Premetive and Non Premetive
PPT
Turing Machine
PPTX
Principal Sources of Optimization in compiler design
PPTX
Turing machine-TOC
PPTX
Performance analysis(Time & Space Complexity)
Parsing LL(1), SLR, LR(1)
Interrupts and types of interrupts
Syntax analysis
Compiler vs interpreter
Compiler design syntax analysis
A simple approach of lexical analyzers
Lexical analyzer generator lex
Analysis and Design of Algorithms
Unit 3. Input and Output
Time space trade off
Single pass assembler
Nested loops
Classical problem of synchronization
Arrays in Data Structure and Algorithm
Analysis of algorithm
Data Types - Premetive and Non Premetive
Turing Machine
Principal Sources of Optimization in compiler design
Turing machine-TOC
Performance analysis(Time & Space Complexity)
Ad

Similar to Introduction to algorithms (20)

PPTX
Data structures algorithms basics
PPTX
2. Introduction to Algorithm.pptx
PPTX
design analysis of algorithmaa unit 1.pptx
PPTX
Algorithm.pptx
PPTX
Algorithm.pptx
PPTX
algorithmanalysisinfundamentalsofdatastructure-190810085243.pptx
PPTX
Algorithm analysis in fundamentals of data structure
PDF
Algorithm Analysis.pdf
PPTX
01 Introduction to analysis of Algorithms.pptx
PPTX
Unit i basic concepts of algorithms
PPTX
2-Algorithms and Complexity analysis.pptx
PPTX
Unit ii algorithm
PDF
Performance Analysis,Time complexity, Asymptotic Notations
PDF
2-Algorithms and Complexit data structurey.pdf
PDF
12200223054_SrijanGho;sh_DAA_19.pdfkmkmm
PDF
Introduction to Algorithms Complexity Analysis
PDF
Daa chapter 1
PDF
Python algorithm
PDF
Daa notes 1
PDF
Algorithm Analysis.pdf
Data structures algorithms basics
2. Introduction to Algorithm.pptx
design analysis of algorithmaa unit 1.pptx
Algorithm.pptx
Algorithm.pptx
algorithmanalysisinfundamentalsofdatastructure-190810085243.pptx
Algorithm analysis in fundamentals of data structure
Algorithm Analysis.pdf
01 Introduction to analysis of Algorithms.pptx
Unit i basic concepts of algorithms
2-Algorithms and Complexity analysis.pptx
Unit ii algorithm
Performance Analysis,Time complexity, Asymptotic Notations
2-Algorithms and Complexit data structurey.pdf
12200223054_SrijanGho;sh_DAA_19.pdfkmkmm
Introduction to Algorithms Complexity Analysis
Daa chapter 1
Python algorithm
Daa notes 1
Algorithm Analysis.pdf
Ad

More from Madishetty Prathibha (14)

PPTX
Object Oriented programming - Introduction
PPTX
Access modifiers in java
PPTX
Constructor in java
PPTX
Control statements in java
PPTX
Classes objects in java
PPTX
Structure of java program diff c- cpp and java
PPTX
Operators in java
PPTX
Types of datastructures
PDF
Java data types, variables and jvm
PPTX
Introduction to data structures (ss)
PPTX
PDF
Oops concepts || Object Oriented Programming Concepts in Java
PPT
Java features
PPSX
Introduction of java
Object Oriented programming - Introduction
Access modifiers in java
Constructor in java
Control statements in java
Classes objects in java
Structure of java program diff c- cpp and java
Operators in java
Types of datastructures
Java data types, variables and jvm
Introduction to data structures (ss)
Oops concepts || Object Oriented Programming Concepts in Java
Java features
Introduction of java

Recently uploaded (20)

PPTX
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Pharma ospi slides which help in ospi learning
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
PDF
Pre independence Education in Inndia.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
PDF
Open folder Downloads.pdf yes yes ges yes
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
Module 3: Health Systems Tutorial Slides S2 2025
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
English Language Teaching from Post-.pdf
PDF
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Business Ethics Teaching Materials for college
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Pharma ospi slides which help in ospi learning
NOI Hackathon - Summer Edition - GreenThumber.pptx
Pre independence Education in Inndia.pdf
human mycosis Human fungal infections are called human mycosis..pptx
O7-L3 Supply Chain Operations - ICLT Program
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
Open folder Downloads.pdf yes yes ges yes
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Module 3: Health Systems Tutorial Slides S2 2025
102 student loan defaulters named and shamed – Is someone you know on the list?
English Language Teaching from Post-.pdf
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
O5-L3 Freight Transport Ops (International) V1.pdf
Business Ethics Teaching Materials for college
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table

Introduction to algorithms

  • 2. Topics Introduction to Algorithms Characteristics of an Algorithm Analysis of Algorithms Asymptotic Analysis
  • 3. What is Algorithm ?  An algorithm is a finite set of instructions or logic, written in order, to accomplish a certain predefined task.  Algorithm is not the complete code or program, it is just the core logic(solution) of a problem, which can be expressed either as an informal high level description as pseudocode or using a flowchart.  Algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a certain order to get the desired output.  Algorithms are generally created independent of underlying languages, i.e. an algorithm can be implemented in more than one programming language. Introduction to Algorithms
  • 5. An algorithm should have the following characteristics −  Unambiguous − Algorithm should be clear and unambiguous. Each of its steps (or phases), and their inputs/outputs should be clear and must lead to only one meaning.  Input − An algorithm should have 0 or more well-defined inputs.  Output − An algorithm should have 1 or more well-defined outputs, and should match the desired output.  Finiteness − Algorithms must terminate after a finite number of steps.  Feasibility − Should be feasible with the available resources.  Independent − An algorithm should have step-by-step directions, which should be independent of any programming code. Characteristics of an Algorithm
  • 7. Characteristics of a good and correct Alg orithm  Has a set of inputs  Steps are uniquely defined  Has finite number of steps  Produces desired output
  • 8. Example of a real-life situation for creating algorithm Algorithm is for going to the market to purchase a pen.
  • 9. Algorithm to add 3 numbers and print their sum: 1. START 2. Declare 3 integer variables num1, num2 and num3. 3. Take the three numbers, to be added, as inputs in variables num1, num2, and num3 respectively. 4. Declare an integer variable sum to store the resultant sum of the 3 numbers. 5. Add the 3 numbers and store the result in the variable sum. 6. Print the value of variable sum 7. END
  • 10. • Efficiency of an algorithm can be analyzed at two different stages, before implementation and after implementation. They are − 1. A Priori Analysis :  “Priori” means “before”.  Hence Priori analysis means checking the algorithm before its implementation.  In this, the algorithm is checked when it is written in the form of theoretical steps. i.e., This is a theoretical analysis of an algorithm.  Efficiency of an algorithm is measured by assuming that all other factors,  for example, processor speed, are constant and have no effect on the implementation. Algorithm Analysis
  • 11. 2. A Posterior Analysis :  “Posterior” means “after”. Hence Posterior analysis means c hecking the algorithm after its implementation.  In this, the algorithm is checked by implementing it in any programming language and executing it.i.e., This is an empirical analysis of an algorithm.  This analysis helps to get the actual and real analysis report about correctness, space required, time consumed etc. (contd..)
  • 12.  A measure of the average execution time necessary for an algorithm to complete work on a set of data.  Algorithm efficiency is characterized by its order.  The complexity of an algorithm is a function describing the e fficiency of the algorithm in terms of the amount of data the al gorithm must process.  Usually there are natural units for the domain and range of this function.  There are two main measures of the efficiency of an algorithm. 1. Time Complexity 2. Space Complexity
  • 13. Time Complexity  Time complexity of an algorithm represents the amount of time required by the algorithm to run to completion.  The time complexity of an algorithm is also calculated by determining following 2 components:  Constant time part: Any instruction that is executed just o nce comes in this part. For example, input, output, if-else, switch, etc.  Variable Time Part: Any instruction that is executed more t han once, say n times, comes in this part. F or example, loops, recursion, etc.  Time requirements can be defined as a numerical functio n T(n), where T(n) can be measured as the number of ste ps, provided each step consumes constant time. For example, addition of two n-bit integers takes n steps. Consequently, the total computational time is T(n) = c ∗ n, wh ere c is the time taken for the addition of two bits. Here, we o bserve that T(n) grows linearly as the input size increases.
  • 14. Space Complexity  Space complexity of an algorithm refers to the amount of memory that this algorithm requires to execute and get the result.  This can be for inputs, temporary operations, or outputs.  The space complexity of an algorithm is calculated by determining following 2 components:  Fixed Part: This refers to the space that is definitely required by the algorithm. For example, input variables, output variables, program size, etc.  Variable Part: This refers to the space that can be different based on the implementation of the algorithm. For example, temporary variables, dynamic memory allocation, recursion stack space, etc.
  • 15. The two popular tools used in the representation of algorithms a re the following: 1. Pseudocode 2. Flowchart Algorithm Design Tools
  • 16.  An algorithm can be written in any of the natural languages such as English, German, French, etc.  One of the commonly used tools to define algorithms is the pseudocode.  Pseudocode is one of the tools that can be used to write a preliminary plan that can be developed into a computer program.  A pseudocode is an English-like presentation of the code required for an algorithm.  Pseudocode is a generic way of describing an algorithm without use of any specific p rogramming language syntax.  It is, as the name suggests, pseudo code —it cannot be executed on a real computer, but it models and resembles real programming code, and is written at roughly the same level of detail. Pseudocode
  • 17. Flowchart  A very effective tool to show the logic flow of a program is the flowchart.  A flowchart is a pictorial representation of an algorithm.  It hides all the details of an algorithm by giving a picture; it shows how the algorithm f lows from beginning to end.  A flowchart is a schematic representation of an algorithm or a stepwise process, showing the steps as boxes of various kinds, and their order by connecting these with arrows.  Flowcharts are used in designing or documenting a process or program.  Flowcharts are usually drawn using some standard symbols; however, some special symbols can also be developed when required.
  • 18. Flowchart Symbols Flowchart Symbols Symbol Symbol Name Purpose Start / Stop Used at the beginning and end of the algorithm to show start and end of the program. Process Indicates processes like mathematical operations. Input/ Output Used for denoting program inputs and outputs. Decision Stands for decision statements in a program, where answer is usually Yes or No. Arrow Shows relationships between different shapes. On-page Connector Connects two or more parts of a flowchart, which are on the same page. Off-page Connector Connects two parts of a flowchart which are s pread over different pages.
  • 19. Flowchart to calculate the average of two numbers
  • 20.  Asymptotic analysis of an algorithm refers to defining the mathematical boundation/ framing of its run-time performance.  Using asymptotic analysis, we can very well conclude the best case, average case, and worst case scenario of an algorithm.  Asymptotic analysis is input bound i.e., if there's no input to the algorithm, it is concluded to w ork in a constant time.  Other than the "input" all other factors are considered constant.  Asymptotic analysis refers to computing the running time of any operation in mathematical units of computation.  The time required by an algorithm falls under three types −  Best Case − Minimum time required for program execution.  Average Case − Average time required for program execution.  Worst Case − Maximum time required for program execution. Asymptotic Analysis
  • 21. Commonly used asymptotic notations to calculate the running time complexity of an algorithm. 1. Ο Notation 2. Ω Notation 3. θ Notation Asymptotic Notations
  • 22. • The notation Ο(n) is the formal way to express the upper bound of an algorithm's running time. • It measures the worst case time complexity or the longest amount of time an algorithm can possibly take to complete. For example, for a function f(n) Ο(f(n)) = { g(n) : there exists c > 0 and n0 such that f(n) ≤ c.g(n) for all n > n0. } Big Oh Notation, Ο
  • 23. Omega Notation, Ω  The notation Ω(n) is the formal way to express the l ower bound of an algorithm's running time.  It measures the best case time complexity or the best amount of time an algorithm can possibly take to complete. For example, for a function f(n) Ω(f(n)) ≥ { g(n) : there exists c > 0 and n0 such that g(n) ≤ c.f(n) for all n > n0. }
  • 24. Theta Notation, θ • The notation θ(n) is the formal way to express b oth the lower bound and the upper bound of an algorithm's running time. θ(f(n)) = { g(n) if and only if g(n) = Ο(f(n)) and g(n) = Ω(f(n )) for all n > n0. }
  • 25.  Introduction to Algorithms  Characteristics of an Algorithm  Algorithms Analysis  Algorithms Efficiency  Algorithms Design Tools  Asymptotic Analysis Summary