SlideShare a Scribd company logo
WHAT IS AN ALGORITHM?
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.
ALGORITHM
An algorithm: is an outline of the steps that a program or any computational
procedure has to take.
A program: on the other hand is an implementation of an algorithm and it
could be in any programming language.
Data structure: is the way we need to organize the data, so that it can be used
effectively by the program.
WHAT IS AN ALGORITHM?
We can also view an algorithm as a tool for solving a well-specified
computational problem.
The statement of the problem specifies in general terms the desired
input/output relationship.
The algorithm describes a specific computational procedure for achieving that
input/output relationship.
ALGORITHM
What is an algorithmic problem?
specifications
of an input ?
specification
of output as
function of
input
Input: 67, 34, 12, 5, 7, 67, 1
Output: 1, 5, 7, 12, 34, 67, 67
ALGORITHM
What is an algorithmic problem?
specifications
of an input Algorithm
specification
of output as
function of
input
An algorithm is essentially, describing the actions that one should take on the
input instance to get the specified output.
WHAT IS AN ALGORITHM?
For example, we might need to sort a sequence of numbers into non-
decreasing order.
Here is how we formally define the sorting problem.
Input: A sequence of n numbers <a1, a2, . . ., an >.
Output: A permutation (reordering) <a’1, a’2, . . ., a’n > of the input sequence such
that a’1≤ a’2 ≤. . . ≤a’n .
WHAT IS AN ALGORITHM?
For example, we might need to sort a sequence of numbers into non-
decreasing order.
Here is how we formally define the sorting problem.
Input: A sequence of n numbers <a1, a2, . . ., an >.
Output: A permutation (reordering) <a’1, a’2, . . ., a’n > of the input sequence such
that a’1≤ a’2 ≤. . . ≤a’n .
WHAT IS AN ALGORITHM?
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.
ALGORITHM
Characteristics of 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.
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
WHAT IS AN ALGORITHM?
An algorithm is said to be correct if, for every input instance, it halts with the
correct output.
We say that a correct algorithm solves the given computational problem.
An incorrect algorithm might not halt at all on some input instances, or it might
halt with an incorrect answer.
Contrary to what you might expect, incorrect algorithms can sometimes be
useful, if we can control their error rate.
WHAT IS AN ALGORITHM?
There are two main criteria for judging the merits of algorithms:
1. correctness (does the algorithm give solution to the problem in a finite
number of steps?) and
2. efficiency (how much resources (in terms of memory and time) does it take
to execute the).
WHY THE ANALYSIS OF ALGORITHMS?
In computer science, multiple algorithms are available for solving the same
problem (for example, a sorting problem has many algorithms, like insertion
sort, selection sort, quick sort and many more).
Algorithm analysis helps us to determine which algorithm is most efficient in
terms of time and space consumed.
GOAL OF THE ANALYSIS OF ALGORITHMS
The goal of the analysis of algorithms is to compare algorithms (or solutions)
mainly in terms of running time but also in terms of other factors (e.g.,
memory, developer effort, etc.)
HOW DOES ONE MEASURE THE RUNNING TIME OF AN ALGORITHM?
Let us look at the empirical (experimental) study.
1. Write a program that implements the algorithm.
2. Run the program with varying data sets in which some are smaller, some are
of larger data sets, some would be of some kinds and some would be of
different kinds of varying composition.
3. Use a method (like System.currentTimeMillis()) to get an accurate measure
of the actual running time.
HOW DOES ONE MEASURE THE RUNNING TIME OF AN ALGORITHM?
This has certain limitations.
1. First you have to implement the algorithm in which we will be able to determine how
good your algorithm is. Implementing it is a huge overhead, where you have to spend
considerable amount of time.
2. Experiments can be done only on a limited set of inputs.
3. You can run your experiment on a small set of instances and that might not really
indicate the time that your algorithm is taking for other inputs, which you have not
considered in your experiment.
4. It is machine dependent.
HOW DOES ONE MEASURE THE RUNNING TIME OF AN ALGORITHM?
Theoretical or apriori analysis.
• Let us assume that we express the running time of a given algorithm as a
function of the input size n (i.e., f ( n )) and compare these different functions
corresponding to running times.
• That is, this methodology aims at associating with each algorithm a function
f(n) that characterizes the running time of the algorithm in terms of the input
size n.
• This kind of comparison is independent of machine time, programming style,
etc.
WHAT IS RUNNING TIME ANALYSIS?
It is the process of determining how processing time increases as the size of the
problem (input size) increases.
Input size is the number of elements in the input, and depending on the
problem type, the input may be of different types.
WHAT IS RUNNING TIME ANALYSIS?
Typical functions that will be encountered include n and n2
.
For example, we will write statements of the type:
"Algorithm A runs in time proportional to n," meaning that if we were to
perform experiments, we would find that the actual running time of algorithm
A on any input of size n never exceeds cn, where c is a constant that depends
on the hardware and software environment used in the experiment.
WHAT IS RUNNING TIME ANALYSIS?
Given two algorithms A and B, where
A runs in time proportional to n and
B runs intime proportional to n2
,
Then, we will prefer A to B, since the function n grows at a smaller rate than the
function n2
.
WHAT IS RATE OF GROWTH?
The rate at which the running time increases as a function of input is called rate
of growth.
TYPES OF ANALYSIS
To analyze the given algorithm, we need to know with which inputs the
algorithm takes less time (performing wel1) and with which inputs the
algorithm takes a long time.
We have already seen that an algorithm can be represented in the form of an
expression.
That means we represent the algorithm with multiple expressions:
one for the case where it takes less time and another for the case where it
takes more time.
TYPES OF ANALYSIS
In general, the first case is called the best case and the second case is called the
worst case for the algorithm.
• Worst case
○ Defines the input for which the algorithm takes a long time (slowest time to
complete).
○ Input is the one for which the algorithm runs the slowest.
TYPES OF ANALYSIS
In general, the first case is called the best case and the second case is called the
worst case for the algorithm.
• Best case
o Defines the input for which the algorithm takes the least time (fastest time
to complete).
o Input is the one for which the algorithm runs the fastest.
TYPES OF ANALYSIS
• Average case
○ Provides a prediction about the running time of the algorithm.
○ Run the algorithm many times, using many different inputs that come from
some distribution that generates these inputs, compute the total running time
(by adding the individual times), and divide by the number of trials.
○ Assumes that the input is random.
Lower Bound <= Average Time <= Upper Bound
WHAT IS AN ALGORITHM?
Let us consider the problem of preparing an omelette.
To prepare an omelette, we follow the steps given below:
1) Get the frying pan.
2) Get the oil.
A. Do we have oil?
a. If yes, put it in the pan.
b. If no, do we want to buy oil?
i. If yes, then go out and buy.
ii. If no, we can terminate.
3) Turn on the stove, etc...

