0% found this document useful (0 votes)
46 views

T1 Decomposition and Abstraction

The document discusses computational thinking concepts including decomposition, abstraction, and algorithms. It explains how decomposition involves breaking problems into smaller subproblems and abstraction removes unnecessary details to focus on essential components. Algorithms are defined as sets of instructions to solve problems. Subprograms are introduced as a way to break problems into reusable parts.

Uploaded by

rukh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

T1 Decomposition and Abstraction

The document discusses computational thinking concepts including decomposition, abstraction, and algorithms. It explains how decomposition involves breaking problems into smaller subproblems and abstraction removes unnecessary details to focus on essential components. Algorithms are defined as sets of instructions to solve problems. Subprograms are introduced as a way to break problems into reusable parts.

Uploaded by

rukh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Objectives

• Understand the benefits of solving problems and


modelling the real world using:
• Decomposition
• Abstraction

• Understand the benefits of using subprograms


Decomposition and abstraction
Unit 1 Computational thinking

Starter
• Computer Science is about studying problems and
how to solve them
• Discuss some solutions to the following:
• How can you route pieces of information across a network to
the other side of the world?
• How can you make the images in a computer game look
more realistic?
• How can you program a computer to work out the
school timetable?
• How can you search 1,000,000 items quickly?
Decomposition and abstraction
Unit 1 Computational thinking

Starter
• The answers to these problems are too long to
write here – some aspects that you may have
considered in your discussions
• Some problems such as ‘how can you search 1,000,000 items
quickly?’ require a specific algorithm to be considered
• There may be many different algorithms that solve the
same problem
• Problems such as ‘How can you make the images in a computer
game look more realistic?’ need abstractions, where we
consider the important components of a realistic image
• Routing items of data around the world requires many different
protocols. This is a result of decomposing the problem into
smaller tasks
Decomposition and abstraction
Unit 1 Computational thinking

What is an algorithm?
Decomposition and abstraction
Unit 1 Computational thinking

Algorithms
• An algorithm is a set of instructions for solving a
problem or completing a task
• The task could be:
• Making a chocolate cake
• Summing the numbers 1 to 1000
• Building a Lego model
• Think of some more …
Decomposition and abstraction
Unit 1 Computational thinking

Strategies for problem-solving


• One strategy for solving a large problem is to first try
and solve a similar but smaller problem
• How do you set about doing a jigsaw puzzle?
Decomposition and abstraction
Unit 1 Computational thinking

Algorithmic thinking
• Solving these puzzles involves algorithmic thinking
• If you are using a computer to find the answer, you
have to figure out how to solve the problem, and
then write down the steps
• Not all solutions are equally efficient
Decomposition and abstraction
Unit 1 Computational thinking

Divide and conquer


• Here is a problem
• Ask a friend to think of a number between
1 and 1000
• Guess the number by asking: “Is the number greater
than n?” (where n is your guess)
• How many guesses will you need to find the number?
Decomposition and abstraction
Unit 1 Computational thinking

Worst case scenario


• Search for the number at the mid-point (500)
• If it’s the number we are searching for, then stop
• If it’s lower than 500, then search at the mid point of the lower
numbers (250)
• Otherwise, if it’s higher than 500, then search at the mid point
of the higher numbers (750)
• The worst case scenario for this algorithm would be
a search for numbers such as ‘1’ or ‘367’
• With this algorithm, any number can be guessed within
10 guesses
• 1 = 500,250,125,63,32,16,8,4,2,1
• 367 = 500,250,375,312,344,360,368,364,366,367
Decomposition and abstraction
Unit 1 Computational thinking

Worksheet 1
• Now complete Task 1 on Worksheet 1
Decomposition and abstraction
Unit 1 Computational thinking

Abstraction
• Abstraction involves removing unnecessary detail
from a problem so that you can focus on the
essential components
• The London Underground map is a good example
of abstraction
Decomposition and abstraction
Unit 1 Computational thinking

Modelling the real world


• We often build models that are
simplified versions of the
real world
• These will remove
unnecessary details
• What are the details that
have been removed in this
model house?
• What functionality may have
been built into the house?
Decomposition and abstraction
Unit 1 Computational thinking

Modelling the real world


• Some details removed from the model house
• House number
• Letterbox
• Internal wall paper

• Possible functionality built in


• Open/close doors
• Turn on/off lights
• Play sound effects

• When we create programs, functionality is


implemented using subprograms
Decomposition and abstraction
Unit 1 Computational thinking

