SlideShare a Scribd company logo
CSC 313 : object oriented
programming
Algorithm and control structures
Miss Jessica Egwom
Topic content
• The concept of an algorithm
• Properties of an algorithm
• Problem-solving strategies
• Implementation strategies
What is an algorithm
 An algorithm is a procedure used for solving a problem or performing
a computation.
• Algorithms act as an exact list of instructions that conduct specified
actions step by step in either hardware- or software-based routines.
• They are a crucial part of computational thinking and problem-solving
in many areas of life, as we use algorithms to accurately execute
tasks.
• An algorithm is simply a set of steps used to complete a specific task.
They're the building blocks for programming
What is algorithm …
A computer algorithm is a computational procedure that takes in a set
of finite inputs and transforms it into output by applying some math &
logic.
• it is simple logic to a problem represented as an informal description
in the form of a flowchart or pseudocode
problem solving and algorithm development
How write an algorithm
• Problem definition – What is to be done?
• Data collection – What do we have to solve the problem? Or inputs.
• Data processing – Understanding what we have or transforming them
into a usable form.
• A logical approach – Employing the collected & created data against
logic to solve.
• Solution – Present the solution in the way you want in a GUI or a
terminal or a diagram or a chart.
• Analyze the problem.
• Restate the problem.
• Write out examples of input and output.
• Break the problem into its component parts.
• Outline a solution in psuedo-code.
How to Design an Algorithm?
• In order to write an algorithm, the following things are needed as a pre-
requisite:
• The problem that is to be solved by this algorithm i.e. clear problem
definition.
• The constraints of the problem must be considered while solving the
problem.
• The input to be taken to solve the problem.
• The output to be expected when the problem is solved.
• The solution to this problem, is within the given constraints.
• Then the algorithm is written with the help of the above parameters such
that it solves the problem
Properties of Algorithm
An algorithm is an effective, efficient method that can use to express the
solution to any problem within a finite amount of space. It is also a well-
defined formal language. There are five properties of an algorithm as given
below.
• It should terminate after a finite time.
• It should produce at least one output.
• It should take zero or more input.
• It should be deterministic means giving the same output for the same input
case.
• Every step in the algorithm must be effective i.e. every step should do
some work
Characteristics of an algorithm
Characteristics of an algorithm
• Input: An algorithm requires some input values. An algorithm can be given
a value other than 0 as input.
• Output: At the end of an algorithm, you will have one or more outcomes.
• Unambiguity: A perfect algorithm is defined as unambiguous, which means
that its instructions should be clear and straightforward.
• Finiteness: An algorithm must be finite. Finiteness in this context means
that the algorithm should have a limited number of instructions, i.e., the
instructions should be countable.
• Effectiveness: Because each instruction in an algorithm affects the overall
process, it should be adequate.
• Language independence: An algorithm must be language-independent,
which means that its instructions can be implemented in any language and
produce the same results.
Factors of an Algorithm
• Modularity: This feature was perfectly designed for the algorithm if
you are given a problem and break it down into small-small modules
or small-small steps, which is a basic definition of an algorithm.
• Correctness: An algorithm's correctness is defined as when the given
inputs produce the desired output, indicating that the algorithm was
designed correctly. An algorithm's analysis has been completed
correctly.
• Maintainability: It means that the algorithm should be designed in a
straightforward, structured way so that when you redefine the
algorithm, no significant changes are made to the algorithm
Factors of an Algorithm II
• Functionality: It takes into account various logical steps to solve a
real-world problem.
• Robustness: Robustness refers to an algorithm's ability to define your
problem clearly.
• User-friendly: If the algorithm is difficult to understand, the designer
will not explain it to the programmer.
• Simplicity: If an algorithm is simple, it is simple to understand.
• Extensibility: Your algorithm should be extensible if another algorithm
designer or programmer wants to use it.
Approaches of an Algorithm (Problem-solving
strategies)
• Brute Force Algorithm
• This algorithm uses the general logic structure to design an algorithm. It is
also called an exhaustive search algorithm because it exhausts all
possibilities to provide the required solution. There are two kinds of such
algorithms:
• Optimizing: Finding all possible solutions to a problem and then selecting
the best one, will terminate if the best solution is known.
• Sacrificing: It will stop as soon as the best solution is found.
• Divide and Conquer
• This is a straightforward algorithm implementation. It enables you to
create an algorithm in a step-by-step fashion. It deconstructs the algorithm
to solve the problem in various ways. It allows you to divide the problem
into different methods, generating valid output for valid input. This
accurate output is forwarded to another function.
• Greedy Algorithm
• This is an algorithm paradigm that makes the best choice possible on
each iteration in the hopes of choosing the best solution. It is simple
to set up and has a shorter execution time. However, there are very
few cases where it is the best solution.
• Branch and Bound Algorithm
• Only integer programming problems can be solved using the branch
and bound algorithm. This method divides all feasible solution sets
into smaller subsets. These subsets are then evaluated further to find
the best solution.
• Randomized Algorithm
• As with a standard algorithm, you have predefined input and output.
Deterministic algorithms have a defined set of information and
required results and follow some described steps. They are more
efficient than non-deterministic algorithms.
• Backtracking
• It is an algorithmic procedure that recursively and discards the
solution if it does not satisfy the constraints of the problem.
Types of Algorithms
• There are two types of algorithms:
• Search Algorithm
• Sort Algorithm
Search Algorithm
• The searching algorithm is of two types:
• Linear Search
• Linear search is a simple algorithm that begins searching for an element or
a value at the beginning of an array and continues until the required
element is not found. It compares the element to be searched with all the
elements in an array; if a match is found, the element index is returned;
otherwise, -1 is returned. This algorithm can be applied to an unsorted list.
• Binary Search
• A binary algorithm is the most basic algorithm, and it searches for
elements very quickly. It is used to find an element in a sorted list. To
implement the binary algorithm, the elements must be stored in
sequential order or sorted. If the elements are stored randomly,
binary search cannot be implemented.
• Sort Algorithm
• Sorting algorithms rearrange elements in an array or a given data
structure in ascending or descending order. The comparison operator
decides the new order of the elements.
• Step 1: Fulfilling the pre-requisites (implementation strategies)
As discussed above, in order to write an algorithm, its pre-requisites
must be fulfilled.
• The problem that is to be solved by this algorithm: Add 3 numbers and print
their sum.
• The constraints of the problem that must be considered while solving the
problem: The numbers must contain only digits and no other characters.
• The input to be taken to solve the problem: The three numbers to be added.
• The output to be expected when the problem is solved: The sum of the
three numbers taken as the input i.e. a single integer value.
• The solution to this problem, in the given constraints: The solution consists
of adding the 3 numbers. It can be done with the help of ‘+’ operator, or bit-
wise, or any other method.
Designing the algorithm
• Step 2: Designing the algorithm
Now let’s design the algorithm with the help of the above pre-
requisites:
Algorithm to add 3 numbers and print their sum:
• START
• Declare 3 integer variables num1, num2 and num3.
• Take the three numbers, to be added, as inputs in variables num1, num2, and
num3 respectively.
• Declare an integer variable sum to store the resultant sum of the 3 numbers.
• Add the 3 numbers and store the result in the variable sum.
• Print the value of the variable sum
• END
problem solving and algorithm development
problem solving and algorithm development
problem solving and algorithm development
problem solving and algorithm development
Control structure
Ad

