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

Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming ConceptsJussi Pohjolainen
 
Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialQA TrainingHub
 
Our presentation on algorithm design
Our presentation on algorithm designOur presentation on algorithm design
Our presentation on algorithm designNahid Hasan
 
Algorithm Design & Implementation
Algorithm Design & ImplementationAlgorithm Design & Implementation
Algorithm Design & ImplementationGaditek
 
Programming fundamentals lecture 1&2
Programming fundamentals lecture 1&2Programming fundamentals lecture 1&2
Programming fundamentals lecture 1&2Raja Hamid
 
XII Computer Science- Chapter 1-Function
XII  Computer Science- Chapter 1-FunctionXII  Computer Science- Chapter 1-Function
XII Computer Science- Chapter 1-FunctionPrem Joel
 
Steps for c program execution
Steps for c program executionSteps for c program execution
Steps for c program executionRumman Ansari
 
Presentation on generation of languages
Presentation on generation of languagesPresentation on generation of languages
Presentation on generation of languagesRicha Pant
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignAkhil Kaushik
 
Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Janki Shah
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal languageRabia Khalid
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchartSachin Goyani
 

What's hot (20)

Algorithm big o
Algorithm big oAlgorithm big o
Algorithm big o
 
Compilers
CompilersCompilers
Compilers
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming Concepts
 
Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python Tutorial
 
Our presentation on algorithm design
Our presentation on algorithm designOur presentation on algorithm design
Our presentation on algorithm design
 
Algorithm Design & Implementation
Algorithm Design & ImplementationAlgorithm Design & Implementation
Algorithm Design & Implementation
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
Programming fundamentals lecture 1&2
Programming fundamentals lecture 1&2Programming fundamentals lecture 1&2
Programming fundamentals lecture 1&2
 
XII Computer Science- Chapter 1-Function
XII  Computer Science- Chapter 1-FunctionXII  Computer Science- Chapter 1-Function
XII Computer Science- Chapter 1-Function
 
Steps for c program execution
Steps for c program executionSteps for c program execution
Steps for c program execution
 
Presentation on generation of languages
Presentation on generation of languagesPresentation on generation of languages
Presentation on generation of languages
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler Design
 
Compiler design
Compiler designCompiler design
Compiler design
 
Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
 
Python
PythonPython
Python
 
C++ ppt
C++ pptC++ ppt
C++ ppt
 
register
registerregister
register
 
Compilers
CompilersCompilers
Compilers
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 

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

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
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
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
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
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
 
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
 
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
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 

Recently uploaded (20)

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
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
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
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).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
 
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 🔝✔️✔️
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 

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