Flow

Ryan: FYS Computational Reasoning Fall 2025

Flowcharts are the best

PreClass Work Review

Image from "Healers of the Wild: People Who Care for Injured and Orphaned Wildlife" by Shannon K. Jacobs, by way of the Wild Bird Fund.

What's Wrong With This Picture?

Flowchart = visualization of sequence and contingency

Sequence

Lists

Sequences

IKEA "Instructions"

IKEA Sequence

IKEA Flow

Contingency

Repetition

as sequence + contingency

if some condition, do it all over again tomorrow

Drawing Flowcharts

The Elements of Flow(charts)

arrow

flow

"go to..."

circle

terminal/connector

"and then..."

diamond

decision/branch

"if this is true..."

rectangle

module/action

"do this"

Wake Up

Shower

Eat

Read

Flow Chart My Morning Routine

  1. Wake up
  2. Shower
  3. Make breakfast
  4. Eat
  5. Read

Make breakfast

BUT!
On M,W,F I have an egg, on Tu,Th I have a protein shake...

M,W,F

Shake

Egg

Wake Up

Shower

Eat

Read

Flow Chart My Morning Routine

  1. Wake up
  2. Shower
  3. Make breakfast
  4. Eat
  5. Read

 

 

Make

breakfast

 

 

BUT!
On M,W,F I have an egg, on Tu,Th I have a protein shake...

M,W,F

Shake

Egg

Three Skills

flowChart2words

words2flowChart

fixFlowChart

A

D

B

C

E

F

do A
if B, do C,
  otherwise do D
do E
if A, do B
do C
if not D, do E

B

A

E

D

C

Flow in and Flow Out

\

O

\

O

\

O

Grammar of Flowcharts I

enter

exit

step*

module

<module> ::= enter <step>* exit

<step> ::= action | <contingency> 

<contingency> ::= <condition>
                                       <module>
                                       [<module>]

<condition> ::= condition

action

module

module

exit

condition

enter

true

false

step

RULE: Every Module has a Single Entry and a Single Exit

This can be a single action or any combination of sequence and contingency.

MODULE: any chunk of activity that can be popped into or out of a flowchart because of its single entry single exit property.

MODULE

How Does "Single Entry Single Exit" Rule Apply to Decisions?

Diamonds Do Not Stand Alone

condition
A

do action
B

do action
C

if condition A
     do action B
else
     do action C

the diamond splits the

flow into branches

the circle rejoins the

branches into a single exit

Diamond = IF-THEN-ELSE Module

condition
A

do action
B

do action
C

if condition A
     do action B
else
     do action C

STOP+THINK

Draw a flow chart:
 

If the light is green, go.
If it is red, stop.

"What you do at a traffic light"

STOP+THINK

Q1008

Draw a flow chart:
 

If it has 4 legs it is a donkey but if it has 2 legs it is a monkey, but if if has 0 legs it is a snake. Otherwise it is a spider.

Translate Into "if-then-else" Form

While it is raining,
keep your umbrella up.

is it raining?

umbrella up

is it raining?

umbrella up

is it raining?

umbrella up

"if-then-else" > WHILE Modules

While it is raining, use an umbrella.

If it is raining, use an umbrella, if not, put the umbrella away. Check every few minutes to see if it is still raining.

Is it raining?

    Yes? Use an umbrella

    Check again

Put the umbrella away

raining?

use umbrella

put umbrella away

Keep your umbrella up until it stops raining.

Translate Into "if-then-else" Form

"if-then-else" > UNTIL Modules

Use an umbrella. Check every few minutes to see if it is still raining.  When it stops, put the umbrella away.

Use an umbrella

    Check for rain

    If no rain, proceed.

Put the umbrella away

use umbrella

put umbrella away

Keep your umbrella up until it stops raining.

stopped raining?

In a WHILE loop, the "action" may be executed ZERO OR MORE TIMES

In an UNTIL loop, the "action" is always executed AT LEAST ONCE (i.e., "one or more times")

Grammar of Flowcharts

action step

action

module

module

exit

condition

enter

true

false

module

exit

condition

enter

true

false

module

exit

condition

enter

true

false

module

exit

enter

true

false

condition

enter

exit

step*

contingent step
while step
until step
module

Grammar of Flowcharts

<module> ::= enter <step>* exit

