100% found this document useful (1 vote)
31 views15 pages

Algorithms and Flowcharts Guide

Uploaded by

azeemibaqi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
31 views15 pages

Algorithms and Flowcharts Guide

Uploaded by

azeemibaqi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

Chapter#2: Algorithm and Flowcharts


ALGORITHM: Algorithm is a step by step method of designing a program
using normal human-language statements. It describes the logic, processing, and
flow of a program. It is like an outline or summary form of the program we will
write.

Example1:
Write an algorithm to compute the distance travelled by train in the
specific time.
Step1: Start the program.
Step2: Read value for SPEED.
Step3: Read value for TIME.
Step4: Set DISTANCE = SPEED * TIME
Step5: Write value of DISTANCE.
Step6: Exit.

Example2:
Write an algorithm to prepare the students’ mark sheet.
Step1: Start.
Step2: Read marks of all subjects.
Step3: Sum all subject’s marks as, Set TOTAL = ENG + MATH+ URDU +
PHY + ISL +COMP
Step4: Calculate percentage as, Set PERCENTAGE =
TOTAL*100/MAX_MARKS
Step5: Write marks of all subjects.
Step6: Write MAX_MARKS, TOTAL, and PERCENTAGE.
Step7: Exit.

PSEUDOCODE:
The prefix pseudo means fake; pseudo-code, therefore literally means fake
code- that is, not the code actually it is entered into the computer. It is considered
as the “First Draft”. In this we can concentrate on the logic of a specific language.

ALGORITHM NOTATION
OR
CERTAIN POINTS AND TERMINOLOGIES USED IN MAKING
ALGORTHM

1. Algorithm Name: Each algorithm must be given a unique name for


identification.
2. Step Number: Each statement of the algorithm must be given a unique
number for identification.

1
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

3. Variable Names: Variable names will use capital letters, as X, Y, SUM,


NUM, etc.
4. Getting Input from the user: “Read” word is used to get input from the
user.
5. Assigning value to a variable: “Set” is used to assign a value to a
variable.
6. Algorithm Termination: “Exit” is used to terminate the algorithm.
7. Comments: “[“ and “]” are used for providing comments or remarks.
8. Displaying Output on the screen: “Write” word is used to display
output on the screen
9. Control Transfer: Use “Got to Step n” to transfer control to step n.

Example:

Write algorithm that takes two numbers and generates output of their
sum:
Step1: Start
Step2: Read X [to get first number]
Step3: Read Y [to get second number]
Step4: Set SUM = X + Y [Adding two numbers]
Step5: Write SUM [displaying sum of two numbers]
Step6: Exit [Terminate of program]

FLOWCHART: A flowchart is a graphical or pictorial representation of any


algorithm which is used in a program.
The flowchart uses arrows to represent the direction of the program flow and
boxes and other shapes to display.
Symbols and Boxes:The American National Standard Institute (ANSI) has
established standard for symbols and boxes that are used in flowcharting. The
shape of the boxes represents the type of activity that is to be performed.
List of the symbols of flowchart:The pictorial symbols that used flowcharts
are defined below:
1. Terminal Symbol
2. Arrow or Flow lines
3. Input/ Output Symbol
4. Process Symbol
5. Decision Symbol
6. On-page Connector Symbol
7. Off-page Connector Symbol
8. Predefined Process Symbol
9. Printed Document Symbol
10. Annotation Symbol

2
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

1. TERMINAL SYBOL:
The terminal symbol is used to indicate the beginning (start), ending (Stop) and
pauses (Halt) in the program’s logic flow.
Oval
Halt Start Stop

2. ARROWS / FLOW LINES:


In flowchart, flowchart symbols are connected to each other with lines called
“flow lines”. These arrows represent the direction of program flow.

3. INPUT/ OUTPUT SYMBOLS:


This symbol is used to denote any type of input data or output information.

Read X Write X
Parallelogram

