Você está na página 1de 4

Programming Fundamentals with C Padmashree Desai, Asst.

Prof, CSE Dept

ALGORITHM & FLOWCHARTS

Definition: “An effective procedure for solving a problem in a finite no of steps.

OR
An algorithm is a finite set of well defined instructions or step by step procedure to solve
a given problem.

Programs= Algorithms + Data.

Characteristics of an Algorithm

1) Input : It may accept zero or more inputs

2) Definiteness : Each instruction must be clear, well-defined and precise. There


should not be any ambiguity

3) Effectiveness : Each instruction must be simple and be carried out in a finite


amount of time.

4) Finiteness : Algorithm should have finite sequence of instructions. That is, it


should end after a fixed time. It should not enter into an infinite loop

5) Output :It should produce at least one output.

Algorithm Notation

1) Name of algorithm: Specifies problem to be solved.


2) Step no - Identification tag of an instruction and it is an unsigned position
number.
3) Explanatory comment within the square brackets
4) Termination

Advantages of Algorithm
• Effective communication: Since algorithm is written in English like
language, logic of the problem can be explained easily to others
• Easy and efficient coding : It acts as a blue print during a program
development
• Program debugging : Helps in debugging so that we can identify the
logical errors in a program
• Program maintenance : maintaining the software becomes much easier

1
Programming Fundamentals with C Padmashree Desai, Asst.Prof, CSE Dept

Different patterns of algorithms

1) Sequential : In this different steps occur in a sequence

2) Conditional : In this different steps are executed based on a condition(whether


true/false) . In programming languages, an conditional pattern is
implemented using decision making statements.
3) Iterational : In this a task (one or more steps ) is repeated more than once. In
programming languages, an iterational pattern is implemented using
loops. An iterational construct is also known as “repetitive” construct

Examples

1. Write an algorithm to find sum and average of 3 numbers

Step 1: start
Step 2: read a,b,c [ input 3 numbers]
Step 3: sum ß a + b + c [ find sum]
Step 4: avg ß sum/3 [find average]
Step 5: print sum, avg [output the result]
Step 6: stop

2. Write an Algorithm to find whether an entered integer number is positive or


negative (Decision making type)

Step 1: Start [Beginning of the Algorithm]


Step 2: Read a number A [Input the integer number]
Step 3: If A is greater than 0 [compare A to zero]
print “number as positive”
else
print “number as negative”
Step 4: Stop [End of the Algorithm]

3. Write an algorithm to find largest of two numbers

Step 1: Start [Beginning of the Algorithm]


Step 2: Read a and b [Input two numbers a,b]
Step 3: if a is greater than b [ compare a and b]
print “ a as large”
else
print “b as large” [output the result]
Step 4: Stop

2
Programming Fundamentals with C Padmashree Desai, Asst.Prof, CSE Dept

Disadvantage of algorithm
• Developing algorithm for large and complex problems would be time consuming
and difficult to understand
• Understanding complex logic through algorithms would be difficult

Flowcharts
It is diagrammatic or pictorial representation of an algorithm. In other words “A
flowchart is a diagrammatic representation that illustrates the sequence of operations to be
performed to get the solution of a problem.” The various symbols are used to write different
instructions/operations.

Symbols :

For Diagrams/Block Diagrams refer class notes.

3
Programming Fundamentals with C Padmashree Desai, Asst.Prof, CSE Dept

Advantages
• Flowchart form a good visual aid to represent the logic for the problem solution
• Easy and efficient coding: Writing program is easy
• Program debugging : Helps in debugging so that we can identify the logical
errors in a program
• Program maintenance : maintaining the software becomes much easier

Disadvantages of flowchart
Complex logic: For complicated logic, the flowchart becomes complex and clumsy
Alterations and modifications : If there is change in the logic, the flowchart becomes
to be completely rewritten and requires lot of time.

----------------------------------------------------

Uploaded by Nix

Você também pode gostar