Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
153 views

Algorithm and Flowchart-4

The document discusses algorithms, flowcharts, and pseudocode. It defines each concept, provides examples, and discusses their characteristics and uses. Control structures are also covered, including sequential, selection, and iteration logic.

Uploaded by

Malavika Vipin
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
153 views

Algorithm and Flowchart-4

The document discusses algorithms, flowcharts, and pseudocode. It defines each concept, provides examples, and discusses their characteristics and uses. Control structures are also covered, including sequential, selection, and iteration logic.

Uploaded by

Malavika Vipin
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

ALGORITHM &

FLOWCHART
ARCHANA MENON P
archananirmal1414@gmail.com
Agenda
• Algorithm
• Flowchart
• Pseudocode
• Control structures
• Examples
• References
STEPS IN PROBLEM SOLVING

 First produce a general algorithm.


 Refine the algorithm successively to get step by step detailed
algorithm (t h a t is very close to a computer language.
 Draw flowcharts which show how d a t a flows from source documents
through the computer to final distribution to users.
 Implement the solution by developing a program using any high level
programming language such as C, C++, Java, Python
Algorithm
• An algorithm is a set of commands that must be followed for a computer to perform
calculations or other problem-solving operations.
• An algorithm is a finite set of instructions carried out in a specific order to perform
a particular task.
• It is not the entire program or code; it is simple logic to a problem represented as an
informal description in the form of a flowchart or pseudocode.
Algorithm

Example: Write a n algorithm to find the sum of 2 numbers.

Algorithm
Step 1: Start
Step 2: Read A, B
Step 3: S= A + B
Step 4: Display Sum 'S'
Step 5: Stop
Algorithm

1. Write a n algorithm to find the remainder after division of 2 numbers.


2. Write a n algorithm to convert temperature from Fahrenheit to Celsius.
The formulae is C=(5(F-32))/9.
Algorithm
1. Write a n algorithm to find the remainder after division of 2 numbers.
Step 1: Start.
Step 2: Read A,B.
Step 3: R=A%B.
Step 4: Print R.
Step 5: Stop.
2. Write a n algorithm to convert temperature from Fahrenheit to Celsius.
Step 1: Start.
Step 2: Read F.
Step 3: C=(5(F-32))/9.
Step 4: Print C.
Step 5: Stop.
Characteristics of an algorithm
• Input: An algorithm has some input values. We can pass 0 or some input value to an
algorithm.
• Output: We will get 1 or more output at the end of an algorithm.
• Unambiguity: An algorithm should be unambiguous which means that the instructions in an
algorithm should be clear and simple.
• Finiteness: An algorithm should have finiteness. Here, finiteness means that the algorithm
should contain a limited number of instructions, i.e., the instructions should be countable.
• Effectiveness: An algorithm should be effective as each instruction in an algorithm affects the
overall process.
• Language independent: An algorithm must be language-independent so that the instructions
in an algorithm can be implemented in any of the languages with the same output.
Classification of Algorithms
Flowchart
 Pictorial/ graphical rep resen tatio n of a n algorithm is known a s flow chart.
 It increases the readability of the program.
 It u ses some special symbol to r e p r e s e n t instruction set.
 Information system flowcharts show how d a t a flows from source
documents t h r o u g h t h e computer to final distribution to users.
 Complex programs can be drawn in a simple way using a flowchart.
 It helps team members get an insight into the process and use this knowledge to collect
data, detect problems, develop software, etc.
 A flowchart is a basic step for designing a new process or adding extra features.
 Communication with other people becomes easy by drawing flowcharts and sharing
them.
Flowchart Symbols
Flowchart Symbols
Start/Stop
• This box is of an oval shape which is used to indicate the start or end of the program.
• Every flowchart diagram has an oval shape that depicts the start of an algorithm and another oval shape that
depicts the end of an algorithm.
Input/Output
• This is a parallelogram-shaped box inside which the inputs or outputs are written.
• This basically depicts the information that is entering the system or algorithm and the information that is
leaving the system or algorithm.
Processing
• This is a rectangular box inside which a programmer writes the main course of action of the algorithm or the
main logic of the program.
• This is the crux of the flowchart as the main processing codes is written inside this box.
Flowchart Symbols
Decision
• A rhombus-shaped box represents control statements like if, condition like a > 0, etc are written inside this box.
• There are 2 paths from this one which is “yes” and the other one is “no”.
• Every decision has either yes or no as an option, similarly, this box has these as options.
Connector
• Circular figure is used to depict that the flowchart is in continuation with the further steps.
• This figure comes into use when the space is less and the flowchart is long.
• Any numerical symbol is present inside this circle and that same numerical symbol will be depicted before the
continuation to make the user understand the continuation.
Flow lines
• The arrow line represents the flow of the algorithm or process.
• It represents the direction of the process flow. in all the previous examples, we included arrows in every step to
display the flow of the program.
• Arrow increases the readability of the program.
Pseudocode
• Pseudo code is a methodology that allows the programmer to represent the
implementation of an algorithm.
• It’s the cooked up representation of an algorithm.
• Algorithms are represented with the help of pseudo codes as they can be interpreted by
programmers no matter what their programming background or knowledge is.
• Pseudo code, as the name suggests, is a false code or a representation of code which
can be understood by even a layman with some school level programming knowledge.
• Pseudo code is an implementation of an algorithm in the form of annotations and
informative text written in plain English.
• It has no syntax like any of the programming language and thus can’t be compiled or
interpreted by the computer.
Pseudocode
• Although pseudocode is a syntax-free description of an algorithm, it must provide a full
description of the algorithm’s logic so that moving from pseudocode to implementation is
merely a task of translating each line into code using the syntax of any given programming
language.
• It Improves the readability of any approach. It’s one of the best approaches to start
implementation of an algorithm.
• Acts as a bridge between the program and the algorithm or flowchart. Also works as a rough
documentation, so the program of one developer can be understood easily when a pseudo code
is written out. In industries, the approach of documentation is essential. And that’s where a
pseudo-code proves vital.
• The main goal of a pseudo code is to explain what exactly each line of a program should do,
hence making the code construction phase easier for the programmer.
ALGORITHM, PSEUDOCODE & FLOWCHART
ALGORITHM, PSEUDOCODE & FLOWCHART
Example: Write a p s e u d o c o d e a n d algorithm to determine a
student’s final grade and indicate whether it is passing or failing.
The final grade is calculated as the average of four marks.

Pseudocode:
I n p u t a set of 4 m a r k s
Calculate their average by summing a n d dividing by 4
if average is below 50
P r i n t “FAIL”
else
P r i n t “PASS”
Flowchart:

START
Algorithm:

In p u t Step 1: Input M1,M2,M3,M4


M1,M2,M3,M4 Step 2: GRADE  (M1+M2+M3+M4)/4
4
Step 3: if (GRADE <50) then
Print “FAIL”
GRADE (M1+M2+M3+M4)/4
else
Print “PASS”
N IS Y endif
GRADE<
50

PRINT P RINT

“PAS S” “FAIL”

S TOP
Control Structures
• Control Structures specifies the flow of control in programs.
• It analyzes and chooses in which direction a program flows based on certain
parameters or conditions.
• There are three basic types of logic, or flow of control, known as:
 Sequence logic, or sequential flow
 Selection logic, or conditional flow
 Iteration logic, or repetitive flow
Control Structures
Sequential Logic (Sequential Flow)
• Sequential logic as the name suggests follows a serial or sequential flow in which the flow depends on the
series of instructions given to the computer.
• Unless new instructions are given, the modules are executed in the obvious sequence.
• The sequences may be given, by means of numbered steps explicitly.
• Also, implicitly follows the order in which modules are written.
• Most of the processing, even some complex problems, will generally follow this elementary flow pattern.
• It is a continuous set of actions where one is followed by another till the expected result is
obtained.

Statement 1
Statement 2
Statement 3
...
Statement n
SEQUENTIAL FLOW
Control Structures
Selection Logic (Conditional Flow)
 Selection Logic simply involves a number of conditions or parameters which decides one
out of several written modules. The structures which use these type of logic are known
as Conditional Structures.
 It is used in conditional execution.
 When you take some action based on the results of logical test, that is a selection
construct.

If (condition)
True statements;
Else
False statements;
Endif
CONDITIONAL FLOW
Control Structures
Iteration Logic (Repetitive Flow)
• The Iteration logic employs a loop which involves a repeat statement followed by a module
known as the body of a loop.
• Iteration is repetitive execution of consecutive instructions.
• It is also called looping.
• It may either be conditional or unconditional looping.
REPETITIVE FLOW
Control Structures
EXAMPLE
Wr it ea n a lgorit h m a n d d ra w a flowch a r t to
convert the length in feet to centimeter.

Pseudocode:

Input the length in feet (Lft)


Calculate the length in cm (Lcm) by multiplying Lft with 30
Print length in cm (Lcm)
EXAMPLE
Algorithm Flowchart

Step 1: Input Lft START

Step 2: Lcm = Lft x 30 In p u t


Lft
Step 3: Print Lcm
Lcm  Lft x
30

P rin t
Lcm

S TO P
Flowchart
1. Draw a flowchart to read a number and find the sum with its previous number.
2. Draw a flowchart to check if the given no. is positive or not?
3. Write an algorithm and draw a flowchart to find the biggest no from 2 given
numbers.
4. Write an algorithm and draw a flowchart to find the sum of first N real numbers.
5. Write an algorithm and draw a flowchart to find the sum of first n odd numbers.
6. Write an algorithm and draw a flowchart to find the biggest among 3 numbers.
Flowchart
Solution:4
How to write an algorithm
Refer this mannual to learn how to write algorith and draw flowchart.

• http://www.yspuniversity.ac.in/cic/algorithm-manual.pdf
References
• https://www.slideshare.net/ijs2k8/programming-in-c-70043397
• https://www.slideshare.net/gauravjuneja11/c-language-ppt
THANK YOU

You might also like