4. PROCESS SYMBOL:
The process box indicates processing operations in the form of variables and
formulas.
OR
The process box is used for all arithmetic and data transfer operation

Rectangle

5. DECISION SYMBOL:
It is used whenever a decision of a condition is required in the form of yes or
no, true or false, less than or greater than, equal to or not equal to.

If Yes
A=10

No
Diamond

3
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

6. ON-PAGE CONNECTOR SYMBOL:


It is used to branch/ connect flow of program on the same page. An on-page
connector symbol is represented by a circle and a letter or digit is placed within
the circle to indicate the link.

A
Circle

7. OFF – PAGE CONNECTOR SYMBOL:


It is used to connect flow of program from one page to another.

A
Pentagon

8. PREDEFINED PROCESS SYMBOL:


Predefined process symbol indicates the number of processing steps, a sub-
program or sub-routine.

For
A=1 to 10
[FOR,
WHILE,
DO WHILE]
9. PRINTED DOCUMENT SYMBOL:

This symbol indicates printed output of data on paper as hard copy output.

10. ANNOTATION SYMBOL:


This symbol holds additional descriptive, comments, explanatory notes, or
clarifications; connected by dashed line to the symbol. It is used as needed to
aid understanding.

4
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

ADVANTAGES OF FLOWCHART:
 Communication: Flowcharts are better way of communicating the logic of
a system to all concerned or involved.
 Effective analysis: With the help of flowchart, problem can be analyzed in
more effective way therefore reducing cost and wastage of time.
 Proper documentation: Program flowcharts serve as a good program
documentation, which is needed for various purposes, making things more
efficient.
 Efficient Coding: The flowcharts act as a guide or blueprint during the
systems analysis and program development phase.
 Proper Debugging: The flowchart helps in debugging process.
 Efficient Program Maintenance: The maintenance of operating program
becomes easy with the help of flowchart. It helps the programmer to put
efforts more efficiently on that part.

DISADVANTAGES OF FLOWCHART:
•Complex logic: Sometimes, the program logic is quite complicated. In that
case, flowchart becomes complex and clumsy. This will become a pain for the
user, resulting in a waste of time and money trying to correct the problem
•Alterations and Modifications: If alterations are required the flowchart may
require re-drawing completely. This will usually waste valuable time.
•Reproduction: As the flowchart symbols cannot be typed, reproduction of
flowchart becomes a problem.

RULES AND GUIDELINES:


 Keep flowchart as simple as possible.
 Do not include many details; they will appear in the program.
 Words in the flowchart symbols should be common statements and easy
to understand.
 Be consistent in using names and variables in the flowchart.
 Each symbol of a flowchart should probably be connected with each
other by arrows.
 Go from left to right and top to bottom in constructing a flowchart.
 Each connector should have an alphabet or a number in it.
 There must be a statement inside every symbol accordingly.
If more than one flow lines are required to enter in any symbol, then they should
be connected by flow line to flow line.

5
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

CONTROL STRUCTURES
Control Structures control how the program executes.
Three types of control structures:
1. Sequence Logic or Sequential Flow
2. Selection Logic or Conditional Flow
3. Iteration Logic or Repetitive Flow

1. SEQUENCE LOGIC OR SEQUENTIAL FLOW:


It is the straightest forward. One module simply follows another in
sequence.
Example of Algorithm:
Step1: Start
Step2: Read NUM1, NUM2
Step3: Set SUM=NUM1+NUM2
Step4: Write SUM
Step5: Exit
Example of Flowchart:

2. SELECTION LOGIC OR CONDITIONAL FLOW: The selection control


structure set a number of conditions, which lead to a selection one out of several
alternative modules. These structures are called conditional or IF structures.

Examples of IF and IF-ELSE by Flowchart:

6
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

General Flowchart for IF Structure General Flowchart for IF ELSE Structure

3. ITERATION LOGIC OR REPETITIVE FLOW


