SlideShare a Scribd company logo
Design and Analysis of
Algorithm
Week 01
Problem Solving
 Solving problems is the core of computer
science. Programmers must first understand
how a human solves a problem, then
understand how to translate this "algorithm"
into something a computer can do, and
finally how to "write" the specific syntax
(required by a computer) to get the job
done. It is sometimes the case that a
machine will solve a problem in a completely
different way than a human.
Problem Solving
Computer Programmers are problem solvers. In
order to solve a problem on a computer you must:
 Know how to represent the information (data)
describing the problem.
 Determine the steps to transform the
information from one representation into
another.
Problem Solving Process
Algorithm
 An algorithm is a clearly defined set of instructions
to be followed to solve a problem. Algorithms are
generally created independent of underlying
programming languages.
 Informally, an algorithm is any well-defined
computational procedure that takes some value, or
set of values, as input and produces some value,
or set of values, as output. An algorithm is thus a
sequence of computational steps that transform
the input into the output. 5
Characteristics of an
Algorithm
 Not all procedures can be called an algorithm. 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.
6
Characteristics of an
Algorithm
– 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.
Example
 Problem − Design an algorithm to add two
numbers and display the result.
– Step 1 – START
– Step 2 – declare three integers a, b & c
– Step 3 – define values of a & b
– Step 4 – add values of a & b
– Step 5 – store output of Step 4 to c
– Step 6 – print c
– Step 7 – STOP
8
Example
 Problem − Design an algorithm to add two
numbers and display the result.
– Step 1 – START ADD
– Step 2 – get values of a & b
– Step 3 – c  a + b
– Step 4 – display c
– Step 5 – STOP
 Second method is preferable in Data
Structure and Algorithms
9
Algorithm Analysis
 Efficiency of an algorithm can be analyzed at two different
stages, before implementation and after implementation.
They are the following −
– A Priori Analysis − 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.
– A Posterior Analysis − This is an empirical analysis of
an algorithm. The selected algorithm is implemented
using programming language. This is then executed on
target computer machine. In this analysis, actual
statistics like running time and space required, are
collected 10
Pseudo Code and Algorithm
 An algorithm is a systematic logical approach
used to solve problems in a computer.
 Pseudocode is the statement in plain English
which may be translated later into a programming
language (program).
 Pseudo code is an intermediary between an
algorithm and implemented program
Example
Pseudo code to add two numbers:
 Take two number inputs
 Add numbers using the + operator
 Display the result
Pseudo Code Example
If Ali’s height is greater then 6 feet
Then
Ali can become a member of the Basket Ball
team
Conversion from Pseudo code to
Source code
Pseudo Code
If amir’s age is greater than Ammara’s age
then show message that amir is elder than
amara, otherwise show message that amir
is younger than ammara.
Conversion from Pseudo code
to Source code
Source Code
if (AmirAge > AmaraAge)
{
cout<< “Amir is older than Amara” ;
}
else
{
cout<<“Amir is younger than or of the same
age as Amara” ;
}
Algorithm : Find the largest number among three numbers
 Step 1: Start
 Step 2: Declare variables a,b and c.
 Step 3: Read variables a,b and c.
 Step 4: If a > b
 If a > c
 Display a is the largest number.
 Else
 Display c is the largest number.
 Else
 If b > c
 Display b is the largest number.
 Else
 Display c is the greatest number.
 Step 5: Stop
Algorithm: Find the factorial of a
number
 Step 1: Start
 Step 2: Declare variables n, factorial and i.
 Step 3: Initialize variables
 factorial ← 1
 i ← 1
 Step 4: Read value of n
 Step 5: Repeat the steps until i = n
 5.1: factorial ← factorial*i
 5.2: i ← i+1
 Step 6: Display factorial
 Step 7: Stop
Sorting Problem
 we might need to sort a sequence of numbers into non
decreasing order. This problem arises frequently in practice
and provides fertile ground for introducing many standard
design techniques and analysis tools. Here is how we
formally define the sorting problem:
 Input: A sequence of n numbers (a1, a2,……an).
Sorting Problem
 For example, given the input sequence (31; 41; 59; 26; 41; 58) a
sorting algorithm returns as output the sequence (26; 31; 41; 41; 58;
59). Such an input sequence is called an instance of the sorting
problem. In general, an instance of a problem consists of the input
(satisfying whatever constraints are imposed in the problem
statement) needed to compute a solution to the problem.
 Because many programs use it as an intermediate step, sorting is a
fundamental operation in computer science. As a result, we have a
large number of good sorting algorithms at our disposal. Which
algorithm is best for a given application depends on—among other
factors—the number of items to be sorted, the extent to which the
items are already somewhat sorted, possible restrictions on the item
values, the architecture of the computer, and the kind of storage
devices to be used: main memory, disks, or even tapes.
What kinds of problems are solved by
algorithms?
 The Human Genome Project has made great progress toward the goals