More Related Content

Similar to Algorithm description in data structures (20)

PPTX
Algorithm in data structure bca .pptx
SukhBanger
 
PPTX
Design and Analysis of Algorithms.pptx
Syed Zaid Irshad
 
PPTX
Module-1.pptxbdjdhcdbejdjhdbchchchchchjcjcjc
shashashashashank
 
PPT
Introduction to design and analysis of algorithm
DevaKumari Vijay
 
PPTX
daa unit 1.pptx
LakshayYadav46
 
PDF
Introduction to analysis algorithm in computer Science
tissandavid
 
PDF
introduction to analysis of algorithm in computer science
tissandavid
 
PPTX
Unit 1, ADA.pptx
jinkhatima
 
PPTX
Introduction to algorithms
Madishetty Prathibha
 
PPTX
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
AntareepMajumder
 
PPTX
Algorithm analysis (All in one)
jehan1987
 
PPTX
Algorithm analysis and design
Megha V
 
PPTX
Unit i basic concepts of algorithms
sangeetha s
 
PDF
Introduction to Algorithms Complexity Analysis
Dr. Pankaj Agarwal
 
PDF
Data Structure & Algorithms - Introduction
babuk110
 
PDF
Algorithm Design and Analysis
Sayed Chhattan Shah
 
PPTX
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
RashidFaridChishti
 