Iteration is often referred to as loops because the program will keep
repeating the activity until the condition becomes false.
There are three iteration logics:
1. FOR
2. WHILE
3. DO – WHILE

7
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

FOR:
The FOR loop uses an index variable, such as “K” to control the loop.

FOR K =1 to 10
Example of FOR loop:

2. WHILE LOOP…..

While- loop tests condition at the beginning of the loop.

8
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

3. DO – WHILE LOOP….
The Do-WHILE loop tests condition after execution of at least once of
loop.

9
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

SOME EXAMPLES OF ALGORITHM AND FLOWCHART

Example 1: Write an algorithm which reads and write your name, age,
height, and gender.

ALGORITHM:

Step1: Start

Step2: Read GENDER, NAME, HEIGHT, and AGE.

Step6: Write GENDER, NAME, HEIGHT, and AGE

Step7: Exit

FLOWCHART:

10
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

Example 2: Write an algorithm for printing your name ten times using FOR
Statement.

ALGORITHM:

Step1: Start
Step2: FOR A=1 to 10
a) Write “Name”
b) A = A+1 [END OF FOR LOOP]
Step3: Exit

FLOWCHART:

11
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

Example 3: Write an algorithm and draw a flowchart to calculate square


and cube of first natural numbers.

ALGORITHM:

Step1: Start
Step2: FOR A = 1 to 10 by 1
a) Write A, A^2, A^3
b) Set A = A + 1 [END OF FOR LOOP]
Step3: Exit.

FLOWCHART:

12
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

Example 4: Write an algorithm and draw a flowchart to generate a table of


inputted number.

ALGORITHM:

Step1: Start
Step2: Read NUM
Step3: FOR A = 1 to 10 by 1
a) Write NUM; “*” A; “=” NUM*A
b) Set A = A + 1 [END OF FOR LOOP]
Step4: Exit

FLOWCHART:

13
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

Questions
1. Define the term Algorithm with the help of examples. (Short)
2. Define the term Pseudocode. (Short)
3. What is an Algorithm? Write the names of Algorithm Notations. (Short)
4. Define algorithm and also define all the algorithm notations. (Long)
5. Define Flowchart. List all the symbols of a flowchart. (Short)
6. What is a Flowchart? List and also describe all the symbols of Flowchart.
(Long)
7. Describe all the Categories of flowchart. (Long)
8. Write the advantages and disadvantages of a flowchart (Short)
9. Describe the rules and guidelines while designing the flowchart. (Short)
[Link] are the control structures? And name the types control structures.
(Short)
[Link] the control structures with the examples of Algorithm and
Flowchart. (Long)

14
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

MCQ’s (Multiple Choice Questions)


1. A pictorial representation of a problem is called
(a) a flowchart (b) an algorithm
(c) a pseudo code (d) None of the above
2. What do you call the step-by-step solution to a programming
problem?
(a) recipe (b) structure chart
(c) syntax (d) algorithm
3. What does the symbol in a flowchart represent?
(a) decision (b) process
(c) start/ stop (d) predefined process
4. What does the symbol in a flowchart represent?
(a) process (b) terminal
(c) input/output procedure (d) predefined process
5. Which of the following control structures use DO-WHILE?
(a) sequence (b) selection
(c) iteration (d) None of the above
6. In flowchart, this symbol represents start or finish of program:
(a) Diamond (b) Oval
(c) Rectangle (d) Square
7. The ____________ symbol in a flowchart represents process.
(a) decision (b) process
(c) start/ stop (d) predefined process
8. At least ______ arrows leave the diamond in a flowchart.
(a) one (b) two
(c) three (d) none of them
9. _______ word is used to get input from the user.
(a) Write (b) Read
(c) Scan (d) both b and c
10. In a flowchart, symbols are connected with
(a) arrows (b) flow lines
(c) decision box (d) both a and b

15

You might also like