<step> ::= action | <contingency> | <while> | <until>

<contingency> ::= "if" <condition> <module> [<module>]

<while> ::= "while" <condition> <module>

<until> ::=  <module> "until" <condition>

<condition> ::= condition

Q1003

STOP+THINK

Draw a flow chart:
 

If the light is red, STOP and remain stopped until green.

Otherwise GO.

while red, stop. Then Go

STOP

RED

GREEN

GO

Q1003

STOP+THINK

You are a self-driving car engineer.

What's wrong with the logic here?

Q1003

STOP+THINK

If the light is red, STOP.
If light is green and no cars, go -
otherwise STOP.
If stale yellow, STOP -

otherwise GO.

STOP+THINK

Fix this flow chart!

Q1005

STOP+THINK

Draw the flow chart.

 

If A and If B then do C.
Otherwise, do D.

Work until you drop

Whistle while you work

If you can't be with the one you love, love the one you're with.

If all else fails, read the instructions

If at first you don't succeed, try, try, try again.

STOP+THINK

Draw flow charts for these sayings:

How to find wildlife rehab

hurt or sick?

feathered?

nestling

intact?

see nest?

safe?

put in nest

parents?

make nest

put in nest

parents?

leave

leave

put in bushes

parents?

leave

wildlife rehab

wildlife rehab

leave

wildlife rehab

fledgling

Y

Y

Y

Y

Y

Y

Y

Y

Q: How would you redraw this flowchart in "standard" form?

How to find wildlife rehab

hurt or sick?

feathered?

nestling

intact?

see nest?

safe?

put in nest

parents?

make nest

put in nest

parents?

leave

leave

put in bushes

parents?

leave

wildlife rehab

wildlife rehab

leave

wildlife rehab

fledgling

Y

Y

Y

Y

Y

Y

Y

Y

How to find wildlife rehab

hurt or sick?

feathered?

nestling

intact?

see nest?

safe?

put in nest

parents?

make nest

put in nest

parents?

leave

leave

put in bushes

parents?

leave

wildlife rehab

wildlife rehab

leave

wildlife rehab

fledgling

Y

Y

Y

Y

Y

Y

Y

Y

How to find wildlife rehab

hurt or sick?

feathered?

nestling

intact?

see nest?

safe?

put in nest

parents?

make nest

put in nest

parents?

leave

leave

put in bushes

parents?

leave

wildlife rehab

wildlife rehab

leave

wildlife rehab

fledgling

Y

Y

Y

Y

Y

Y

Y

How to find wildlife rehab

hurt or sick?

feathered?

nestling

intact?

see nest?

safe?

put in nest

parents?

make nest

put in nest

parents?

leave

leave

put in bushes

parents?

leave

wildlife rehab

wildlife rehab

leave

wildlife rehab

fledgling

Y

Y

Y

Y

Y

Y

Y

hurt or sick?

feathered?

nestling

intact?

see nest?

safe?

put in nest

parents?

make nest

put in nest

parents?

leave

leave

put in bushes

parents?

leave

wildlife rehab

wildlife rehab

leave

fledgling

Y

Y

Y

Y

Y

Y

Y

How to find wildlife rehab

wildlife rehab

hurt or sick?

feathered?

nestling

intact?

see nest?

safe?

put in nest

parents?

make nest

put in nest

parents?

leave

leave

put in bushes

parents?

leave

wildlife rehab

wildlife rehab

leave

fledgling

Y

Y

Y

Y

Y

Y

Y

How to find wildlife rehab

wildlife rehab

hurt or sick?

feathered?

nestling

intact?

see nest?

safe?

put in nest

parents?

make nest

put in nest

parents?

leave

leave

put in bushes

parents?

leave

wildlife rehab

wildlife rehab

leave

fledgling

Y

Y

Y

Y

Y

Y

Y

How to find wildlife rehab

wildlife rehab

hurt or sick?

feathered?

nestling

intact?

see nest?

safe?

put in nest

parents?

make nest

put in nest

parents?

leave

leave

put in bushes

parents?

leave

wildlife rehab

wildlife rehab

leave

fledgling

Y

Y

Y

Y

Y

Y

Y

wildlife rehab

How to find wildlife rehab

wildlife rehab

hurt or sick?

feathered?

nestling

intact?

see nest?

safe?

put in nest