PDF
Daa notes 1
smruti sarangi
 
PPTX
Modile-1-PPT-1-BCAC0207-AlgorithmDesign.pptx
ryadavrohit26
 
Algorithm in data structure bca .pptx
SukhBanger
 
Design and Analysis of Algorithms.pptx
Syed Zaid Irshad
 
Module-1.pptxbdjdhcdbejdjhdbchchchchchjcjcjc
shashashashashank
 
Introduction to design and analysis of algorithm
DevaKumari Vijay
 
daa unit 1.pptx
LakshayYadav46
 
Introduction to analysis algorithm in computer Science
tissandavid
 
introduction to analysis of algorithm in computer science
tissandavid
 
Unit 1, ADA.pptx
jinkhatima
 
Introduction to algorithms
Madishetty Prathibha
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
AntareepMajumder
 
Algorithm analysis (All in one)
jehan1987
 
Algorithm analysis and design
Megha V
 
Unit i basic concepts of algorithms
sangeetha s
 
Introduction to Algorithms Complexity Analysis
Dr. Pankaj Agarwal
 
Data Structure & Algorithms - Introduction
babuk110
 
Algorithm Design and Analysis
Sayed Chhattan Shah
 
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
RashidFaridChishti
 
Daa notes 1
smruti sarangi
 
Modile-1-PPT-1-BCAC0207-AlgorithmDesign.pptx
ryadavrohit26
 

Recently uploaded (20)

PPTX
Artificial Intelligence jejeiejj3iriejrjifirirjdjeie
VikingsGaming2
 
PPTX
Comparison of Flexible and Rigid Pavements in Bangladesh
Arifur Rahman
 
PDF
FSE-Journal-First-Automated code editing with search-generate-modify.pdf
cl144
 
PPTX
template.pptxr4t5y67yrttttttttttttttttttttttttttttttttttt
SithamparanaathanPir
 
PDF
MODULE-5 notes [BCG402-CG&V] PART-B.pdf
Alvas Institute of Engineering and technology, Moodabidri
 
PPSX
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
 
DOCX
Engineering Geology Field Report to Malekhu .docx
justprashant567
 
PPTX
darshai cross section and river section analysis
muk7971
 
PDF
Decision support system in machine learning models for a face recognition-bas...
TELKOMNIKA JOURNAL
 
PDF
Python Mini Project: Command-Line Quiz Game for School/College Students
MPREETHI7
 
PDF
LLC CM NCP1399 SIMPLIS MODEL MANUAL.PDF
ssuser1be9ce
 
PDF
Module - 4 Machine Learning -22ISE62.pdf
Dr. Shivashankar
 
PDF
Module - 5 Machine Learning-22ISE62.pdf
Dr. Shivashankar
 
