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

What's hot

Algorithms and flowcharts
Algorithms and flowchartsAlgorithms and flowcharts
Algorithms and flowchartsSamuel Igbanogu
 
Pascal Programming Language
Pascal Programming LanguagePascal Programming Language
Pascal Programming LanguageReham AlBlehid
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchartRabin BK
 
structured programming
structured programmingstructured programming
structured programmingAhmad54321
 
Pseudocode flowcharts
Pseudocode flowchartsPseudocode flowcharts
Pseudocode flowchartsnicky_walters
 
History of Programming Language
History of Programming LanguageHistory of Programming Language
History of Programming Languagetahria123
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C ProgrammingKamal Acharya
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codeshermiraguilar
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language CourseVivek chan
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python ProgrammingKamal Acharya
 
pseudocode and Flowchart
pseudocode and Flowchartpseudocode and Flowchart
pseudocode and FlowchartALI RAZA
 
Programming fundamentals lecture 1 0f c
Programming fundamentals lecture 1 0f cProgramming fundamentals lecture 1 0f c
Programming fundamentals lecture 1 0f cRaja Hamid
 
Algorithm and flowchart
Algorithm and flowchart Algorithm and flowchart
Algorithm and flowchart Shivam Sharma
 
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithmrajkumar1631010038
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)praveena p
 

What's hot (20)

Algorithms and flowcharts
Algorithms and flowchartsAlgorithms and flowcharts
Algorithms and flowcharts
 
Pascal Programming Language
Pascal Programming LanguagePascal Programming Language
Pascal Programming Language
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
structured programming
structured programmingstructured programming
structured programming
 
Pseudocode flowcharts
Pseudocode flowchartsPseudocode flowcharts
Pseudocode flowcharts
 
History of Programming Language
History of Programming LanguageHistory of Programming Language
History of Programming Language
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C Programming
 
Java Applet
Java AppletJava Applet
Java Applet
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codes
 
Computer languages 11
Computer languages 11Computer languages 11
Computer languages 11
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language Course
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python Programming
 
pseudocode and Flowchart
pseudocode and Flowchartpseudocode and Flowchart
pseudocode and Flowchart
 
Programming fundamentals lecture 1 0f c
Programming fundamentals lecture 1 0f cProgramming fundamentals lecture 1 0f c
Programming fundamentals lecture 1 0f c
 
Algorithm and flowchart
Algorithm and flowchart Algorithm and flowchart
Algorithm and flowchart
 
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithm
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
 
Introduction to algorithms
Introduction to algorithmsIntroduction to algorithms
Introduction to algorithms
 

Similar to Introduction to algorithms

Data structures algorithms basics
Data structures   algorithms basicsData structures   algorithms basics
Data structures algorithms basicsayeshasafdar8
 
2. Introduction to Algorithm.pptx
2. Introduction to Algorithm.pptx2. Introduction to Algorithm.pptx
2. Introduction to Algorithm.pptxRahikAhmed1
 
Algorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structureAlgorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structureVrushali Dhanokar
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdfNayanChandak1
 
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
 
Unit i basic concepts of algorithms
Unit i basic concepts of algorithmsUnit i basic concepts of algorithms
Unit i basic concepts of algorithmssangeetha s
 
2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdfishan743441
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Dr. Pankaj Agarwal
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdfMemMem25
 
Theory of algorithms final
Theory of algorithms final Theory of algorithms final
Theory of algorithms final Dgech
 
Algorithms notes 2 tutorials duniya
Algorithms notes 2   tutorials duniyaAlgorithms notes 2   tutorials duniya
Algorithms notes 2 tutorials duniyaTutorialsDuniya.com
 
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
 

Similar to Introduction to algorithms (20)

Data structures algorithms basics
Data structures   algorithms basicsData structures   algorithms basics
Data structures algorithms basics
 
2. Introduction to Algorithm.pptx
2. Introduction to Algorithm.pptx2. Introduction to Algorithm.pptx
2. Introduction to Algorithm.pptx
 
Algorithm.pptx
Algorithm.pptxAlgorithm.pptx
Algorithm.pptx
 
Algorithm.pptx
Algorithm.pptxAlgorithm.pptx
Algorithm.pptx
 
Algorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structureAlgorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structure
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdf
 
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
 
Unit i basic concepts of algorithms
Unit i basic concepts of algorithmsUnit i basic concepts of algorithms
Unit i basic concepts of algorithms
 
Unit ii algorithm
Unit   ii algorithmUnit   ii algorithm
Unit ii algorithm
 
2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis
 
Daa chapter 1
Daa chapter 1Daa chapter 1
Daa chapter 1
 
Python algorithm
Python algorithmPython algorithm
Python algorithm
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdf
 
DATA STRUCTURE.pdf
DATA STRUCTURE.pdfDATA STRUCTURE.pdf
DATA STRUCTURE.pdf
 
DATA STRUCTURE
DATA STRUCTUREDATA STRUCTURE
DATA STRUCTURE
 
Theory of algorithms final
Theory of algorithms final Theory of algorithms final
Theory of algorithms final
 
Algorithms notes 2 tutorials duniya
Algorithms notes 2   tutorials duniyaAlgorithms notes 2   tutorials duniya
Algorithms notes 2 tutorials duniya
 
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
 

More from Madishetty Prathibha

More from Madishetty Prathibha (14)

Object Oriented programming - Introduction
Object Oriented programming - IntroductionObject Oriented programming - Introduction
Object Oriented programming - Introduction
 
Access modifiers in java
Access modifiers in javaAccess modifiers in java
Access modifiers in java
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
Structure of java program diff c- cpp and java
Structure of java program  diff c- cpp and javaStructure of java program  diff c- cpp and java
Structure of java program diff c- cpp and java
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Types of datastructures
Types of datastructuresTypes of datastructures
Types of datastructures
 
Java data types, variables and jvm
Java data types, variables and jvm Java data types, variables and jvm
Java data types, variables and jvm
 
Introduction to data structures (ss)
Introduction to data structures (ss)Introduction to data structures (ss)
Introduction to data structures (ss)
 
Java Tokens
Java  TokensJava  Tokens
Java Tokens
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in Java
 
Java features
Java  features Java  features
Java features
 
Introduction of java
Introduction  of javaIntroduction  of java
Introduction of java
 

Recently uploaded

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answersdalebeck957
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactisticshameyhk98
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 

Recently uploaded (20)

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 

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