Recommended

Chapter-1-Introduction-to-Aglorithms.pdf
Chapter-1-Introduction-to-Aglorithms.pdf
Shanmuganathan C
 
Algorithm in data structure bca .pptx
Algorithm in data structure bca .pptx
SukhBanger
 
DAA INTRO.pdf of design analysis algorithms
DAA INTRO.pdf of design analysis algorithms
VaishnaviDappu
 
Introduction to analysis algorithm in computer Science
Introduction to analysis algorithm in computer Science
tissandavid
 
introduction to analysis of algorithm in computer science
introduction to analysis of algorithm in computer science
tissandavid
 
Analysis and Design of Algorithms
Analysis and Design of Algorithms
Bulbul Agrawal
 
daa18d8d-d333-4398-94dd-a46802d88d79.pptx
daa18d8d-d333-4398-94dd-a46802d88d79.pptx
yvtinsane
 
ALGO VS FLOW.pptx
ALGO VS FLOW.pptx
NagendraK18
 
Algorithm - A set of rules for solving operations
Algorithm - A set of rules for solving operations
Kumari99
 
CH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptx
satvikkushwaha1
 
Types of Algorithms.ppt
Types of Algorithms.ppt
ALIZAIB KHAN
 
Algo_Lecture01.pptx
Algo_Lecture01.pptx
ShaistaRiaz4
 
Binary to hexadecimal algorithmic old.pptx
Binary to hexadecimal algorithmic old.pptx
bulbul931579
 
