UC2 WEEK 4
Topic: ALGORITHM AND FLOWCHART
Algorithm: Step-by-step procedure to solve a problem or perform an
operation. Example: Cooking fried rice.
Flowchart: Visual representation of steps and decisions to solve a problem,
using diagram shapes and arrows.
Functions of an Algorithm:
1. Road maps for tasks.
2. Develop effective solutions.
3. Predict special cases.
4. Manage memory and data.
5. Simplify program development.
CHARACTERISTICS OF AN ALGORITHM
The characteristics of a good algorithm are:
Unambiguous: Each step must be clear, well-defined and precise. It must be
easy to understand the procedure.
Effectiveness: it must give the correct answer.
Finiteness – there is exact number of steps to be taken and has an end.
Precision – the steps are precisely stated (defined).
Uniqueness – results of each step are uniquely defined and only depend on
the input and the result of the preceding steps.
Sequence of execution: instructions are performed from top to bottom.
Input specified: must specify the type, amount and from of data to be used
during the algorithm.
Output: It should result in at least one output.
WRITING SIMPLE ALGORITHMS FOR SOLVING PROBLEMS
1. Algorithm to compute the average of a given set of numbers.
The Algorithm follows:
i. c = 1 (use to count the numbers processed)
ii. Sum = 0
iii. If c > sum: go to line viii
iv. Sum = sum + c
v. c=c+1
vi. Go to line iii
vii. vii average = sum/c
viii. Print the average
ix. End.
2. An algorithm that evaluates Y=a(b-c) /d + 2
2
i. Input the values a, b, c, d
ii. Y=a*(b-c)^2 /(d + 2)
iii. Print Y
3. An algorithm that prints out the first ten odd numbers.
i. Count =0
ii. Sum=1
iii. Sum =sum + count
iv. If count > 10, go to line viii
v. Count = count + 2
vi. Go to line iii
vii. Average = sum/num
viii. Print average
ix. End
BASIC FLOWCHART SYMBOLS
The flowchart symbols are as follows:
Terminator (Start and Stop): The oval, or terminator, is used to
represent the start and end of a process.
Process: It represents any step in the process you’re
diagramming
Data (Input/Output): Input and output symbols show where and
how data is coming in and out throughout your process
Arrow (Directional flow): The arrow is used to guide the
viewer along their flowcharting path.
Decision (Diamond): The diamond symbolizes that
a decision is required to move forward.
Document: Single and multiple document icons show that there
are additional points of reference involved in your flowchart.
Connector: connector symbols make it easier to connect
flowcharts that span multiple pages.
Predefined process: Used to reference flowchart defined
elsewhere.
FLOWCHART DIAGRAMS FOR GIVEN PROBLEMS
1. Flowchart to compute the average of a given set of numbers.
Video Links:
[Link]