Académique Documents
Professionnel Documents
Culture Documents
ALGORITHM
PSEUDOCODE
FLOWCHART
PROBLEM SOLVING USING ALGORITHMS
What is an Algorithm?
Your favourite app, the online game that you always play, the
document you type, the spreadsheet that you use to compute
and analyze data, the GPS in your car. You may not be aware
of it, but these computer programs wont be able to perform
their specific task without creating an algorithm.
ALGORITHM
You can think of an algorithm as similar to a food recipe. If you
make a sandwich, you follow a set of steps to put the different
ingredients together. You bring ingredients together, assemble
them as you like, and produce a final product - the sandwich. If
you were asked to write down instructions to make a sandwich,
you could create a written algorithm.
PROGRAM LOGIC FORMULATION
Statement 1;
Statement 2;
Statement 3;
Statement 4;
Statement 5;
Statement 6;
and so on…
PROGRAM LOGIC FORMULATION
But, what if we want to make a choice? What if we want to add sugar
or not the tea? We call this SELECTION.
In a pseudocode, the example looks like this:
IF (sugar is required)
THEN add sugar;
ELSE don't add sugar;
ENDIF;
IF (<CONDITION>)
THEN <Statements>;
ELSE <Statements>;
ENDIF;
IF (A > B)
THEN Print A + “is bigger”;
ELSE PrintB + “is bigger”;
ENDIF;
PROGRAM LOGIC FORMULATION
PSEUDOCODE THAT SHOWS SELECTION
STATEMENT IN A PROGRAM
PROGRAM LOGIC FORMULATION
What if we need the computer to keep doing something until some condition
occurs? What if we would like to indicate that the kettle should be filled with water
until it is full. In this case, we need a loop or ITERATION.
WHILE (<Condition>)
DO <Statements>;
ENDWHILE;
A = 1;
WHILE (A < 5)
DO Print A:
A = A + 1;
ENDWHILE;
DISCOVERY: What is the advantage of using loops or iteration? Search the answer
on the Internet.
PROGRAM LOGIC FORMULATION
More examples!
PSEUDOCODE
Problem: Read in a number and print it out
Solution using a pseudocode: Problem: Read in a number and check if
that number is odd or even/
PROGRAM PrintNumber: Solution using a pseudocode:
Read A;
Print A; PROGRAM IsAddOreven:
END. IF (A > B)
THEN Print “It’s Odd”
ELSE Print “It’s Even”
Problem: Read in a number and print it out END.
and double the number
Solution using a pseudocode:
Problem: Print out the bigger of two numbers
PROGRAM PrintDoubleNumber: Solution using a pseudocode:
Read A;
B = A*2 PROGRAM PrintBiggerOfTwo:
Print B; Read A;
END. Read B;
IF (A/2 gives a remainder)
THEN Print A
ELSE Print B
END.
FLOWCHART
represents
FLOWCHARTING algorithm in a
graphical manner.
It uses shapes
ADVANTAGES: and symbols.
• Communication: - Flowcharts are better way of communicating the logic of a system to all
concerned.
• Effective analysis: - With the help of flowchart, problem can be analysed in more effective
way.
• Proper documentation: - Program flowcharts serve as a good program documentation,
which is needed for various purposes.
• Efficient Coding: - The flowcharts act as a guide or blueprint during the systems analysis
and program development phase.
• Proper Debugging: - The flowchart helps in debugging or fixing the errors in the process.
• Efficient Program Maintenance: - The maintenance of operating program becomes easy with
the help of flowchart. It helps the programmer to put efforts more efficiently on that part
DISADVANTAGES:
• 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.
• Reproduction: - As the flowchart symbols cannot be typed, reproduction of flowchart becomes a
problem.
FLOWCHART SYMBOLS
FLOWCHART
SYMBOLS
Examples of Flowchart