Chapter1.1 Introduction to design and analysis of algorithm.ppt
Chapter1.1 Introduction to design and analysis of algorithm.ppt
Tekle12
 
Chapter1.1 Introduction.ppt
Chapter1.1 Introduction.ppt
Tekle12
 
CSE-113 UNIT-1 with the basic knowledge of the computer science.pptx
CSE-113 UNIT-1 with the basic knowledge of the computer science.pptx
ghardik4002
 
Design and Analysis of Algorithm for II year Computer science and Engineering...
Design and Analysis of Algorithm for II year Computer science and Engineering...
Kalpana Devi M
 
2. Introduction to Algorithm.pptx
2. Introduction to Algorithm.pptx
RahikAhmed1
 
Algorithm.pptx
Algorithm.pptx
DipayanSadhu1
 
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
dinesh620610
 
Algorithm and C code related to data structure
Algorithm and C code related to data structure
Self-Employed
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Algorithm Analysis.pdf
Algorithm Analysis.pdf
NayanChandak1
 
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
AIET
 
DAA 1 ppt.pptx
DAA 1 ppt.pptx
RAJESH S
 
DAA ppt.pptx
DAA ppt.pptx
RAJESH S
 
Unit 1 Introduction Part 3.pptx
Unit 1 Introduction Part 3.pptx
NishaRohit6
 
Introduction to data structure
Introduction to data structure
A. S. M. Shafi
 
Pushkar camel fest at college campus placement
Pushkar camel fest at college campus placement
nandanitiwari82528
 
Citizen Science and Science communication
Citizen Science and Science communication
tarhanhatice0101
 

More Related Content

Similar to problem solving and algorithm development (20)

Algorithm - A set of rules for solving operations
Algorithm - A set of rules for solving operations
Kumari99
 
CH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptx
satvikkushwaha1
 
Types of Algorithms.ppt
Types of Algorithms.ppt
ALIZAIB KHAN
 
Algo_Lecture01.pptx
Algo_Lecture01.pptx
ShaistaRiaz4
 
Binary to hexadecimal algorithmic old.pptx
Binary to hexadecimal algorithmic old.pptx
bulbul931579
 
Chapter1.1 Introduction to design and analysis of algorithm.ppt
Chapter1.1 Introduction to design and analysis of algorithm.ppt
Tekle12
 
Chapter1.1 Introduction.ppt
Chapter1.1 Introduction.ppt
Tekle12
 
CSE-113 UNIT-1 with the basic knowledge of the computer science.pptx
CSE-113 UNIT-1 with the basic knowledge of the computer science.pptx
ghardik4002
 
Design and Analysis of Algorithm for II year Computer science and Engineering...
Design and Analysis of Algorithm for II year Computer science and Engineering...
Kalpana Devi M
 
2. Introduction to Algorithm.pptx
2. Introduction to Algorithm.pptx
RahikAhmed1
 
Algorithm.pptx
Algorithm.pptx
DipayanSadhu1
 
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
dinesh620610
 
Algorithm and C code related to data structure
Algorithm and C code related to data structure
Self-Employed
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Algorithm Analysis.pdf
Algorithm Analysis.pdf
NayanChandak1
 
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
AIET
 
DAA 1 ppt.pptx
DAA 1 ppt.pptx
RAJESH S
 
DAA ppt.pptx
DAA ppt.pptx
RAJESH S
 
Unit 1 Introduction Part 3.pptx
Unit 1 Introduction Part 3.pptx
NishaRohit6
 
Introduction to data structure
Introduction to data structure
A. S. M. Shafi
 
Algorithm - A set of rules for solving operations
Algorithm - A set of rules for solving operations
Kumari99
 
CH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptx
satvikkushwaha1
 
Types of Algorithms.ppt
Types of Algorithms.ppt
ALIZAIB KHAN
 
Algo_Lecture01.pptx
Algo_Lecture01.pptx
ShaistaRiaz4
 
Binary to hexadecimal algorithmic old.pptx
Binary to hexadecimal algorithmic old.pptx
bulbul931579
 
Chapter1.1 Introduction to design and analysis of algorithm.ppt
Chapter1.1 Introduction to design and analysis of algorithm.ppt
Tekle12
 
Chapter1.1 Introduction.ppt
Chapter1.1 Introduction.ppt
Tekle12
 
CSE-113 UNIT-1 with the basic knowledge of the computer science.pptx
CSE-113 UNIT-1 with the basic knowledge of the computer science.pptx
ghardik4002
 