of identifying all the 100,000 genes in human DNA, determining the
sequences of the 3 billion chemical base pairs that make up human
DNA, storing this information in databases, and developing tools for
data analysis. Each of these steps requires sophisticated algorithms.
 The Internet enables people all around the world to quickly access and
retrieve large amounts of information. With the aid of clever algorithms,
sites on the internet are able to manage and manipulate this large
volume of data. Examples of problems that make essential use of
algorithms include finding good routes.
 Electronic commerce enables goods and services to be negotiated and
exchanged electronically, and it depends on the privacy of personal
information such as credit card numbers, passwords, and bank
statements. The core technologies used in electronic commerce include
public-key cryptography and digital signatures which are based on
numerical algorithms and number theory.
What kinds of problems are solved by
algorithms?
 Manufacturing and other commercial enterprises often need to
allocate scarce resources in the most beneficial way.
 An oil company may wish to know where to place its wells in
order to maximize its expected profit.
 A political candidate may want to determine where to spend
money buying campaign advertising in order to maximize the
chances of winning an election.
 An airline may wish to assign crews to flights in the least
expensive way possible, making sure that each flight is covered
and that government regulations regarding crew scheduling are
met.
 An Internet service provider may wish to determine where to
place additional resources in order to serve its customers more
effectively. All of these are examples of problems that can be
solved using linear programming algos.

More Related Content

Similar to AOA Week 01.ppt (20)

PPTX
Algorithm for computational problematic sit
Saurabh846965
 
PPT
UNIT-1-PPT-DESIGN AND ANALYSIS OF ALGORITHMS
ramalakshmikaliappan
 
PPT
Problem Solving Techniques notes for Unit 1
SATHYABAMAMADHANKUMA
 
PPT
chapter 1
yatheesha
 
PPTX
Design and analysis of algorithms Module-I.pptx
DhanushreeAN1
 
PDF
1.1 the introduction of design and analysis of algorithm
Mohammed khaja Jamaluddin
 
DOC
Program concep sequential statements
ankurkhanna
 
PPT
Unit 1 python (2021 r)
praveena p
 
PPTX
Introduction to python Grade 10 with exercies.pptx
judynouran
 
PPTX
01 Introduction to analysis of Algorithms.pptx
ssuser586772
 
PPSX
Algorithm and flowchart
Sachin Goyani
 
PPTX
Chp-1 DAA (2).pptx design analysis and algoritham presentation
vaishnavbhavna17
 
PPS
Data Structures and Algorithms Unit 01
Prashanth Shivakumar
 
PPTX
Algorithm types performance steps working
Saurabh846965
 
PDF
Algorithms notes 2 tutorials duniya
TutorialsDuniya.com
 
PDF
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
dinesh620610
 
PPTX
Algorithmics, intro to data structures.pptx
OntopScenes
 
PPTX
Segment_1_New computer algorithm for cse.pptx
fahmidasetu
 
PDF
Practical 01 (detailed)
Muhammadalizardari
 
PDF
Algo and flowchart
Swapnil Suryavanshi
 
Algorithm for computational problematic sit
Saurabh846965
 
UNIT-1-PPT-DESIGN AND ANALYSIS OF ALGORITHMS
ramalakshmikaliappan
 
Problem Solving Techniques notes for Unit 1
SATHYABAMAMADHANKUMA
 
chapter 1
yatheesha
 
Design and analysis of algorithms Module-I.pptx
DhanushreeAN1
 
1.1 the introduction of design and analysis of algorithm
Mohammed khaja Jamaluddin
 
Program concep sequential statements
ankurkhanna
 
Unit 1 python (2021 r)
praveena p
 
Introduction to python Grade 10 with exercies.pptx
judynouran
 
01 Introduction to analysis of Algorithms.pptx
ssuser586772
 
Algorithm and flowchart
Sachin Goyani
 
Chp-1 DAA (2).pptx design analysis and algoritham presentation
vaishnavbhavna17
 
Data Structures and Algorithms Unit 01
Prashanth Shivakumar
 
Algorithm types performance steps working
Saurabh846965
 
Algorithms notes 2 tutorials duniya
TutorialsDuniya.com
 
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
dinesh620610
 
Algorithmics, intro to data structures.pptx
OntopScenes
 
Segment_1_New computer algorithm for cse.pptx
fahmidasetu
 
Practical 01 (detailed)
Muhammadalizardari
 
Algo and flowchart
Swapnil Suryavanshi
 

Recently uploaded (20)

PPTX
Blended Wing Body y jet engines Aircrafts.pptx
anshul9051
 
