1-Introduction To Algorithms-Flowcharts-Pseudocodes
1-Introduction To Algorithms-Flowcharts-Pseudocodes
to solve a problem.
Easy to debug
Statement 1
Statement 2
Statement 3
:
Flowchart – Selection Control Structure
No Yes
Condition
else- then-
statement(s) statement(s)
Flowchart – Repetition Control Structure
yes Loop
Condition
Statement(s)
no
Flowchart Example – Find Age of a Person
Begin
Calculate
Age = current year – birth date
Display
age
End
Flowchart Example – Bigger of Two Numbers
Flowchart Example – Sum Numbers from 1 to 10
Begin
sum = 0
current_number = 1
NO
current_number <= 10? print sum
YES
sum = sum + current_number End
current_number = current_number + 1
Pseudocode - Introduction
Pseudo is a way of describing an algorithm without using any specific
programming language.
Pseudo codes uses simple English language to express the logic and flow of
the program.
It has no graphical or tabular syntax.
Pseudocode - Advantages
It is very easy to convert a pseudo code into program of actual computer
language.
Pseudo codes are relatively easy to modify in case of change in the logic of
program.
Pseudo codes are relatively less time consuming than a flow chart.
Pseudocode - Disadvantages
No graphical representation is available with pseudo codes.
There are no standard rules to follow in using pseudo codes.
Pseudo code is difficult to understand for beginner.
Pseudocode Example - Fibonacci Sum
Initialize n to fifty
Initialize sum to zero
Initialize f1 and f2 to zero
repeat n times
add f1 and f2, store this value in sum
assign f1’s current value to f2
assign sum’s current value to f1
end loop
Pseudocode Example – Factorial of a Number
Fact find_factorial (n)
FOR value = 1 to n
Factorial = factorial * value
END FOR
DISPLAY value of factorial
END Fact
Difference between Algorithm and Pseudocode
An algorithm is a procedure or set of instructions which are followed for
solving a mathematical problem or accomplishing a task. An algorithm may
or may not be written in a programming language.
Ans: d
MCQ - 2
What is a Flowchart?
a. A way to design a text-based algorithm
d. A scheme of instructions
Ans: Option c
MCQ - 3
What is the difference between a Flowchart and a Pseudocode?
a. Flowchart is a diagram while the pseudocode is written in a programming
language (e.g. Pascal or Java)
Ans: c
Practice Questions
1. Write an algorithm to find the largest of given three numbers.
2. Write an algorithm to find the reversal of a number.
3. Draw a flowchart to find the sum of the digits of a number.
4. Draw a flowchart to check whether a given number is prime or not.
5. Write a pseudocode to find out whether a number is perfect number or not.
6. Write a pseudocode to find out a number is odd or even number.