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

Algorithm

My notes also in my class

Uploaded by

Ali bakari
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Algorithm

My notes also in my class

Uploaded by

Ali bakari
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Algorithm: a step-by-step procedure for solving a problem; programming languages are

essentially a way of expressing algorithms. There are many different algorithms for
almost any problem.
Informally, an algorithm is a collection of instructions which, when performed in a
specific sequence, produce the correct result.
Procedure (Steps Involved in Problem Solving)
A computer cannot solve a problem on its own. One has to provide step by step
solutions of the problem to the computer. In fact, the task of problem solving is not that
of the computer. It is the programmer who has to write down the solution to the
problem in terms of simple operations which the computer can understand and execute.
In order to solve a problem by the computer, one has to pass though certain stages or
steps. They are
1. Understanding the problem
2. Analyzing the problem
3. Developing the solution
4. Coding and implementation.
Pseudo code
An algorithm can be written in English like sentences or in any standard representation
sometimes, algorithm written in English like languages are called Pseudo Code.
It is an abstract form of a program. It does not use any graphical representation. In
pseudo code, the program is represented in terms of words and phrases, but the syntax
of program is not strictly followed.
Example
1. Suppose we want to find the average of three numbers, the algorithm is as follows
Step 1 Read the numbers a, b, c
Step 2 Compute the sum of a, b and c
Step 3 Divide the sum by 3
Step 4 Store the result in variable d
Step 5 Print the value of d
Step 6 End of the program
Algorithms for Simple Problem
Write an algorithm for the following
1. Write an algorithm to calculate the simple interest using the formula.
Simple interest = P*N* R/100. Where P is principle Amount, N is the number of years
and R is the rate of interest.
Step 1: Read the three input quantities’ P, N and R.
Step 2: Calculate simple interest as Simple interest = P* N* R/100
Step 3: Print simple interest.
Step 4: Stop.
2. Area of Triangle: Write an algorithm to find the area of the triangle. Let b, c be the
sides of the triangle ABC and A the included angle between the given sides.
Step 1: Input the given elements of the triangle namely sides b, c and angle between the
sides A.
Step 2: Area = (1/2) *b*C* sin A
Step 3: Output the Area
Step 4: Stop.
Flowchart
A flow chart is a step by step diagrammatic representation of the logic paths to solve a
given problem. Or A flowchart is visual or graphical representation of an algorithm.
Advantages of Flowcharts
1. The flowchart shows the logic of a problem displayed in pictorial fashion which
facilitates easier checking of an algorithm.
2. The Flowchart is good means of communication to other users. It is also a compact
means of recording an algorithm solution to a problem.
3. The flowchart allows the problem solver to break the problem into parts. These parts
can be connected to make master chart.
4. The flowchart is a permanent record of the solution which can be consulted at a later
time.

Symbols used in Flow-Charts


a) Oval: Rectangle with rounded sides is used to indicate either START/STOP of

the program.
b) Input and output indicators: Parallelograms are used to represent input and
output operations. Statements like INPUT, READ and PRINT are represented in
these Parallelograms.

c) Process Indicators: - Rectangle is used to indicate any set of processing operation


such as for storing arithmetic operations.

d) Decision Makers: The diamond is used for indicating the step of decision
making and therefore known as decision box. Decision boxes are used to test the
conditions or ask questions and depending upon the answers, the appropriate
actions are taken by the computer. The decision box symbol is

e) Flow Lines: Flow lines indicate the direction being followed in the flowchart. In
a Flowchart, every line must have an arrow on it to indicate the direction. The
arrows may be in any direction.

Simple Problems using Flow Chart


Draw the Flowchart for the following
1. Draw the Flowchart to find Roots of Quadratic equation ax2 + bx + c = 0. The
coefficients a, b, c are the input data.
2. Draw a flowchart to find out the biggest of the three unequal positive numbers.

3. Write an algorithm to find the largest of three numbers X, Y,Z.


Step 1: Read the numbers X,Y,Z.
Step 2: if (X > Y)
Big = X
else BIG = Y
Step 3 : if (BIG < Z)
Step 4: Big = Z
Step 5: Print the largest number i.e. Big
Step 6: Stop.

You might also like