PPTX
SQL_Statement_Categories_With_Examples.pptx
sedhupathivishnu2
 
PDF
mlbrolllist2024-25 (1)ygrude4ferfssrddde
rishabh1chaurasia4
 
PDF
5 Psychological Principles to Apply in Web Design for Better User Engagement
DigitalConsulting
 
PDF
Kitchen_Aluminium_Doors_Prices_Presentation.pdf
Royal Matrixs
 
PDF
Dark Green White Gradient Technology Keynote Presentation.pdf
sharmayakshita0308
 
PDF
Spring Summer 2027 Beauty & Wellness Trend Book
Peclers Paris
 
DOCX
BusinessPlan_redesignedf word format .docx
MohammadMaqatif
 
PPTX
Mini-Project description of design of expert project
peter349484
 
PPTX
Time_Management_Presenuuuuuuutation.pptx
Rajni Goyal
 
PDF
Home_Decor_Presentation and idiea with decor
sp1357556
 
PDF
Shayna Andrieze Yjasmin Goles - Your VA!
shaynagoles31
 
PPTX
Digital Printing presentation-update-26.08.24.pptx
MDFoysalAhmed13
 
PDF
Fashion project1 kebaya reimagined slideshow
reysultane
 
PDF
ornament making and its material used for.pdf
departmentofcdft
 
PPTX
confluence of tradition in modernity- design approaches and design thinking
madhuvidya7
 
DOCX
Amplopxxxxxxxxxvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
Lm Hardin 'Idin'
 
PPTX
Interior Design Portfolio XL by Slidesgo.pptx
jeremysalvadore19
 
PDF
Hossain Kamyab on Mixing and Matching Furniture.pdf
Hossain Kamyab
 
PPTX
designing in footwear- exploring the art and science behind shoe design
madhuvidya7
 
Blended Wing Body y jet engines Aircrafts.pptx
anshul9051
 
SQL_Statement_Categories_With_Examples.pptx
sedhupathivishnu2
 
mlbrolllist2024-25 (1)ygrude4ferfssrddde
rishabh1chaurasia4
 
5 Psychological Principles to Apply in Web Design for Better User Engagement
DigitalConsulting
 
Kitchen_Aluminium_Doors_Prices_Presentation.pdf
Royal Matrixs
 
Dark Green White Gradient Technology Keynote Presentation.pdf
sharmayakshita0308
 
Spring Summer 2027 Beauty & Wellness Trend Book
Peclers Paris
 
BusinessPlan_redesignedf word format .docx
MohammadMaqatif
 
Mini-Project description of design of expert project
peter349484
 
Time_Management_Presenuuuuuuutation.pptx
Rajni Goyal
 
Home_Decor_Presentation and idiea with decor
sp1357556
 
Shayna Andrieze Yjasmin Goles - Your VA!
shaynagoles31
 
Digital Printing presentation-update-26.08.24.pptx
MDFoysalAhmed13
 
Fashion project1 kebaya reimagined slideshow
reysultane
 
ornament making and its material used for.pdf
departmentofcdft
 
confluence of tradition in modernity- design approaches and design thinking
madhuvidya7
 
Amplopxxxxxxxxxvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
Lm Hardin 'Idin'
 
Interior Design Portfolio XL by Slidesgo.pptx
jeremysalvadore19
 
Hossain Kamyab on Mixing and Matching Furniture.pdf
Hossain Kamyab
 
designing in footwear- exploring the art and science behind shoe design
madhuvidya7
 
Ad

