0% found this document useful (0 votes)
7 views33 pages

Algorithms

Uploaded by

sam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
7 views33 pages

Algorithms

Uploaded by

sam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 33

WEEK 1: ALGORITHMS

Solving problems with an Orderly Mind


WEEK 1: ALGORITHMS
Solving problems with an Orderly Mind
What results
would you get if
you search
Google for
Adobo recipe?
How does Google
rank its search
result?
Let’s go to MC!
1. Go to maps.google.com
2. In the search bar, type Miriam College Quezon City
3. Click the Directions button.
4. Observe the results field and determine the following:
a. Number of routes suggested by Google
b. Shortest route
c. Fastest route
5. Among the given routes which path will you choose? What other factors might
affect your choice?
These directions are all algorithms. They all have
the same goal, but a few them is more efficient or
less expensive than other options.
Get the remainder of the following expression:

203 ÷ 9
What is an Algorithm?

A formula or set of steps for Algorithms can be expressed in


solving a particular problem. any natural language like
Algorithms must be clear and English, symbols or
must have an end point. programming languages like
Python.
What is an Algorithm?

We use algorithms every day. Most programs, with the exception of


some artificial intelligence applications, consist of algorithms.
Inventing elegant algorithms -- algorithms that are simple and
require the fewest steps possible -- is one of the principal
challenges in programming
What makes a
good algorithm?
Characteristics of a good algorithm
1. Input specified

2. Output specified

3. Definiteness

4. Effectiveness

5. Finiteness

6. Independent
Let’s practice!

From our Google Classroom, access the assignment post titled Exercise 1. Use the
attached slide template and design a flowchart on how to cook rice.
Week 1: Day 2
There are four common ways of
writing an Algorithm in CS

● Natural Language
● Pseudocode
● Flowchart
● Programming code
How to write an Algorithm?
1. Natural Language – simply writing the algorithm in plain language. It
observes proper grammar and spelling. Typically understood only
among persons. Recipes for cooking are examples of natural
language algorithm.

2. Pseudocode – is an instruction written to mimic actual programming


code, yet does not strictly follow the language’s rules nor can be
understood by a computer. Preferred drafting/planning language
among programmers.
How to write an Algorithm?
3. Flowchart – uses predefined symbols to contained steps of an algorithm.
The symbols even more simplify the presentation of the algorithm, which
focuses more on the flow of procedures.

4. Programming code – the algorithm understood by the computer. Can be


classified into many languages, each vary in the manner of interfacing with a
computer. Examples include machine code, assembly code and Python.
Pseudo code
1. Ask no. of participants in total
2. Ask for planned no. of groups
3. Divide no. of participants by planned no. of groups
4. If quotient doesn’t have a remainder
a. Display no. of participants for each group
5. else
a. Get remainder and deduct from group size and display first batch of groupings.
b. Display groupings for remaining participants
Sample
programming
code
Read aloud the color of the text
Basic Flowchart Symbols
Symbol Name Function

Terminator An oval represents a start or end


START END
point.

Arrow line/Arrow Arrow line is a connector that shows


relationship and direction between
symbols.

INPUT Input/Output or A parallelogram represents input or


c Data output data.
a, b

Add a,b Process A rectangle represents a process.


c=a+b

Is it Grade Decision/Branch/ A diamond indicates a branch in the


raining? >= 75? Question process or a decision.
Sample
Flowchart

source : https://www.codeavengers.com/notes/planning/flowcharts
Flowcharting Guidelines
● The start/end(Terminator) symbols must be the first and last symbols that
the reader should see. Depending on your layout, the start symbol should
be the topmost/leftmost part of the flowchart area, and end symbol must
the bottommost/rightmost area.

● Only one start and one end symbol should appear in a flowchart.

START END
Flowcharting Guidelines
● Avoid using lines without arrowheads. The arrowhead points the reader to
the next step.

● Do not make the lines intersect.


Flowcharting Guidelines
● Decision symbols have at least have incoming line and two possible
outgoing lines (yes/no or true/false).

● Attach the lines to the vertices/corners of the diamond(decision) symbol


and not on the sides.

Incoming line/process

Yes 3rd is optional.


Can be incoming/
Yes No Outgoing line
Outgoing No
line/process
Flowcharting Guidelines
● Difference between Process(rectangle) and Input/Output(Parallelogram)
● Use the Process symbol for all actions except for actions that require input
of information or generation of data.

ADD a and b INPUT a, b

● It is not necessary to only have one input or output in a flowchart. The


number of input or output do not always need to match.
How to create a flowchart in Google slides
HOA 1: Flowchart

Access the Assignment post for HOA 1. Use the attached slide template and design
a flowchart for the following scenarios:

1. Ordering food from Grab/Foodpanda


2. Rounding up a number

Turn in the slides of your 2 flowcharts through the Assignment post in our Google
Classroom not later than 4:00 P.M. today.
Do you think a
robot can
understand
your
instructions?
“I took a computer-science
course to fill a prerequisite
at Stanford, and I realized
that every day was a new
problem, and every day you
got to think about how to
solve something new, how
to reason through
something new, how to
develop an algorithm to
solve for something you
hadn't worked on before.”

Marissa Mayer,
Google’s first female engineer
RESOURCES
http://openbookproject.net/thinkcs/python/english3e/way_of_the_program.
html

https://www.programiz.com/article/flowchart-programming

What’s an algorithm, David Malan -


https://www.youtube.com/watch?v=6hfOvs8pY1k

You might also like