Design and Analysis of Algorithm for II year Computer science and Engineering...
Design and Analysis of Algorithm for II year Computer science and Engineering...
Kalpana Devi M
 
2. Introduction to Algorithm.pptx
2. Introduction to Algorithm.pptx
RahikAhmed1
 
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
dinesh620610
 
Algorithm and C code related to data structure
Algorithm and C code related to data structure
Self-Employed
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Algorithm Analysis.pdf
Algorithm Analysis.pdf
NayanChandak1
 
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
AIET
 
DAA 1 ppt.pptx
DAA 1 ppt.pptx
RAJESH S
 
DAA ppt.pptx
DAA ppt.pptx
RAJESH S
 
Unit 1 Introduction Part 3.pptx
Unit 1 Introduction Part 3.pptx
NishaRohit6
 
Introduction to data structure
Introduction to data structure
A. S. M. Shafi
 

Recently uploaded (20)

Pushkar camel fest at college campus placement
Pushkar camel fest at college campus placement
nandanitiwari82528
 
Citizen Science and Science communication
Citizen Science and Science communication
tarhanhatice0101
 
Introduction to solar panel and about solar on grid
Introduction to solar panel and about solar on grid
vardhanreddypuli06
 
Pneumonia Presentation for CPG Review and Mastery
Pneumonia Presentation for CPG Review and Mastery
JayricDepalobos
 
Abzymes mimickers in catalytic reactions at nanoscales
Abzymes mimickers in catalytic reactions at nanoscales
OrchideaMariaLecian
 
Molecular biology and pellet weight marked
Molecular biology and pellet weight marked
nandanitiwari82528
 
BP_MXene_Project_Proposal_Presentation.pptx
BP_MXene_Project_Proposal_Presentation.pptx
RoccoHunter8
 
SCIENCE-G7-Quarter1-Week1-Day5.matatagptx
SCIENCE-G7-Quarter1-Week1-Day5.matatagptx
Pyumpyum
 
Cloud Collaboration Market Challenges, Drivers, Trends, and Forecast by 2031
Cloud Collaboration Market Challenges, Drivers, Trends, and Forecast by 2031
moresonali406
 
Antibiotic and herbicide Resistance Genes
Antibiotic and herbicide Resistance Genes
AkshitRawat20
 
Cryptocurrency and cyber crime Presentation
Cryptocurrency and cyber crime Presentation
IqraRehaman
 
Morphological and biochemical characterization in Rice
Morphological and biochemical characterization in Rice
AbhishekChauhan911496
 
Gene Expression & Regulation in Eukaryotes.pptx
Gene Expression & Regulation in Eukaryotes.pptx
Muhammad Hassan Asadi
 
Agriculture fruit production for crrot candy amala candy banana sudi stem borrer
Agriculture fruit production for crrot candy amala candy banana sudi stem borrer
kanopatel8840
 
Class 12 biology project on the topic cancer
Class 12 biology project on the topic cancer
crazycompetitor000
 
CULTIVATION - HARVESTING - PROCESSING - STORAGE -.pdf
CULTIVATION - HARVESTING - PROCESSING - STORAGE -.pdf
Nistarini College, Purulia (W.B) India
 
Driving sustainability: AI adoption framework for the fast fashion industry
Driving sustainability: AI adoption framework for the fast fashion industry
Selcen Ozturkcan
 
To study the factors on which the self-inductance of the coil depends by obse...
To study the factors on which the self-inductance of the coil depends by obse...
crazycompetitor000
 
the presentation on downstream processing (DSP).pptx
the presentation on downstream processing (DSP).pptx
aanchalm373
 
Deconstruction Analysis The adventure of devil's foot by Sir Arthur Conan Doyle
Deconstruction Analysis The adventure of devil's foot by Sir Arthur Conan Doyle
staverechard
 
Pushkar camel fest at college campus placement
Pushkar camel fest at college campus placement
nandanitiwari82528
 
Citizen Science and Science communication
Citizen Science and Science communication
tarhanhatice0101
 
Introduction to solar panel and about solar on grid
Introduction to solar panel and about solar on grid
vardhanreddypuli06
 
Pneumonia Presentation for CPG Review and Mastery
Pneumonia Presentation for CPG Review and Mastery
JayricDepalobos
 
Abzymes mimickers in catalytic reactions at nanoscales
Abzymes mimickers in catalytic reactions at nanoscales
OrchideaMariaLecian
 
Molecular biology and pellet weight marked
Molecular biology and pellet weight marked
nandanitiwari82528
 
