[go: up one dir, main page]

0% found this document useful (0 votes)
46 views8 pages

M2 Guide

This document provides an overview of algorithms, pseudocode, and flowcharts. It defines an algorithm as a procedure or formula for solving a problem through a sequence of specified actions. Pseudocode is described as a way to express an algorithm using plain English instead of a programming language. Finally, flowcharts are defined as pictorial representations of program logic using standard graphic symbols to show the sequence of instructions. The document provides examples of algorithms expressed in pseudocode and as flowcharts.

Uploaded by

Artus Artigas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views8 pages

M2 Guide

This document provides an overview of algorithms, pseudocode, and flowcharts. It defines an algorithm as a procedure or formula for solving a problem through a sequence of specified actions. Pseudocode is described as a way to express an algorithm using plain English instead of a programming language. Finally, flowcharts are defined as pictorial representations of program logic using standard graphic symbols to show the sequence of instructions. The document provides examples of algorithms expressed in pseudocode and as flowcharts.

Uploaded by

Artus Artigas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

STUDY GUIDE

ALGORITHM

• Algorithm is a procedure or formula for solving a problem, based on conducting a sequence of


specified actions.

• Algorithm can be expressed using pseudocode or flowchart.

ALGORITHM OVERVIEW

• Plan the algorithm that will transform the problem’s input into its output.

• Write the algorithm in the Processing column of the Input-Process-Output (IPO) chart.

• Each instruction in the algorithm will describe an action that the computer needs to
take.

• Thus, each instruction should start with a verb.

ALGORITHM OVERVIEW

• Most algorithms begin with instruction to enter the input items into the computer.

• Next, record instructions to process the input items to achieve the problem’s output.

• The processing typically involves performing one or more calculations using the input items.

• Most algorithms end with instruction to display, print, or store the output items.

• Display, print, and store refer to the computer screen, printer, and a file on a disk, respectively.

PSEUDOCODE

• Pseudocode is called false code because, it has no syntax like any of the programming language
and thus can’t be compiled or interpreted by the computer.

• It is simply an implementation of an algorithm in the form of annotations and informative text


written in plain English.

• It is not standardized.

• Every programmer has his or her own version, but you will find some similarities among other
versions.

WRITING A PSEUDOCODE

• In Pseudocode, keywords are used to indicate common input-output and processing operations.
They are written fully in uppercase.

• It also used mathematical, relational and logical operators to express arithmetic and logical
operations.
• When writing pseudocode, we assume that the order of execution of the statements is from top
to bottom. This changes when using control structures, functions and exception handling.

WRITING A PSEUDOCODE

KEYWORDS:

• START: This is the start of your pseudocode.

• INPUT, ENTER, READ / GET : This is data retrieved from the user through typing or through an
input device.

• PRINT, OUTPUT, DISPLAY, SHOW: This will show your output to a screen or the relevant output
device.

• COMPUTE, CALCULATE, DETERMINE: This is used to calculate the result of an expression.

• SET, INIT: To initialize values

• INCREMENT, BUMP: To increase the value of a variable

• DECREMENT: To reduce the value of a variable

COMMON OPERATORS:

• Assignment: ← or :=

Example:

c ← 2πr, c := 2πr

• Arithmetic: +, −, ×, /, mod

Example:

a + b, x – y, m x n,

s / t, num mod 2

KEYWORDS in CONDITIONAL:

During algorithm development, we need statements which evaluate expressions and execute
instructions depending on whether the expression evaluated to True or False.

Here are some common conditions used in Pseudocode:

• IF — THEN – ENDIF

• IF – ELSE IF — ENDIF

• IF — ELSE IF — ELSE – ENDIF

• CASE – OTHERS – ENDCASE


PSEUDOCODE EXAMPLES

BASIC I/O STATEMENT

Problem Specification 1:

Ms. Noreen wants a program that will calculate and display the amount she should tip a waiter at a
restaurant. Tip can be computed by multiplying the total bill and the tip (using a percentage).

CONDITIONAL: IF-ELSE STATEMENT

Problem Specification 2:

Make a program that will display the lowest and highest of two integers entered by the user using if-else
statement.

CONDITIONAL: CASE STATEMENT

Problem Specification 3:

Make a program that will ask the user to choose from letters A to C then display the equivalent fruit
starting from the selected letter using case statement.
ITERATION: FOR LOOP

Problem Specification 5:

Make a program that will display the sum of three input numbers using for loop statement

ITERATION: WHILE LOOP

Problem Specification 4:

Make a program that will display the sum of three input numbers using while loop statement

ITERATION: DO-WHILE LOOP


Problem Specification 6:

Make a program that will display the sum of three input numbers using do-while loop statement

FLOWCHART OVERVIEW

Flowchart is a pictorial representation of an ordered, step-by-step solution to a problem.

• Program Flowchart is a diagram that uses a set of standard graphic symbols to represent the
sequence of coded instructions fed into a computer, enabling it to perform specified logical and
arithmetical operations.

FLOWCHART SYMBOLS

Symbol Purpose Description

Indicates the flow of logic by connecting


Flow line
symbols.

Represents the start and the end of a


Terminal(Stop/Start)
flowchart.

Input/Output Used for input and output operation.

Used for arithmetic operations and


Processing
data-manipulations.

Used for decision making between two


Decision
or more alternatives.
On-page Connector Used to join different flowline

Used to connect the flowchart portion


Off-page Connector
on a different page.

Predefined Represents a group of statements


Process/Function performing one processing task.

FLOWCHART STRUCTURES

Flowcharts can be used to express different structures:

• sequence

• selection/conditional

• loop.

Examples of flowcharts in programming:

1. Add two numbers entered by the user.

2. Find the largest among three different numbers entered by the user.
3. Find all the roots of a quadratic equation ax2+bx+c=0

4. Find the Fibonacci series till term≤1000.


Note: Though flowcharts can be useful writing and analysis of a program, drawing a flowchart for
complex programs can be more complicated than writing the program itself. Hence, creating flowcharts
for complex programs is often ignored.

You might also like