Using abstraction
• Real world dice have many properties, such as their
temperature, size and curved edges
• When you write a program to play a game involving
dice with a computer, the
programmer needs to use
abstraction to remove
unnecessary details.
This models the
real world
• How does the program
‘roll the dice’?
Decomposition and abstraction
Unit 1 Computational thinking

Rolling dice
• When a computer rolls a dice we can use
abstraction to remove many unnecessary details
• It will depend on the problem being solved as to what is and
isn’t important
• A computer game may need to show a graphical
representation of a dice, but they may be able to abstract
away all the details about the surface it rolls onto and the
physics of the bounce
• Many programs just need a random number. In which case
they don’t need to worry about how the dice appears, its
weight or how the spots are arranged – they can just find a
random number with one line of programming code
Decomposition and abstraction
Unit 1 Computational thinking

Decomposition
• Decomposition involves breaking down a large
problem into smaller sub-problems
• Then the sub-problems can be broken down further
until each small task is manageable
Decomposition and abstraction
Unit 1 Computational thinking

Decomposing a dice game


• Suppose you want to create a dice game to be
played on the computer
• You need to think of the main tasks that need to be
performed – for example:
• Display the rules
• Establish whether this particular game is to be a two-player
game, or one person against the computer
• Display the ‘board’ if there is one
• Play the game
• Display the result when the game is over
Decomposition and abstraction
Unit 1 Computational thinking

Decomposition - advantages
• The problem becomes easier to solve when it
consists of a number of small subtasks
or subprograms
• Some subprograms may be reusable in other
programs, saving development time
Decomposition and abstraction
Unit 1 Computational thinking

Structure diagrams
• A structure diagram is used to show how a problem
is broken down
• It will show subtasks which accomplish an identifiable task
and their links to other subtasks
Decomposition and abstraction
Unit 1 Computational thinking

Benefits of subprograms
• In the dice program one subprogram might be
showResults()
• The code for this may be:
def showResults():
for result in resultsTable:
print(result)
• Another subprogram may be rollDice(6)
• A different programmer has developed this function. The
programmer just calls it to get a dice roll between 1 and 6
• What are the benefits of using subprograms?
Decomposition and abstraction
Unit 1 Computational thinking

Benefits of subprograms
• Subprograms can be reused many times in
a program
• There may be many times in the dice game that we need to
show the results. By using the subprogram displayResults()
the programmer can reuse this whenever they need to
• This reduces the amount of code needed

• Code will be easier to maintain and have fewer bugs


• It makes it easier to adapt the program – if displayResults() is
updated or a bug fixed then it would be fixed everywhere that
displayResults() is called
Decomposition and abstraction
Unit 1 Computational thinking

Worksheet 1
• Now complete Task 2, Task 3 and Task 4 on
Worksheet 1
Decomposition and abstraction
Unit 1 Computational thinking

Plenary
• With a partner define the following terms:
• Abstraction
• Decomposition
• Algorithm
Decomposition and abstraction
Unit 1 Computational thinking

Plenary
• Definitions
• Abstraction – removing unimportant parts of a problem in
order to concentrate on those that are important
• Decomposition – breaking down a problem into smaller more
manageable ones
• Algorithm – a sequence of steps that are followed to complete
a task
• Note that a computer program is an implementation of an
algorithm and that an algorithm is not a computer program
Decomposition and abstraction
Unit 1 Computational thinking

© 2020 PG Online Limited

The contents of this unit are protected by copyright.

This unit and all the worksheets, PowerPoint presentations, teaching guides and other associated files
distributed with it are supplied to you by PG Online Limited under licence and may be used and copied by you
only in accordance with the terms of the licence. Except as expressly permitted by the licence, no part of the
materials distributed with this unit may be used, reproduced, stored in a retrieval system, or transmitted, in any
form or by any means, electronic or otherwise, without the prior written permission of PG Online Limited.

Licence agreement
This is a legal agreement between you, the end user, and PG Online Limited. This unit and all the worksheets,
PowerPoint presentations, teaching guides and other associated files distributed with it is licensed, not sold, to
you by PG Online Limited for use under the terms of the licence.

The materials distributed with this unit may be freely copied and used by members of a single institution on a
single site only. You are not permitted to share in any way any of the materials or part of the materials with any
third party, including users on another site or individuals who are members of a separate institution. You
acknowledge that the materials must remain with you, the licensing institution, and no part of the materials may
be transferred to another institution. You also agree not to procure, authorise, encourage, facilitate or enable any
third party to reproduce these materials in whole or in part without the prior permission of PG Online Limited.

You might also like