BP_MXene_Project_Proposal_Presentation.pptx
BP_MXene_Project_Proposal_Presentation.pptx
RoccoHunter8
 
SCIENCE-G7-Quarter1-Week1-Day5.matatagptx
SCIENCE-G7-Quarter1-Week1-Day5.matatagptx
Pyumpyum
 
Cloud Collaboration Market Challenges, Drivers, Trends, and Forecast by 2031
Cloud Collaboration Market Challenges, Drivers, Trends, and Forecast by 2031
moresonali406
 
Antibiotic and herbicide Resistance Genes
Antibiotic and herbicide Resistance Genes
AkshitRawat20
 
Cryptocurrency and cyber crime Presentation
Cryptocurrency and cyber crime Presentation
IqraRehaman
 
Morphological and biochemical characterization in Rice
Morphological and biochemical characterization in Rice
AbhishekChauhan911496
 
Gene Expression & Regulation in Eukaryotes.pptx
Gene Expression & Regulation in Eukaryotes.pptx
Muhammad Hassan Asadi
 
Agriculture fruit production for crrot candy amala candy banana sudi stem borrer
Agriculture fruit production for crrot candy amala candy banana sudi stem borrer
kanopatel8840
 
Class 12 biology project on the topic cancer
Class 12 biology project on the topic cancer
crazycompetitor000
 
Driving sustainability: AI adoption framework for the fast fashion industry
Driving sustainability: AI adoption framework for the fast fashion industry
Selcen Ozturkcan
 
To study the factors on which the self-inductance of the coil depends by obse...
To study the factors on which the self-inductance of the coil depends by obse...
crazycompetitor000
 
the presentation on downstream processing (DSP).pptx
the presentation on downstream processing (DSP).pptx
aanchalm373
 
Deconstruction Analysis The adventure of devil's foot by Sir Arthur Conan Doyle
Deconstruction Analysis The adventure of devil's foot by Sir Arthur Conan Doyle
staverechard
 
Ad

