Professional Documents
Culture Documents
TOPICS:
1. INTRODUCTION TO ALGORITHMS
2. PSEUDOCODE
3. FLOWCHARTS
ALGORITHMS
There are many ways to solve a problem. Moreover, given a certain way to solve a
problem, there are many ways to express that into algorithm. Problem solving is the
process of transforming the description of a problem into the solution of that problem.
The study of algorithms began as a subject in mathematics. The search for algorithms
was a significant part of early mathematicians. Their goal then was to find a single set of
instructions that can be used to solve any problem of a particular type.
EXAMPLE:
Write an algorithm to compute the distance traveled and the average miles per gallon on
a trip when given as input the number of gallons used and the starting and ending
mileage readings on the odometer. Repeat this process until user wants to stop.
PSEUDOCODE
Pseudocode consists of short, English phrases used to explain specific tasks within a
program's algorithm. Pseudocode should not include keywords in any specific computer
languages. It should be written as a list of consecutive phrases.. Indentation can be used
to show the logic in pseudocode as well.
The purpose of using pseudocode is that it may be easier for humans to read than
conventional programming languages, and that it may be a compact and environment-
independent description of the key principles of an algorithm. No standard for
pseudocode syntax exists, as a program in pseudocode is not an executable program.
You can’t draw diagrams in Pseudocode. Instead you use special words (called key
words) to specify the logic of an algorithm.
Start
Walk
to door
BEGIN
Open Walk to door
door Open door
Move through door
Move
through END
door
FLOWCHARTS
The flowchart is a means of visually presenting the flow of data through an information
processing systems, the operations performed within the system and the sequence in
which they are performed. Flowcharts are generally drawn in the early stages of
formulating computer solutions. Flowcharts facilitate communication between
programmers and business people. These flowcharts play a vital role in the
programming of a problem and are quite helpful in understanding the logic of
complicated and lengthy problems. Once the flowchart is drawn, it becomes easy to
write the program in any high level language.
Often we see how flowcharts are helpful in explaining the program to others. Hence, it is
correct to say that a flowchart is a must for the better documentation of a complex
program.
HISTORY OF FLOWCHARTS
The first structured method for documenting process flow, the flow process chart, was
introduced by Frank Gilbreth to members of ASME (American Society of Mechanical
Engineers) in 1921 in the presentation “Process Charts—First Steps in Finding the One
Best Way”
FLOWCHART SYMBOLS
Off-page connector
Flow line
Preparation / Initialization
Now we shall present few examples on flowcharting for proper understanding of this
technique. This will help in student in program development process at a later stage.
TYPES OF DATA
Some rules must be followed for defining identifiers. They are as follows:
1. It must consist only of letters, digits, and underscores.
2. An identifier cannot begin with a digit.
3. An identifier defined in the C standard library should not be redefined.
4. Identifiers are case sensitive; meaning uppercase is not equal to the lowercase.
• Variables are identifiers that can store a value that can be changed.
These can be of different data types. They can store literals or some type
of structured data. Structured data can contain one or more values or data.
• Constants are identifiers that can store a value that cannot be changed.
Usually, constant identifiers are all capital letters with underscores between
each word to distinguish them from variables.
• Keywords are words that have a strict meaning in C. These are special
words “reserved” by the programming language for processing, thus these
may not be redefined by the programmer.
In the English language, we have both syntax and semantics. Syntax is the grammar of
the language. Semantics is the meaning. An English sentence may be syntactically
correct, yet semantically incorrect. This is also true of algorithms. And it is also true of
computer code.
HOLY ANGEL UNIVERSITY
COLLEGE OF INFORMATION & COMMUNICATION TECHNOLOGY
Pseudocode is used in
• designing algorithms
• communicating an algorithm to the customer
• converting an algorithm to code (used by the programmer)
• debugging logic (semantic) errors in a solution before coding (hand tracing)
GUIDELINES
• Any user prompts should appear exactly as you wish the programmer to code them.
• The destination of any output data should be stated, such as in “Display”, which
implies the screen.
• Make the data items clear (e.g., surround them by < and > ) and give them
descriptive names.
• Use formulas wherever possible for clarity and brevity.
• Use keywords (such as Read and While) and use them consistenty. Accent them in
some manner.
• Use indentation for clarity of logic.
• Avoid using code. Pseudocode should not be programming language-specific.
• Always keep in mind that you may not be the person translating your pseudocode
into programming language code. It must, therefore, be unambiguous.
• You may make up your own pseudocoding guidelines, but you MUST be consistent.
Any problem can be solved using only three logical control structures:
• Sequence - A series of steps or statements that are executed in the order they are
written.
Display “Enter two numbers: “
Read <number1>
Read <number2>
<sum> = <number1> + <number2>
Display “sum = “, <sum>