0% found this document useful (0 votes)
57 views23 pages

DCIT 22 Computer Programming 1 Lecture 2

Uploaded by

Norvin Lincallo
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
57 views23 pages

DCIT 22 Computer Programming 1 Lecture 2

Uploaded by

Norvin Lincallo
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 23

DEVELOPING

ALGORITHMS
DCIT 22 –
COMPUTER
PROGRAMMING 1
Algorithms are in everything we
An algorithm is the list of
do. But for those that aren’t
instructions and rules that a
inclined toward maths and
computer needs to do to
programming, the term
complete a task.
‘algorithm’ is less than clear.
DEVELOPING
ALGORITHMS
(In fact, the joke runs that
developers use the word So, you might have heard the
‘algorithm’ when they don’t term before, even used it. But
want to explain what they’ve what is an algorithm exactly?
done.)
In essence, algorithms are simply a series of instructions
that are followed, step by step, to do something useful or
solve a problem. You could consider a cake recipe an
algorithm for making a cake, for example.

In computing, algorithms provide computers with a


WHAT IS AN successive guide to completing actions. They’re comprised
ALGORITHM? of a precise list of instructions that outline exactly how to
complete a task.

So, what is an algorithm? A good way to think of them is as


mini instruction manuals telling computers how to complete
a given task or manipulate given data.
HOW DO COMPUTER
ALGORITHMS WORK?

• Computer algorithms work via input and output. They take


the input and apply each step of the algorithm to that
information to generate an output.

• For example, a search engine is an algorithm that takes a


search query as an input and searches its database for items
relevant to the words in the query. It then outputs the
results.

• You can easily visualize algorithms as a flowchart. The


input leads to steps and questions that need handling in
order. When each section of the flowchart is completed, the
generated result is the output.
• Pseudocode is an informal way of programming
description that does not require any strict
programming language syntax or underlying
WHAT IS technology considerations. It is used for creating an
PSEUDOCODE? outline or a rough draft of a program. Pseudocode
summarizes a program’s flow, but excludes underlying
details. System designers write pseudocode to ensure
that programmers understand a software project's
requirements and align code accordingly.
IDENTIFIERS
• These are names that represents numeric and
non-numeric data which occupy computer
memory location.

• Types of Identifier

• Variable - identifier that can store a


changeable value

• Constant – identifier with fixed value


• General Rules in Naming Identifier

• The names must be according to what they represent. As


a good programming practice, identifiers must be short
and descriptive.
IDENTIFIERS • Space is not allowed to be part of identifiers.

• It must not start with a digit.

• Special characters (except for an underscore) are not


permitted to use as identifiers.
OPERATORS
These are symbols that instruct the compiler to
perform mathematical and logical manipulations.
CLASSIFICATION OF OPERATORS
SYMBOL MEANING EXAMPLE
• A. Arithmetic - used to perform
+ Addition num1 + num2
mathematical operations and produce
- Subtraction gross - expense
numerical values
* Multiplication unit * grade

/ Division sum / 10

% Modulus Division 5%2

^ Exponentiation x^3
CLASSIFICATION OF OPERATORS
SYMBOL MEANING EXAMPLE • B. Rational - used to compare two
< Less than x<y
data values against each other and
<= Less than or equal to subjectLoad<=21 produce true or false results
> Greater than score>70

>= Greater than or equal to num1>=num2

‘==’ Equal to GPA==2.5

!= Not equal to Salary!=1000


CLASSIFICATION OF OPERATORS

SYMBOL MEANING DESCRIPTION EXAMPLE • C. Logical – used to combine two or


more comparison tests into a single
Returns true if both
&& And
expression are true
age >= 13 && age <= 19
compound comparison expression.
Return true if at least one
|| Or num1 < 0 || num2 > 100
expression is true

Negates the results of an


! Not !(x=7)
expression
CONVERSION OF ALGEBRAIC EXPRESSION
INTO COMPUTER EXPRESSION

• When converting expression, the appropriate equivalent symbols of operators must be