problem solving and algorithm development

  • 1. CSC 313 : object oriented programming Algorithm and control structures Miss Jessica Egwom
  • 2. Topic content • The concept of an algorithm • Properties of an algorithm • Problem-solving strategies • Implementation strategies
  • 3. What is an algorithm  An algorithm is a procedure used for solving a problem or performing a computation. • Algorithms act as an exact list of instructions that conduct specified actions step by step in either hardware- or software-based routines. • They are a crucial part of computational thinking and problem-solving in many areas of life, as we use algorithms to accurately execute tasks. • An algorithm is simply a set of steps used to complete a specific task. They're the building blocks for programming
  • 4. What is algorithm … A computer algorithm is a computational procedure that takes in a set of finite inputs and transforms it into output by applying some math & logic. • it is simple logic to a problem represented as an informal description in the form of a flowchart or pseudocode
  • 6. How write an algorithm • Problem definition – What is to be done? • Data collection – What do we have to solve the problem? Or inputs. • Data processing – Understanding what we have or transforming them into a usable form. • A logical approach – Employing the collected & created data against logic to solve. • Solution – Present the solution in the way you want in a GUI or a terminal or a diagram or a chart.
  • 7. • Analyze the problem. • Restate the problem. • Write out examples of input and output. • Break the problem into its component parts. • Outline a solution in psuedo-code.
  • 8. How to Design an Algorithm? • In order to write an algorithm, the following things are needed as a pre- requisite: • The problem that is to be solved by this algorithm i.e. clear problem definition. • The constraints of the problem must be considered while solving the problem. • The input to be taken to solve the problem. • The output to be expected when the problem is solved. • The solution to this problem, is within the given constraints. • Then the algorithm is written with the help of the above parameters such that it solves the problem
  • 9. Properties of Algorithm An algorithm is an effective, efficient method that can use to express the solution to any problem within a finite amount of space. It is also a well- defined formal language. There are five properties of an algorithm as given below. • It should terminate after a finite time. • It should produce at least one output. • It should take zero or more input. • It should be deterministic means giving the same output for the same input case. • Every step in the algorithm must be effective i.e. every step should do some work
  • 11. Characteristics of an algorithm • Input: An algorithm requires some input values. An algorithm can be given a value other than 0 as input. • Output: At the end of an algorithm, you will have one or more outcomes. • Unambiguity: A perfect algorithm is defined as unambiguous, which means that its instructions should be clear and straightforward. • Finiteness: An algorithm must be finite. Finiteness in this context means that the algorithm should have a limited number of instructions, i.e., the instructions should be countable. • Effectiveness: Because each instruction in an algorithm affects the overall process, it should be adequate. • Language independence: An algorithm must be language-independent, which means that its instructions can be implemented in any language and produce the same results.
  • 12. Factors of an Algorithm • Modularity: This feature was perfectly designed for the algorithm if you are given a problem and break it down into small-small modules or small-small steps, which is a basic definition of an algorithm. • Correctness: An algorithm's correctness is defined as when the given inputs produce the desired output, indicating that the algorithm was designed correctly. An algorithm's analysis has been completed correctly. • Maintainability: It means that the algorithm should be designed in a straightforward, structured way so that when you redefine the algorithm, no significant changes are made to the algorithm
  • 13. Factors of an Algorithm II • Functionality: It takes into account various logical steps to solve a real-world problem. • Robustness: Robustness refers to an algorithm's ability to define your problem clearly. • User-friendly: If the algorithm is difficult to understand, the designer will not explain it to the programmer. • Simplicity: If an algorithm is simple, it is simple to understand. • Extensibility: Your algorithm should be extensible if another algorithm designer or programmer wants to use it.
  • 14. Approaches of an Algorithm (Problem-solving strategies) • Brute Force Algorithm • This algorithm uses the general logic structure to design an algorithm. It is also called an exhaustive search algorithm because it exhausts all possibilities to provide the required solution. There are two kinds of such algorithms: • Optimizing: Finding all possible solutions to a problem and then selecting the best one, will terminate if the best solution is known. • Sacrificing: It will stop as soon as the best solution is found. • Divide and Conquer • This is a straightforward algorithm implementation. It enables you to create an algorithm in a step-by-step fashion. It deconstructs the algorithm to solve the problem in various ways. It allows you to divide the problem into different methods, generating valid output for valid input. This accurate output is forwarded to another function.
  • 15. • Greedy Algorithm • This is an algorithm paradigm that makes the best choice possible on each iteration in the hopes of choosing the best solution. It is simple to set up and has a shorter execution time. However, there are very few cases where it is the best solution. • Branch and Bound Algorithm • Only integer programming problems can be solved using the branch and bound algorithm. This method divides all feasible solution sets into smaller subsets. These subsets are then evaluated further to find the best solution.
  • 16. • Randomized Algorithm • As with a standard algorithm, you have predefined input and output. Deterministic algorithms have a defined set of information and required results and follow some described steps. They are more efficient than non-deterministic algorithms. • Backtracking • It is an algorithmic procedure that recursively and discards the solution if it does not satisfy the constraints of the problem.
  • 17. Types of Algorithms • There are two types of algorithms: • Search Algorithm • Sort Algorithm Search Algorithm • The searching algorithm is of two types: • Linear Search • Linear search is a simple algorithm that begins searching for an element or a value at the beginning of an array and continues until the required element is not found. It compares the element to be searched with all the elements in an array; if a match is found, the element index is returned; otherwise, -1 is returned. This algorithm can be applied to an unsorted list.
  • 18. • Binary Search • A binary algorithm is the most basic algorithm, and it searches for elements very quickly. It is used to find an element in a sorted list. To implement the binary algorithm, the elements must be stored in sequential order or sorted. If the elements are stored randomly, binary search cannot be implemented. • Sort Algorithm • Sorting algorithms rearrange elements in an array or a given data structure in ascending or descending order. The comparison operator decides the new order of the elements.
  • 19. • Step 1: Fulfilling the pre-requisites (implementation strategies) As discussed above, in order to write an algorithm, its pre-requisites must be fulfilled. • The problem that is to be solved by this algorithm: Add 3 numbers and print their sum. • The constraints of the problem that must be considered while solving the problem: The numbers must contain only digits and no other characters. • The input to be taken to solve the problem: The three numbers to be added. • The output to be expected when the problem is solved: The sum of the three numbers taken as the input i.e. a single integer value. • The solution to this problem, in the given constraints: The solution consists of adding the 3 numbers. It can be done with the help of ‘+’ operator, or bit- wise, or any other method.
  • 20. Designing the algorithm • Step 2: Designing the algorithm Now let’s design the algorithm with the help of the above pre- requisites: Algorithm to add 3 numbers and print their sum: • START • Declare 3 integer variables num1, num2 and num3. • Take the three numbers, to be added, as inputs in variables num1, num2, and num3 respectively. • Declare an integer variable sum to store the resultant sum of the 3 numbers. • Add the 3 numbers and store the result in the variable sum. • Print the value of the variable sum • END