0% found this document useful (0 votes)
5 views15 pages

Flowchart Algorithm

Uploaded by

ayushdocs123
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
0% found this document useful (0 votes)
5 views15 pages

Flowchart Algorithm

Uploaded by

ayushdocs123
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

CO101 Programming Fundamentals

- Flowchart and Algorithm -


Flowcharts
• Diagrammatic/pictorial representation of an algorithm.
• Can be used for writing programs and explaining the program to
others.
• Makes use of symbols which when connected together, indicates the
flow of information and processing.

By Priya Singh (Assistant Professor), Dept. of S.E., DTU


Symbols used in Flowchart
1. Flow Lines:
• Arrows represent the direction of flow of control and relationship among
different symbols of flowchart.
• Indicate exact sequence in which instructions are executed.

2. Terminal:
• Oval symbol indicates Start, Stop and Halt in a program’s logic flow.
• A pause/halt is generally used in a program logic under some error
conditions.
• Terminal is the first and last symbols in the flowchart.

By Priya Singh (Assistant Professor), Dept. of S.E., DTU


3. Input/Output:
• Parallelogram depicts input/output.
• Program instructions that take input from input devices and display
output on output devices are indicated with parallelogram in a
flowchart.

4. Processing:
• Box/Rectangle is used to represent arithmetic instructions.
• All arithmetic operations (adding, subtracting, multiplication, etc.) are
indicated by action or process symbol.

By Priya Singh (Assistant Professor), Dept. of S.E., DTU


5. Decision:
Diamond symbol represents a decision point.
Decision based operations (yes/no or true/false) are indicated by
diamond in flowchart.

6. Connectors:
• Represented by a circle.
• If flowchart becomes complex or it spans over multiple pages, it is
useful to use connectors.
By Priya Singh (Assistant Professor), Dept. of S.E., DTU
Advantages of Flowchart
• Flowcharts are better way of communicating the logic of system.
• Flowcharts act as a guide for blueprint during program designed.
• Flowcharts helps in debugging process.
• With the help of flowcharts programs can be easily analyzed.
• It provides better documentation.

By Priya Singh (Assistant Professor), Dept. of S.E., DTU


Disadvantages of Flowchart
• It is difficult to draw flowchart for large and complex programs.
• In this there is no standard to determine the amount of detail.
• Difficult to reproduce the flowcharts.
• It is very difficult to modify the Flowchart.

By Priya Singh (Assistant Professor), Dept. of S.E., DTU


Example Flowchart

Fig1. Find the largest of three numbers


By Priya Singh (Assistant Professor), Dept. of S.E., DTU
More examples:
• Find if a number is prime or not.

By Priya Singh (Assistant Professor), Dept. of S.E., DTU


Algorithm
Definition:
An algorithm is a detailed step-by-step instruction set or formula for
solving a problem or completing a task. In computing, programmers
write algorithms that instruct the computer how to perform a task.

• Used to provide a solution to a particular problem in form of well-


defined steps.
• Can be expressed using natural language, flowcharts, etc.

By Priya Singh (Assistant Professor), Dept. of S.E., DTU


Characteristics of an algorithm
• Unambiguous − Algorithm should be clear and unambiguous.
• 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.

By Priya Singh (Assistant Professor), Dept. of S.E., DTU


Syntax Proposal
Generic imperative language that accepts recursive call
Control structures: indentation delimits the scope:
for all element ∈ Set do
for iterator = lowerbound to upperbound step increment do
while conditional do
do ... while conditional
if conditional then ... else
case element in value :
return value
break
continue
intructions: standard C++ syntax without pointers/reference
function call: standard C++ syntax without pointers/reference
exception: when your algorithm cannot safely terminate and/or respect the output specification

By Priya Singh (Assistant Professor), Dept. of S.E., DTU


Example Algorithm
Problem: Find Greatest Common Divisor (GCD) of two numbers
input: integer a, b
output: greatest common divisor of a and b
if a = 0 then return b
while b >= 0 do
if a > b then
a = a−b else
b = b−a
return a

By Priya Singh (Assistant Professor), Dept. of S.E., DTU


More example:
• Algorithm to check if number is prime

By Priya Singh (Assistant Professor), Dept. of S.E., DTU


Tips for writing algorithm
• Determine the input and output
• Find a correct data structure to represent the problem
• Convert the input to a suitable form, and to preprocess it.
• Try to reduce your problem to a variation of a well-known one
Decide whether you look for a recursive algorithm or an imperative
one, or a mix
• Write the algorithm
• Run all your examples on it, manually, before trying to prove it

By Priya Singh (Assistant Professor), Dept. of S.E., DTU

You might also like