used
• the operators are always carried out from left to right
• Hierarchy of operators must be considered when performing evaluation. Hierarchy
decides which operators will be used first by the compiler.
• Expressions can be grouped with the use of parentheses. As a rule, the expressions
inside the parenthesis are always evaluated first by the compiler.
• The result of an algebraic expression must be the same with the result of a computer
expression.
^ Exponentiation
Multiplication, Division and Modulus Division have
*/%
the same level of precedence
Addition and Subtraction have the same level of
+-
precedence

HIERARCHY OF ARITHMETIC OPERATORS


• this operation is used to store a new value
to the variable.
• can be distinguished through an equal
symbol(=).
ASSIGNMENT •
OPERATION • Examples

• sum = num1 + num2

• A=B

• grade = 70
TYPES OF VARIABLE UTILIZED IN
AN ASSIGNMENT OPERATION

CONSTRUCTIVE VARIABLE – DESTRUCTIVE VARIABLE – ITS


MAINTAINS ITS VALUE AFTER VALUE CHANGES AFTER THE
BEING USED IN THE PROCESS PROCESS
ALGORITHM AND FLOWCHART
• Algorithm
It is a set of instruction that specify a sequence of operations to be carried out in order to solve a
specific problem.

Ex. A recipe in cookbook is an excellent example of an algorithm.

• Flowchart
 It is a diagram representing the logical sequence in which a combination of steps operations is to be
performed.
 Generally, flowchart contains all the three stages of data processing namely: Input, Process, and
Output.
 It consists of labelled geometrical symbols that are interconnected to provide a pictorial representation
of a data processing procedure.
 It is actually a visual representation of an algorithm.
FLOWCHARTING SYMBOLS

SYMBOL REPRESENTATION FUNCTION

Indicates the starting and ending


oblong Terminal
points of the flowchart.

Assigns the initial values of the


hexagon Initialization/Preparation variables, usually 0 to numeric and
null to string.
Represents variables to be
parallelogram Input/Output processed and prints the required
information.

Executes arithmetic operations


rectangle Process
involved.
FLOWCHARTING SYMBOLS
SYMBOL REPRESENTATION FUNCTION

Diamond Decision Select paths for various conditions

Shows an exit of the program path line


from one part of the flowchart or an entry
Circle On – Page Connector
to another part of the flowchart on the
same page

Indicates the direction of the flow in


Arrows
Directions processing data

Shows an exit of the program path line


from one part of the flowchart or an entry
Pentagon Off- Page Connector
to another part of the flowchart of
different page.
Used to show reading order or sequence
Horizontal/Vertical Lines Flow Lines in which flowchart symbols are to be
read.
GUIDELINES FOR
PREPARING A FLOWCHART
• A flowchart always begin with a START/BEGIN and is completed by a
STOP/END;
• Symbols are interconnected using flow lines and arrows;
• Use comma (,) to separate data;
• An arrow’s head indicates the direction to be followed;
• All symbols except diamond may have only one arrow branching out, but
may have one or more arrows branching in;
• Whenever circles are used, the symbol leading to circle should flow to the
symbol where a circle containing a similar character lead to.
• The sequence of symbols matter because it indicates the logical steps to be
followed;
• A flowchart may contain many symbols of the same kind as necessary in
the solution of the problem; and
• There may be many types of flowcharts to solve one problem but the
simplest flowchart is the most efficient.
BASIC CONTROL
STRUCTURES
these are construct that are meant to direct the flow
of flowcharts or programs in one way or another.

• Sequence - the instructions are executed


from one to another in a straightforward
manner.
• Selection – is used to make a decision to go
down to one path or another.
BASIC CONTROL
STRUCTURES
• 3. Looping - In computer science, a loop is a programming
structure that repeats a sequence of instructions until a
specific condition is met. Programmers use loops to cycle
through values, add sums of numbers, repeat functions, and
many other things.

• Loops are supported by all modern programming languages,


though their implementations and syntax may differ. Two of
the most common types of loops are the while loop and
the for loop.
SAMPLE FLOWCHART OF SEQUENCE
(a flowchart that displays the sum of two numbers)
THANK YOU!
Fonts used: Roboto Mono and Gugi

You might also like