PDF
13th International Conference of Security, Privacy and Trust Management (SPTM...
ijcisjournal
 
PPTX
Unit_I Functional Units, Instruction Sets.pptx
logaprakash9
 
PDF
PROGRAMMING REQUESTS/RESPONSES WITH GREATFREE IN THE CLOUD ENVIRONMENT
samueljackson3773
 
PPTX
CM Function of the heart pp.pptxafsasdfddsf
drmaneharshalid
 
PPTX
Explore USA’s Best Structural And Non Structural Steel Detailing
Silicon Engineering Consultants LLC
 
PDF
Tesia Dobrydnia - An Avid Hiker And Backpacker
Tesia Dobrydnia
 
PPT
FINAL plumbing code for board exam passer
MattKristopherDiaz
 
Artificial Intelligence jejeiejj3iriejrjifirirjdjeie
VikingsGaming2
 
Comparison of Flexible and Rigid Pavements in Bangladesh
Arifur Rahman
 
FSE-Journal-First-Automated code editing with search-generate-modify.pdf
cl144
 
template.pptxr4t5y67yrttttttttttttttttttttttttttttttttttt
SithamparanaathanPir
 
MODULE-5 notes [BCG402-CG&V] PART-B.pdf
Alvas Institute of Engineering and technology, Moodabidri
 
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
 
Engineering Geology Field Report to Malekhu .docx
justprashant567
 
darshai cross section and river section analysis
muk7971
 
Decision support system in machine learning models for a face recognition-bas...
TELKOMNIKA JOURNAL
 
Python Mini Project: Command-Line Quiz Game for School/College Students
MPREETHI7
 
LLC CM NCP1399 SIMPLIS MODEL MANUAL.PDF
ssuser1be9ce
 
Module - 4 Machine Learning -22ISE62.pdf
Dr. Shivashankar
 
Module - 5 Machine Learning-22ISE62.pdf
Dr. Shivashankar
 
13th International Conference of Security, Privacy and Trust Management (SPTM...
ijcisjournal
 
Unit_I Functional Units, Instruction Sets.pptx
logaprakash9
 
PROGRAMMING REQUESTS/RESPONSES WITH GREATFREE IN THE CLOUD ENVIRONMENT
samueljackson3773
 
CM Function of the heart pp.pptxafsasdfddsf
drmaneharshalid
 
Explore USA’s Best Structural And Non Structural Steel Detailing
Silicon Engineering Consultants LLC
 
Tesia Dobrydnia - An Avid Hiker And Backpacker
Tesia Dobrydnia
 
FINAL plumbing code for board exam passer
MattKristopherDiaz
 
Ad

Algorithm description in data structures

  • 1. WHAT IS AN ALGORITHM? 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.
  • 2. ALGORITHM An algorithm: is an outline of the steps that a program or any computational procedure has to take. A program: on the other hand is an implementation of an algorithm and it could be in any programming language. Data structure: is the way we need to organize the data, so that it can be used effectively by the program.
  • 3. WHAT IS AN ALGORITHM? We can also view an algorithm as a tool for solving a well-specified computational problem. The statement of the problem specifies in general terms the desired input/output relationship. The algorithm describes a specific computational procedure for achieving that input/output relationship.
  • 4. ALGORITHM What is an algorithmic problem? specifications of an input ? specification of output as function of input Input: 67, 34, 12, 5, 7, 67, 1 Output: 1, 5, 7, 12, 34, 67, 67
  • 5. ALGORITHM What is an algorithmic problem? specifications of an input Algorithm specification of output as function of input An algorithm is essentially, describing the actions that one should take on the input instance to get the specified output.
  • 6. WHAT IS AN ALGORITHM? For example, we might need to sort a sequence of numbers into non- decreasing order. Here is how we formally define the sorting problem. Input: A sequence of n numbers <a1, a2, . . ., an >. Output: A permutation (reordering) <a’1, a’2, . . ., a’n > of the input sequence such that a’1≤ a’2 ≤. . . ≤a’n .
  • 7. WHAT IS AN ALGORITHM? For example, we might need to sort a sequence of numbers into non- decreasing order. Here is how we formally define the sorting problem. Input: A sequence of n numbers <a1, a2, . . ., an >. Output: A permutation (reordering) <a’1, a’2, . . ., a’n > of the input sequence such that a’1≤ a’2 ≤. . . ≤a’n .
  • 8. WHAT IS AN ALGORITHM? 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.
  • 9. ALGORITHM Characteristics of 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. 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
  • 10. WHAT IS AN ALGORITHM? An algorithm is said to be correct if, for every input instance, it halts with the correct output. We say that a correct algorithm solves the given computational problem. An incorrect algorithm might not halt at all on some input instances, or it might halt with an incorrect answer. Contrary to what you might expect, incorrect algorithms can sometimes be useful, if we can control their error rate.
  • 11. WHAT IS AN ALGORITHM? There are two main criteria for judging the merits of algorithms: 1. correctness (does the algorithm give solution to the problem in a finite number of steps?) and 2. efficiency (how much resources (in terms of memory and time) does it take to execute the).
  • 12. WHY THE ANALYSIS OF ALGORITHMS? In computer science, multiple algorithms are available for solving the same problem (for example, a sorting problem has many algorithms, like insertion sort, selection sort, quick sort and many more). Algorithm analysis helps us to determine which algorithm is most efficient in terms of time and space consumed.
  • 13. GOAL OF THE ANALYSIS OF ALGORITHMS The goal of the analysis of algorithms is to compare algorithms (or solutions) mainly in terms of running time but also in terms of other factors (e.g., memory, developer effort, etc.)
  • 14. HOW DOES ONE MEASURE THE RUNNING TIME OF AN ALGORITHM? Let us look at the empirical (experimental) study. 1. Write a program that implements the algorithm. 2. Run the program with varying data sets in which some are smaller, some are of larger data sets, some would be of some kinds and some would be of different kinds of varying composition. 3. Use a method (like System.currentTimeMillis()) to get an accurate measure of the actual running time.
  • 15. HOW DOES ONE MEASURE THE RUNNING TIME OF AN ALGORITHM? This has certain limitations. 1. First you have to implement the algorithm in which we will be able to determine how good your algorithm is. Implementing it is a huge overhead, where you have to spend considerable amount of time. 2. Experiments can be done only on a limited set of inputs. 3. You can run your experiment on a small set of instances and that might not really indicate the time that your algorithm is taking for other inputs, which you have not considered in your experiment. 4. It is machine dependent.
  • 16. HOW DOES ONE MEASURE THE RUNNING TIME OF AN ALGORITHM? Theoretical or apriori analysis. • Let us assume that we express the running time of a given algorithm as a function of the input size n (i.e., f ( n )) and compare these different functions corresponding to running times. • That is, this methodology aims at associating with each algorithm a function f(n) that characterizes the running time of the algorithm in terms of the input size n. • This kind of comparison is independent of machine time, programming style, etc.
  • 17. WHAT IS RUNNING TIME ANALYSIS? It is the process of determining how processing time increases as the size of the problem (input size) increases. Input size is the number of elements in the input, and depending on the problem type, the input may be of different types.
  • 18. WHAT IS RUNNING TIME ANALYSIS? Typical functions that will be encountered include n and n2 . For example, we will write statements of the type: "Algorithm A runs in time proportional to n," meaning that if we were to perform experiments, we would find that the actual running time of algorithm A on any input of size n never exceeds cn, where c is a constant that depends on the hardware and software environment used in the experiment.
  • 19. WHAT IS RUNNING TIME ANALYSIS? Given two algorithms A and B, where A runs in time proportional to n and B runs intime proportional to n2 , Then, we will prefer A to B, since the function n grows at a smaller rate than the function n2 .
  • 20. WHAT IS RATE OF GROWTH? The rate at which the running time increases as a function of input is called rate of growth.
  • 21. TYPES OF ANALYSIS To analyze the given algorithm, we need to know with which inputs the algorithm takes less time (performing wel1) and with which inputs the algorithm takes a long time. We have already seen that an algorithm can be represented in the form of an expression. That means we represent the algorithm with multiple expressions: one for the case where it takes less time and another for the case where it takes more time.
  • 22. TYPES OF ANALYSIS In general, the first case is called the best case and the second case is called the worst case for the algorithm. • Worst case ○ Defines the input for which the algorithm takes a long time (slowest time to complete). ○ Input is the one for which the algorithm runs the slowest.
  • 23. TYPES OF ANALYSIS In general, the first case is called the best case and the second case is called the worst case for the algorithm. • Best case o Defines the input for which the algorithm takes the least time (fastest time to complete). o Input is the one for which the algorithm runs the fastest.
  • 24. TYPES OF ANALYSIS • Average case ○ Provides a prediction about the running time of the algorithm. ○ Run the algorithm many times, using many different inputs that come from some distribution that generates these inputs, compute the total running time (by adding the individual times), and divide by the number of trials. ○ Assumes that the input is random. Lower Bound <= Average Time <= Upper Bound
  • 25. WHAT IS AN ALGORITHM? Let us consider the problem of preparing an omelette. To prepare an omelette, we follow the steps given below: 1) Get the frying pan. 2) Get the oil. A. Do we have oil? a. If yes, put it in the pan. b. If no, do we want to buy oil? i. If yes, then go out and buy. ii. If no, we can terminate. 3) Turn on the stove, etc...