Professional Documents
Culture Documents
LESSON 1
ALGORITHM
Algorithm Defined
B. Properties of Algorithm
1. Finiteness - there is an exact number of steps to be taken and has an end.
2. Absence of Ambiguity - means that every instruction is precisely described and
clearly specified.
3. Sequence of Execution instructions are performed from top to bottom.
4. Input and Output - defined the unknowns of the problem is specified and with the
expected outcome.
5. Effectiveness- the solution prescribed is guaranteed to give a correct answer and that
the specified process is faithfully carried out.
6. Scope Definition - applies to a specific problem or class of problem.
D. Examples
1. Write an algorithm to determine a students final grade and indicate whether it is
passing or failing. The final grade is calculated as the average of four marks.
Pseudocode:
Input a set of 4 marks
Calculate their average by summing and dividing by 4
if average is below 50
Print FAIL
else
Print PASS
Detailed Algorithm
Step 1: Input M1,M2,M3,M4
Step 2:
GRADE (M1+M2+M3+M4)/4
Step 3:
Print FAIL
else
Print PASS
endif
LESSON 2
FLOWCHART
Flowchart Defined
B. Flowchart Symbols
Only a few symbols are needed to indicate the necessary operations in a flowchart.
These symbols have been standardized by the American National Standards Institute
(ANSI).
Processing
Flow lines
Flow lines with arrowheads are used to indicate the flow of operation, that is, the exact
sequence in which the instructions are to be executed. The normal flow of flowchart is
from top to bottom and left to right. Arrowheads are required only when the normal top
to bottom flow is not to be followed.
Decision
The decision symbol is used in a flowchart to indicate a point at which a decision has to
be made and a branch to one of two or more alternative points is possible.
Connector
If a flowchart becomes very long, the flow lines start crisscrossing at many places that
causes confusion and reduces the clarity of the flowchart. Moreover, there are instances
when a flowchart becomes too long to fit in a single page and the use of flow lines
becomes impossible. Thus, whenever a flowchart becomes too complex that the
number and direction of flow lines is confusing or it spreads over more than one page, it
is useful to utilize the connector symbol as a substitute for flow lines. This symbol
represents an entry from, or an exit to another part of the flowchart. A connector symbol
is represented by a circle and a letter or digit is placed within the circle to indicate the
link. A pair of identically labeled connector symbols is commonly used to indicate a
continued flow when the use of a line is confusing.
Name
Symbols
Representation
Terminator (terminal)
Preparation
Data (input/output)
Process
Computational steps or
processing function of a
program
Decision
On-page Connector
Connector or joining of
two parts of a program
Off-page Connector
Flow lines
C. Flowcharting Guidelines
The following are some guidelines in flowcharting:
The flowchart should be clear, neat and easy to follow. There should not be any
room for ambiguity in understanding the flowchart.
The usual direction of the flow of a procedure or system is from left to right or top
to bottom.
Only one flow line should come out from a process symbol.
or
Only one flow line should enter a decision symbol, but two or three flow lines,
one for each possible answer, should leave the decision symbol.
It is useful to test the validity of the flowchart by passing through it with a simple
test data.
Effective analysis: With the help of flowchart, problem can be analyzed in more
effective way.
Efficient Coding: The flowcharts act as a guide or blueprint during the systems
analysis and program development phase.
Complex logic: Sometimes, the program logic is quite complicated. In that case,
flowchart becomes complex and clumsy.
Alterations and Modifications: If alterations are required the flowchart may require
re-drawing completely.
The essentials of what is done can easily be lost in the technical details of how it
is done.
Examples:
1. Draw a flowchart that will accept and display a number. Write its equivalent algorithm.
Algorithm
Algorithm
Algorithm
2. Selection - Once the condition is evaluated, the control flows into one of two paths.
Once the conditional execution is finished, the flows rejoin before leaving the structure.
As an alternative, the "Question" could be replaced with a Boolean expression and the
branches labelled "TRUE" and "FALSE".
Meaning
Addition
Subtraction
Multiplication
Division
B. Relational Operators
Operators
Meaning
Equal
>
Greater than
<
Less than
<>
Not equal
>
<
C. Logical Operators
Operator
Meaning
&&
AND
II
OR
NOT
Examples:
Algorithm
Step 1. Read in the values of x and y.
Step 2. Test if x is greater than y.
Step 3. If x is greater than y, x is higher. However, if x is less than y, y is higher.
Step 4. Print the number and the remark Higher.
1. Draw a flowchart that will input values for x and y. Compare two values inputted and
print which of the values is higher including the remark Higher. Write its equivalent
algorithm.
2. Draw a flowchart that will determine the students final grade and indicate weather it
is passing or failing. The final grade is calculated as the average of four marks.
Algorithm
Step 1. Initialize Grade into 0.
Step 2. Input a set of 4 marks (M1, M2, M3, M4).
Step 3. Calculate their average(Grade) by summing and dividing by 4.
Step 4. If average(Grade) is below 50
Print FAIL
else
Print PASS
Algorithm
Step 1. Initialize bonus to 0.
Step 2. Read in employees name and salary.
Step 3. Test if employees salary is less than 10,000.
Step 4. If salary < 10,000 then
Bonus = salary * 25 %
Else
Bonus = 3,000
Step 5. Print the employees name and bonus.
Construct a flowchart that will accept the evaluation score of a faculty and determine
its equivalent remarks. Print the name of the faculty and the remarks obtained. Write
the equivalent algorithm. Remarks are based on the following criteria:
4.50 5.00
Outstanding
4.00 4.49
Very Satisfactory
3.50 3.99
Satisfactory
3.00 3.49
Needs Improvement
2.99 below
Poor
Algorithm
Step 1. Initialize Rem into space or blanks.
Step 2. Read in the values of Name and Score.
Step 3. Test the score if it is greater than or equal to 4.50.
Step 4. If the score is greater than or equal to 4.50, Rem is Outstanding. However, if
the score is less than 4.50, do step 5.
Step 5. Test the score if it is greater than or equal to 4.00.
Step 6. If the score is greater than or equal to 4.00, Rem is Very Satisfactory.
However, if the score is less than 4.00, do step 7.
Examples:
1. Construct a flowchart that will count from 1 to 10 and print each number counted using
the looping structure. Write the equivalent algorithm.
Algorithm
2. The initial value of the radius of a circle is equal to 1 unit and each succeeding radius
is 1 unit greater than the value before it. Draw a flowchart to compute the area of a
circle starting with radius=1 up to radius = 5, then print each radius and the
corresponding area of a circle.
Formula: area = pi x r2
Algorithm
Step 1. Initialize the value of radius(r) to 1 and the value of pi to 3.1416.
Step 2. Compute the area by multiplying pi to the square of r.
Step 3. Print the value of r and the area.
Step 4. Increment the value of r by 1.
Print
Product
NAME: ______________________________
Course/Year/Section : _____________ ____
SCORE: ________
Date : __________
CONCEPT REVIEW
1.
2.
3.
4.
5.