Decomposition and
Abstraction
Prepared For : Zaamina
Computational
Thinking
• Using special thinking
patterns and
processes to pose and
solve problems or
prepare programs for
computations.
• Simply put, it is a set
of skills that help to
set up a problem in
Portfolio Presentation
such a way that a
computer can help
you solve it.
Four pillars of Computational
Thinking
“ “
“ “
Finding Ignoring
problem similariti details in process by
Breaking certain Controlling
down into es
between order to automatic
smaller, items as a come up means,
a a
more way of with a reducing
manageable gaining solution that human
works for a intervention
parts. extra
more general to a
information.
Decomposition “ Pattern “ problem.
Abstraction “ minimum.
Algorithm “
matching (Automation)
Activity 1.
Solve Sudoku
Decompositi
on
Step 1. Work on upper-left
region (1)
Work on upper- Step 2.
right region (2)
Step 3. Work on lower-left
region (3)
Work on lower- Step 4.
right region (4)
For Region
1
Look at the numbers
that are missing in
Step 1. row 1 of the puzzle.
Look at the numbers That would be 1, 2.
that are missing in
column 1 of the puzzle. Step 2.
That would be 2
and 3. Look at the numbers
missing in region 1.
Step 3.
That would be 1, 2.
If there is only one number missing
from all three sets, that number goes Step 4.
to row 1 and column 1 in region 1.
If there is a second number
That would be missing from all three sets,
2.
Step 5. continue to the next cell and
come back when you have more
information.
For Region
2
Look at the numbers
that are missing in
Step 1. row 2 of the puzzle.
Look at the numbers That would be 1, 3.
that are missing in
column 3 of the puzzle Step 2.
That would be 2 Look at the numbers
and 3. missing in region 2.
Step 3.
That would be 1, 3.
If there is only one number missing
from all three sets, that number goes
to row 2 and column 3 regaion 2. Step 4.
That would be If there is a second number
3. missing from all three sets,
Step 5. continue to the next cell and
come back when you have more
information.
Pattern
Matching Look at the numbers
that are missing in
Look at the numbers
that are missing in
Step 1. row 1. Step 1. row 2.
That would be 1, 2. That would be 1, 3.
For region For region
1 2
Abstracti
on
Look at the numbers
that are missing in
Step 1. row X in the puzzle.
Look at the numbers That would be ...
that are missing in
column Y of the puzzle. Step 2.
That would Look at the numbers
be ... missing in region N.
Step 3.
That would be 1, 3.
If there is only one number missing
from all three sets, that number goes
to row X and column Y in region N. Step 4.
That would be If there is a second number
… missing from all three sets,
Step 5. continue to the next cell and
come back when you have more
information.
Automation
(algorithm)
Step 1.
Step 2.
For every For every cell
region Step 3. in a region
in this puzzle
Step 4.
Step 5.
Decomposition
“Journey of a thousand miles begins with a
single step.”
Lao Tzu
“When eating an elephant, take one bite at a
time”
Creighton
Abrams
Decomposition
In computing, decomposition is
the process of breaking down a
task into smaller, more-
manageable parts.
Pattern Recognition
(Matching)
Patterns are everywhere. By identifying patterns, we
can create rules and solve more-general
problems.
Abstraction
• The practice of ignoring
certain details in order to
come up with a solution that
works for a more general
problem.
• It is a way of letting go of
details to make a process
easier.
Algorithm
(Automation)
• An algorithm is a sequence of
instructions or a set of rules
to get something done.
• Algorithms are written for a
human, rather than for a
computer to understand. In
this way, algorithms differ
from programs.
Algorithm example
Flowchart
Computational
Thinking
Unplugged Lesson in Action - Binary Bracelets from
code.org
Problem-solving
Process
• Problem analysis
• Alternative
consideration
• Choosing an
approach
• Problem
decomposition
• Algorithm
Portfolio Presentation
development
• Algorithm correctness
Problem Understanding
Is the step that leads to the identification of the problem
characteristics.
For algorithmic problems, it starts by recognizing the input
categories of the problem and the selection of the required
output category for each input category.
Basic strategies
Identify outputs
02
Identify inputs
01 03 Each input is a subtask
If yes,
how; If
not, why?
04
Extreme cases
Input/Output/
variable
What are
• Input is data sent toinputs?
a computer system from devices such as a
keyboard, mouse, microphone, camera or physical sensor.
• Input devices enable information from the outside world to get
into a computer
– without them, we wouldn’t even be able to switch the
computer on!
• Some are built in; others are plugged in or wirelessly connected.
What are outputs?
Output is data or information communicated from a computer
system to the outside world via various devices which include:
Activity 6 (a): Input/ Output
Examination
Read the following article:
https://codeburst.io/10-steps-to-
Stage A solving-a- programming-problem-
8a32d1e96d74
Read the two problem specifications
given by your instructor.
Stage B
For each of them, select a technique
learnt in Stage A to identify
input/output for each problem.
Stage C Presentation and discussion
Solution Design
Is the major challenge facing novice learners.
The examination of a given problem’s inputs and outputs
clarifies the problem to the problem solver. The next stage is
to define the variables needed to solve the problem.
Basic
Strategies
Stepwise refinement
02
Identify algorithmic patterns
Define problem variables
01 03
04
How should K-8 incorporate computer science
into their curriculum?
Variables
A variable can be
thought of as a box that
can hold one value at a
time.
Activity 6 (b): Choose problem
variables
Further analyze the problems
given in Activity 6(a).
Stage A
Identify variables needed to solve them.
- Come up with variables Stage B
needed
- Come up with guidelines for a
teacher to evaluate each Stage C Presentation and discussion
learner‘s investigation of
- Compare solutions
variables
- Summarize guidelines for a
teacher to evaluate each
learner‘s investigation of
variables
Stepwise Refinement
Is a top-down methodology that first obtains the overview of the
structure of the problem and the relationship among each parts,
and then to address specific and complex issues related to the
implementation of subpart.
refers to the progressive refinement in small steps of a
program specification into a program.
Step-wise
(top-down)
Refinement
• was used first in the paper titled
Program Development by Stepwise
Refinement by Niklaus Wirth, the
author of the programming language
Pascal and other major contributions
to software design and software
engineering, in the Communications of
the ACM, Vol. 14 (4), 1971, pp. 221-
227.
• Wirth said: "It is here considered as
a sequence of design decisions
concerning the decomposition of
tasks into subtasks and of data into
data structures."
Stepwise
• Start with the initial problem statement
• Break it into a few general steps
• Take each "step", and break it further into more detailed
steps
• Keep repeating the process on each "step", until you get a
breakdown that is pretty specific, and can be written more or
less in pseudocode
• Translate the pseudocode into real code
Stepwise Refinement (Example)
Problem Statement:
Determine the class average for a set of test grades,
input by the user. The number of test grades is not
known in advance (so the user will have to enter a
special code -- a "sentinel" value -- to indicate that
he/she is finished typing in grades).
Initial breakdown into
steps
Declare and initialize variables
Input grades (prompt user and allow input)
Compute class average and output result
Now, breaking down the "compute" step further,
we got:
Compute:
add the grades
count the grades
divide the sum by the count
Revised breakdown of steps
Declare and initialize variables
Input grades -- count and add them as they
are input
Compute class average
Breaking the steps into smaller
steps
So, now we can break down these 3 steps into more detail. The input step can roughly
break down this way:
loop until the user enters the sentinel value (-1 would be good)
prompt user to enter a grade (give them needed info, like -1 to quit)
allow user to type in a grade (store in a variable)
add the grade into a variable used for storing the sum
add 1 to a counter (to track how many grades)
Breaking the steps into smaller
steps
We could specifically write this as a while loop or as a do-while loop. So one more
refining step would be a good idea, to formulate the pseudo-code more like the actual
code we would need to write. For example:
do
prompt user to enter a grade (give them needed info, like -1 to quit)
allow user to type in a grade (store in a variable)
add the grade into a variable used for storing the sum
add 1 to a counter (to track how many grades)
while user has NOT entered the sentinel value (-1 would be good)
Breaking the steps into smaller
steps
If we look at this format, we realize that the "adding" and "counting" steps should only
be done if the user entry is a grade, and NOT when it's the sentinel value. So we can
add one more refinement:
do
prompt user to enter a grade (give them needed info, like -1 to quit)
allow user to type in a grade (store in a variable)
if the entered value is a GRADE (not the sentinel
value) add the grade into a variable used for
storing the sum add 1 to a counter (to track how
many grades)
while user has NOT entered the sentinel value (-1 would
be good)
Breaking the steps into smaller
steps
This breakdown helps us see what variables are needed, so the declare and initialize
variables step can be now made more specific:
initialize variables:
a grade variable (to store user entry)
a sum variable (initialized to 0)
a counter (initialized to 0)
Compute and print:
divide sum by counter and store result
print result
Putting it all
together
initialize variables:
a grade variable (to store user
entry) a sum variable
(initialized to 0)
a counter (initialized to 0)
grade entry:
do
prompt user to enter a grade (give them needed info, like -
1 to quit) allow user to type in a grade (store in a variable)
if the entered value is a GRADE (not the sentinel
value) add the grade into a variable used for
storing the sum add 1 to a counter (to track
how many grades)
while user has NOT entered the sentinel value (-1
would be good)
Compute average:
divide the sum by the
counter print the answer
Variables
Insert the title of your subtitle
Here
Variables are memory location used to keep
information!
• Variables are used as placeholders for values such as numbers or
words.
• Variables allow for a lot of freedom in programming.
• Instead of having to type out a phrase many times or remember
an
obscure number, computer scientists can use variables to
reference them.
What is variable?
• A variable is a simple way of storing one piece of
information somewhere in the computer’s memory while
a program is running, and of getting that information
back later.
• A variable is an example of a data structure.
• A variable can be numerical, textual or perhaps an
indicator of true/false.
• Programs can store, retrieve or change the values of
variables.
Variables used in a graphic user
interface
Variables
A variable can be thought of as a box that can hold one value
at a time.
Declaring a
variable
Before you can use a variable,
you need to claim a piece of
memory and associate it
with a name.
Activity 1: Variables Unplugged
Activity
(peer teaching)
Stage A
Prepare ppt Stage B
Stage C Teach the lesson
Discussion and reflections Stage D
Activity 2: Kidbots! (peer
teaching) Select one from the 1,2,3,4
https://csunplugged.org/en/to
Stage A pics/ kidbots/unit-plan/
Prepare ppt and other materials
Stage B
Stage C Teach the lesson
Design your own Stage D
activity.
Step E. Discussion and reflections
Cons and pros
Concept maps
is a two-dimensional, graphic
or schematic diagram
illustrating the
interconnections, and often
the
hierarchy, of a particular
concept
or topic.
How to create concept map? (1)
How to create concept map? (2)
Von Neumann Computer
Architecture • Fetch – gets the next
program command
from the computer’s
memory
• Decode – deciphers
what the program is
telling the computer
to do
• Execute – carries out
the
requested action
• Store – saves the
results to a Register
Fetch – gets the next
program command
from the computer’s
memory Decode –
deciphers what the
program is telling the
computer to do
Execute – carries out
the
requested action
Store – saves the
results to a Register
or Memory
Activity 3: Pedagogical
Examination of
ConceptStageMaps
A
Design a classroom activity that ask
students to create a concept map Stage B
on a selected subject and create
evaluation rules
Stage C Present your class room activity and
ask your peers to complete the
classroom activity
Present the concept maps . Stage D
created and evaluate them
Discussion and reflections
Main concepts should be -how can concept map .
included and the Step E. help to promote
relationship should be learning
specified - How CM help
assessment of learning
Metaphors
Are used in order to
understand and experience
one specific thing by using
an analogy to another thing,
usually a familiar concept.
Portfolio Presentation
A variable can be thought of as
a container that can hold one
value at a time.
Data
• Types
A variable in Java is designed to hold only one
particular type of data.
• There are eight primitive types built into Java.
• byte, short, int, long variables hold integers.
• float, double variables hold real numbers
• char variable holds a single character from the
Unicode character set.
• boolean variable holds one of the two logical values true
or false.
Variable
int age = 20;
Declaration
byte
nextInStream;
short hour;
long
totalNumberOfSt
ars;
float
reactionTime;
double
Classification
is used to classify objects
and phenomena from real
life to support and guide the
mental construction of
computer science
concepts.
Portfolio Presentation
Declare problem variables
Mapping problem characters to different variables
int float boolean string
Activity 4: Classification of Variable According to
Types
Stage A Study the pictures in previous
page
Sort them into different bins
Stage B
Define a variable for each
scenario
Stage C You can simply
impress your
audience and add
Design your own activity a unique zing.
You can simply Stage D
impress your
audience and add
a unique zing.
Step E. Discussion and reflections
Cons and pros
Program Control Structure (using concept
map)
Sequential: default mode.
Sequential execution of code
statements (one line after
another) -- like following a
recipe Selection: used for
decisions, branching --
choosing between 2 or more
alternative paths.
Repetition: used for looping,
i.e. repeating a piece of code
multiple times in a row.
Sequence statements
int
number1;
int
number2
int
total=0;
Scanner
input =
new
Scanner(S
ystem.in);
System.out.println("please enter the first
number"); number1 = input.nextInt();
System.out.println("please enter the second
number"); number2 = input.nextInt();