parents?

make nest

put in nest

parents?

leave

leave

put in bushes

parents?

leave

wildlife rehab

wildlife rehab

leave

fledgling

Y

Y

Y

Y

Y

Y

Y

wildlife rehab

How to find wildlife rehab

wildlife rehab

hurt or sick?

feathered?

nestling

intact?

see nest?

safe?

put in nest

parents?

make nest

put in nest

parents?

leave

leave

put in bushes

parents?

leave

wildlife rehab

wildlife rehab

leave

fledgling

Y

Y

Y

Y

Y

Y

Y

wildlife rehab

How to find wildlife rehab

wildlife rehab

hurt or sick?

feathered?

nestling

intact?

see nest?

safe?

put in nest

parents?

make nest

put in nest

parents?

leave

leave

put in bushes

parents?

leave

wildlife rehab

wildlife rehab

leave

fledgling

Y

Y

Y

Y

Y

Y

Y

wildlife rehab

How to find wildlife rehab

wildlife rehab

hurt or sick?

feathered?

nestling

intact?

see nest?

safe?

put in nest

parents?

make nest

put in nest

parents?

leave

leave

put in bushes

parents?

leave

wildlife rehab

wildlife rehab

leave

fledgling

Y

Y

Y

Y

Y

Y

Y

wildlife rehab

How to find wildlife rehab

wildlife rehab

hurt or sick?

feathered?

nestling

intact?

see nest?

safe?

put in nest

parents?

make nest

put in nest

parents?

leave

leave

put in bushes

parents?

leave

wildlife rehab

wildlife rehab

leave

fledgling

Y

Y

Y

Y

Y

Y

Y

wildlife rehab

How to find wildlife rehab

wildlife rehab

hurt or sick?

feathered?

nestling

intact?

see nest?

safe?

put in nest

parents?

make nest

put in nest

parents?

leave

leave

put in bushes

parents?

leave

wildlife rehab

wildlife rehab

leave

fledgling

Y

Y

Y

Y

Y

Y

Y

wildlife rehab

wildlife rehab

How to find wildlife rehab

wildlife rehab

How to find wildlife rehab

hurt or sick?

feathered?

nestling

intact?

see nest?

safe?

put in nest

parents?

make nest

put in nest

parents?

leave

leave

put in bushes

parents?

leave

wildlife rehab

wildlife rehab

leave

wildlife rehab

fledgling

Y

Y

Y

Y

Y

Y

Y

wildlife rehab

wildlife rehab

Q1020.

I scored an amazing summer practicum washing pots in a restaurant. My boss is a computational thinker and wants me to post a flowchart describing the pot-washing process on the wall behind the pot-washing sinks. Here are her instructions:

Scrub until clean. Rinse until clear. Inspect. If not OK, start over.

Proceed Stepwise: (1) Pseudocode; (2) Outside; (3) Inside

Q1020.

                      I scored an amazing summer practicum washing pots in a restaurant. My boss is a computational thinker and wants me to post a flowchart describing the pot-washing process on the wall behind the pot-washing sinks. Here are her instructions:

Scrub until clean. Rinse until clear. Inspect. If not OK, start over.

Proceed Stepwise: (1) Pseudocode; (2) Outside; (3) Inside

scrub
until clean
rinse
until clear
inspect
if OK, done
else, start over
repeat
    repeat
       scrub
    until clean
    repeat
       rinse
    until clear
    inspect
until OK

Q1020.

                      I scored an amazing summer practicum washing pots in a restaurant. My boss is a computational thinker and wants me to post a flowchart describing the pot-washing process on the wall behind the pot-washing sinks. Here are her instructions:

Scrub until clean. Rinse until clear. Inspect. If not OK, start over.

Proceed Stepwise: (1) Pseudocode; (2) Outside; (3) Inside

Q1020.

                      I scored an amazing summer practicum washing pots in a restaurant. My boss is a computational thinker and wants me to post a flowchart describing the pot-washing process on the wall behind the pot-washing sinks. Here are her instructions:

Scrub until clean. Rinse until clear. Inspect. If not OK, start over.

Proceed Stepwise: (1) Pseudocode; (2) Outside; (3) Inside

Q1021.

Q1021. Consider this algorithm for converting a number in base 10 to its base 2 representation:

