You are on page 1of 8

Topic: Introduction to Algorithms & Flowcharts Date: _________________

Class Learning Objective: 3.1 How to…explain the three different ways algorithms can
be written & 3.2 How to… use flowcharts to help design algorithms
APCSP Essential Knowledge: AAP-2.A.1-4, AAP-2.B.1-7, AAP-2.C.1-4, AAP-2.E.1-2, AAP-
2.G.1, AAP-2.H.1, AAP-2.J.1, AAP-2.K.1, 4, 5, AAP-2.L.1-2, 5, AAP-2.M.1

Algorithms
Notes
Definition: A process or set of rules to be followed in order to perform a calculation or other
problem-solving operations

***These are generally used to describe computer programs to solve


a problem or complete a task of some kind***

Examples: Recipes, steps to solve a math equation, program code,


rules of a game

Programming Concepts – There are 3 different concepts used in


computer programming that algorithms help with completing:

• Sequence (a series of ordered processes),


• Selection (a decision which is based on a whether a condition is
met)
• Iteration (repetition of a process or a loop)

Everyday Algorithms Examples


Typing shoes (iteration)

Following directions (sequence)


Deciding if someone is tall enough to ride a ride (selection)

Algorithms in Programming vs. Flowcharts


Algorithms in Programming Flowchart
It is a procedure for solving problems. It is a graphic representation of a process.
The process is shown in block-by-block information
The process is shown in step-by-step instruction.
diagram.

It is complex and difficult to understand. It is intuitive and easy to understand.

It is convenient to debug errors. It is hard to debug errors.


The solution is showcased in programming
The solution is showcased in pictorial format.
language.

It is somewhat easier to solve complex problem. It is hard to solve complex problem.

It costs more time to create an algorithm. It costs less time to create a flowchart.
Topic: Introduction to Algorithms & Flowcharts

Creating Flowcharts
Flowcharts generally have a start point, an endpoint, inputs, outputs, possible paths to
follow, and the decisions that lead to those possible paths. Flowcharts help us get started
on creating an algorithm in programming.
Basic Symbol Meaning Function Example

Begin and end your flowchart Start


Start or End
algorithm with these symbols End

Arrows are used to show the


Direction of flow direction of flow or paths
within the algorithm

Used when you want to input OUTPUT: What is


information into your your name?
Input or Output algorithm or output
information into your INPUT: User
answers question
algorithm

Answers a question or
condition with a Boolean False Are you True
Decision hungry?
response (only 2 options:
“True or False” or “Yes or No”)

Variables are used to store


Process: Defines information and can be called
Score = Score + EndRound
a variable OR on later in the algorithm OR
Use input to do next
completes a task Shows a task or process being
calculation
done

The 3 Types of Algorithms in Flowcharts


Sequence Selection Iteration/Loop
Topic: Introduction to Algorithms & Flowcharts
Look at the following flowcharts, label which one shows a sequence, selection, or iteration.
Selection Iteration Sequence

Usefulness of Flowcharts

Flowcharts are VERY useful and important to create


before writing a computer program when using
‘if/else’ decisions and ‘while’/ ‘for’ loops.

This way you can make sure your program is logical.

Selection Flowcharts
**Can sometimes have multiple end spots depending on the “decision”**
If/Else
Topic: Introduction to Algorithms & Flowcharts

Iteration Flowcharts
**There are 2 main types of iterations**
For Loop While Loop If you notice, for and while loops
look VERY similar. Use this
comparison to figure out which
one is more appropriate to use.

For Loop While Loop


Used when
Use for definite
number of
number of
iterations/loops
iterations/loops
is unknown
Will ONLY do
Will do at least iteration/loop if
1 iteration/loop condition is
met

Practicing with Flowcharts

Infinite Loops Match each type of step below if it was used in


a flowchart.
**Be careful with the
conditions to not accidentally Word Bank: Loop, Start, Process, Input, Stop,
create an infinite loop** Decision, Output

1) Process Calculate the total of A, B, & C

2) Stop Indicate that the problem has been solved

3) Decision Find if a number is greater than the


other

4) Loop Walk up a flight of stirs until you’ve reach


the top

5) Input Asks the user to enter their age

6) Output The program displays the total of a


calculation (this is called ‘printing’)

7) Start Indicate the beginning of a problem-


solving flow
Topic: Introduction to Algorithms & Flowcharts

More Practice
The following flowchart classifies animals as herbivore, carnivore, or
omnivore. Study the flowchart and answer the questions below.
a. Put a rectangle around the decision structure.

b. Indicate each element of the flowchart by putting ‘I’


for input, ‘O’ for output, ‘D’ for decision in the I
circles provided next to the boxes.

c. What is/are the condition(s) which classifies an


animal as carnivore? False for the 1st decision &
True for 2nd decision D D
The execution steps for a Lion would be:
Start > Input: Lion > No > Yes > Output: Print
Carnivore > End

d. Write the execution steps if the input is an O O O


Elephant:

Start > Input: Elephant > Yes > Output: Print


Herbivore > End

e. Write the execution steps if the input is a Bear:


Start > Input: Bear > No > No > Output: Print
Omnivore > End

Follow the flowchart below with the indicated different inputs to see the new
final number. Complete the table with the final number.
Final
Number A Number B
Number

4 7 39

13 100 130

5 90 104

40 50 134

1 2 28
Topic: Introduction to Algorithms & Flowcharts

More Practice
This is a flowchart for taking attendance. Add the missing features below to it.
1) Four arrows are missing
2) A loop is missing
3) Assign yes/no labels for the decision.

No

Yes
No

Yes

Below you have 3 different flowcharts. Complete each step by writing in one of the
available options around the flowcharts (each option will only be used once out of all 3
flowcharts). Then indicate which flowchart displays a sequence, selection, and iteration

Sequence Selection Iteration

Check contents of
Put on shirt
wallet/purse
Add water

Have at least $10? Stay at home &


Put on hoodie
watch TV
Is the cup full?

Go to the
Put on jacket
theatre
Stop
Topic: Introduction to Algorithms & Flowcharts
More Practice
1) Which types of algorithms are needed to compute the average height for a list
of basketball player heights? SELECT ALL THAT APPLY
a) Selection
b) Iteration
c) Sequencing
d) None of the above

2) Han develops an algorithm to compute the average amount of time that users watch a
particular video on YouTube. She realizes that the average is very low because of many
watch times with a duration "0" or "1“. She decides that the algorithm should ignore those
durations. What structure must be added to the algorithm so that it does not
consider those short durations when computing the average?

a) Selection
b) Iteration
c) Sequencing
d) None of the above

3) "Aba speak" is a game invented by school children to disguise what they're speaking.
When speaking, they transform each word following this algorithm:
For each letter in a word:
If letter is vowel:
Add "b" after
Add that letter after "b“
Following that algorithm, how would they transform the word "avocado"?
a) abavbvobocbcabadbdobo
b) abavobocabadobo
c) avabocabadabo
d) abavobacabadoba
e) abvobcabdob

Create your own flowcharts

1) Create a flowchart on how to clean the dishes one by one from a sink full of dirty dishes (think if
a loop can help reduce the number of steps). Turn your paper sideways if you need more room
vertically.

See next page


Topic: Introduction to Algorithms & Flowcharts
Create your own flowcharts

1) Create directions on how to clean the 2) Create a flowchart for a program


dishes one by one from a sink full of to print (display) the message “Hello
dirty dishes. World” 10 times.

You might also like