L2 - Algorithm For Problem Solving
L2 - Algorithm For Problem Solving
(FoCS)
• The sequence of instructions designed in such a way that if the instructions are
executed in the specified sequence, the desired results will be obtained.
• The algorithm should precise and unambiguous in practice and the results should
obtain after a finite number of steps.
2
Characteristics of an algorithm:
• 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.
3
Qualities of a good algorithm: The various factors that can be used to judge
the quality of an algorithm are-
• Time.
• Memory.
• Accuracy.
• Sequence.
• Generalized.
=--=-=-=-=--=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=--=-=-=-=-=--=-=--=-=-=--=-=-=--=-=-=-=-
4
Representation of Algorithms:
• Pseudo Code: Pseudo code is a formal design tools and is very well with the
rules of structured design and programming.
5
Algorithm for adding two integers using normal English language:
Step 1: START
Step 2: Declare three integers num1, num2 & sum
Step 3: Define values of num1 & num2
Step 4: Add values of num1 & num2
Step 5: Store output of step 4 to sum
Step 6: Display the output
Step 7: STOP
=--=-=-=-=--=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=--=-=-=-=-=--=-=--=-=-=--=-=--=-=-=-==-=
❖ Think about pre-defined values and run-time values?
6
Algorithm for finding the maximum of three positive numbers using
normal English language:
Step 1: START
Step 2: Declare three integers num1, num2 & num3
Step 3: Check if A is greater than B and C, A is the largest number
Step 4: Check if B is greater than A and C, B is the largest number
Step 5: Check if C is greater than A and B, C is the largest number
Step 6: STOP
7
Q. write an algorithm for finding the average of three numbers?
Q. Write an algorithm to calculate and print the total number of students selected
in various group, using the following criteria. In a school there are 100 student
appeared for examination. Based upon the student marks who secure greater
than 70% as first class, greater than 60% as second class, and greater than 50% as
third class and remaining are fail.
8
Thank You