Proceed Stepwise: (1) Pseudocode; (2) Outside; (3) Inside

Divide the number by two recording both the quotient and the remainder.

Write the remainder down

Take the quotient and divide it by two, recording both the quotient and the remainder.

Write the remainder to the LEFT of what's already written.

Repeat until the quotient reaches zero.

Q1021.

                Consider this algorithm for converting a number in base 10 to its base 2 representation:

Proceed Stepwise: (1) Pseudocode; (2) Outside; (3) Inside

Divide the number by two recording both the quotient and the remainder.

Write the remainder down

Take the quotient and divide it by two, recording both the quotient and the remainder.

Write the remainder to the LEFT of what's already written.

Repeat until the quotient reaches zero.

N is our number
Q = N / 2
R = remainder
Write R
Treat Q as the new N
If Q not 0, repeat


repeat
   Q = N / 2
   Write remainder
   N = Q
until Q = 0

Q1021.

                Consider this algorithm for converting a number in base 10 to its base 2 representation:

Proceed Stepwise: (1) Pseudocode; (2) Outside; (3) Inside

Divide the number by two recording both the quotient and the remainder.

Write the remainder down

Take the quotient and divide it by two, recording both the quotient and the remainder.

Write the remainder to the LEFT of what's already written.

Repeat until the quotient reaches zero.

Ryan: Introduction to Computational Reasoning Fall 2025

Here is the updated version of our card sorting robot:

Ryan: Introduction to Computational Reasoning Fall 2025

Here is the updated version of our card sorting robot:

1 D
2 C
3 IFN1 8 # swap
4 IFN2 20 # START OVER
5 U 
6 E   
7 GOTO 1
8 N        #swap initiate
9 U
10 E
11 S
12 D
13 W
14 U
15 N
16 D
17 E
18 S      #swap complete
19 GOTO 2
20 H         #IF AT END
21 GOTO 1

2 C

FLAG=-1

SWAP

1 D

5U
6E

FLAG=-2

20 H

Ryan: Introduction to Computational Reasoning Fall 2025

Tweak the flowchart so that it has an exit

1 D
2 C
3 IFN1 8 # swap
4 IFN2 20 # START OVER
5 U 
6 E   
7 GOTO 1
8 N        #swap initiate
9 U
10 E
11 S
12 D
13 W
14 U
15 N
16 D
17 E
18 S      #swap complete
19 GOTO 2
20 H         #IF AT END
21 GOTO 1

set sorted = true

set sorted = false

2 C

FLAG=-1

SWAP

1 D

5U
6E

FLAG=-2

20 H

NOT SORTED

exit

What do we need for that "if not sorted" to work?

2 C

FLAG=-1

SWAP

1 D

5U
6E

FLAG=-2

20 H

Flow chart for "move all cards up"

Swap two cards (IRIS)

Swap first and last card

Sort 

Perceptron learning algorithm

8 queens

Graph search.

https://docs.google.com/drawings/d/1-pneUTYTj9YEm4qI3R66KvOqEXcfHTnE4JPH4ZszZME/edit?usp=sharing

https://docs.google.com/drawings/d/1V4CkFr788xVPtfxIZsvQoNAosbi03Zf4UdiNSMfSDXc/edit?usp=sharing

NEXT Abstraction
Modularity
Stepwise refinement

\wedge\text{ means AND} \\ \vee \text{ means OR} \\ \neg \text{ means NOT}
B_r = \{x | x \in A \wedge r(x)\}

Read Niklaus Wirth's 1971 classic "Program Development by Stepwise Refinement."


Some Notation: In logic we call a condition, p, which is true of a thing, x, a predicate and we write it p(x).  

 

 

 

In set theory the symbol      means "is a member of" and the symbol         means "is a subset of (or is the same set)."

 

And the expression                                                means "The set B sub r is all x's such that x is an element of A and the predicate r holds for x."

 

On page 153 the author says find a representation p(x) of in the form

This means identifying two things that must be true of a possible solution for it to be a solution. In the case of the 8 queens problem where p is "the queens are arranged in a manner than none can attack another" can be broken down into two conditions: r = "one queen in each column" and q = "no queens share a diagonal or row."

\in
\subseteq
p(x) = q(x) \wedge r(x).

Flow

By Dan Ryan

Flow

CT2025 thinking visually in flow charts

  • 733