AOA Week 01.ppt

  • 1. Design and Analysis of Algorithm Week 01
  • 2. Problem Solving  Solving problems is the core of computer science. Programmers must first understand how a human solves a problem, then understand how to translate this "algorithm" into something a computer can do, and finally how to "write" the specific syntax (required by a computer) to get the job done. It is sometimes the case that a machine will solve a problem in a completely different way than a human.
  • 3. Problem Solving Computer Programmers are problem solvers. In order to solve a problem on a computer you must:  Know how to represent the information (data) describing the problem.  Determine the steps to transform the information from one representation into another.
  • 5. Algorithm  An algorithm is a clearly defined set of instructions to be followed to solve a problem. Algorithms are generally created independent of underlying programming languages.  Informally, an algorithm is any well-defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values, as output. An algorithm is thus a sequence of computational steps that transform the input into the output. 5
  • 6. Characteristics of an Algorithm  Not all procedures can be called an algorithm. 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. 6
  • 7. Characteristics of an Algorithm – 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.
  • 8. Example  Problem − Design an algorithm to add two numbers and display the result. – Step 1 – START – Step 2 – declare three integers a, b & c – Step 3 – define values of a & b – Step 4 – add values of a & b – Step 5 – store output of Step 4 to c – Step 6 – print c – Step 7 – STOP 8
  • 9. Example  Problem − Design an algorithm to add two numbers and display the result. – Step 1 – START ADD – Step 2 – get values of a & b – Step 3 – c  a + b – Step 4 – display c – Step 5 – STOP  Second method is preferable in Data Structure and Algorithms 9
  • 10. Algorithm Analysis  Efficiency of an algorithm can be analyzed at two different stages, before implementation and after implementation. They are the following − – A Priori Analysis − 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. – A Posterior Analysis − This is an empirical analysis of an algorithm. The selected algorithm is implemented using programming language. This is then executed on target computer machine. In this analysis, actual statistics like running time and space required, are collected 10
  • 11. Pseudo Code and Algorithm  An algorithm is a systematic logical approach used to solve problems in a computer.  Pseudocode is the statement in plain English which may be translated later into a programming language (program).  Pseudo code is an intermediary between an algorithm and implemented program
  • 12. Example Pseudo code to add two numbers:  Take two number inputs  Add numbers using the + operator  Display the result
  • 13. Pseudo Code Example If Ali’s height is greater then 6 feet Then Ali can become a member of the Basket Ball team
  • 14. Conversion from Pseudo code to Source code Pseudo Code If amir’s age is greater than Ammara’s age then show message that amir is elder than amara, otherwise show message that amir is younger than ammara.
  • 15. Conversion from Pseudo code to Source code Source Code if (AmirAge > AmaraAge) { cout<< “Amir is older than Amara” ; } else { cout<<“Amir is younger than or of the same age as Amara” ; }
  • 16. Algorithm : Find the largest number among three numbers  Step 1: Start  Step 2: Declare variables a,b and c.  Step 3: Read variables a,b and c.  Step 4: If a > b  If a > c  Display a is the largest number.  Else  Display c is the largest number.  Else  If b > c  Display b is the largest number.  Else  Display c is the greatest number.  Step 5: Stop
  • 17. Algorithm: Find the factorial of a number  Step 1: Start  Step 2: Declare variables n, factorial and i.  Step 3: Initialize variables  factorial ← 1  i ← 1  Step 4: Read value of n  Step 5: Repeat the steps until i = n  5.1: factorial ← factorial*i  5.2: i ← i+1  Step 6: Display factorial  Step 7: Stop
  • 18. Sorting Problem  we might need to sort a sequence of numbers into non decreasing order. This problem arises frequently in practice and provides fertile ground for introducing many standard design techniques and analysis tools. Here is how we formally define the sorting problem:  Input: A sequence of n numbers (a1, a2,……an).
  • 19. Sorting Problem  For example, given the input sequence (31; 41; 59; 26; 41; 58) a sorting algorithm returns as output the sequence (26; 31; 41; 41; 58; 59). Such an input sequence is called an instance of the sorting problem. In general, an instance of a problem consists of the input (satisfying whatever constraints are imposed in the problem statement) needed to compute a solution to the problem.  Because many programs use it as an intermediate step, sorting is a fundamental operation in computer science. As a result, we have a large number of good sorting algorithms at our disposal. Which algorithm is best for a given application depends on—among other factors—the number of items to be sorted, the extent to which the items are already somewhat sorted, possible restrictions on the item values, the architecture of the computer, and the kind of storage devices to be used: main memory, disks, or even tapes.
  • 20. What kinds of problems are solved by algorithms?  The Human Genome Project has made great progress toward the goals of identifying all the 100,000 genes in human DNA, determining the sequences of the 3 billion chemical base pairs that make up human DNA, storing this information in databases, and developing tools for data analysis. Each of these steps requires sophisticated algorithms.  The Internet enables people all around the world to quickly access and retrieve large amounts of information. With the aid of clever algorithms, sites on the internet are able to manage and manipulate this large volume of data. Examples of problems that make essential use of algorithms include finding good routes.  Electronic commerce enables goods and services to be negotiated and exchanged electronically, and it depends on the privacy of personal information such as credit card numbers, passwords, and bank statements. The core technologies used in electronic commerce include public-key cryptography and digital signatures which are based on numerical algorithms and number theory.
  • 21. What kinds of problems are solved by algorithms?  Manufacturing and other commercial enterprises often need to allocate scarce resources in the most beneficial way.  An oil company may wish to know where to place its wells in order to maximize its expected profit.  A political candidate may want to determine where to spend money buying campaign advertising in order to maximize the chances of winning an election.  An airline may wish to assign crews to flights in the least expensive way possible, making sure that each flight is covered and that government regulations regarding crew scheduling are met.  An Internet service provider may wish to determine where to place additional resources in order to serve its customers more effectively. All of these are examples of problems that can be solved using linear programming algos.