Download presentation
Presentation is loading. Please wait.
1
Topic 1: Problem Solving
Abstraction
2
Problem Solving: Abstraction
When it comes to creating a solution for a problem, there may be times when there is too much information Data that isn’t needed for the solution Stripping away (or hiding) this information is known as abstraction Keeping only the key details/pieces of information needed to solve the problem There are multiple types of abstraction, that deal with removing different details Making the problem simpler to understand Making the solution easier to understand Problem Solving: Abstraction
3
Abstracting the Problem
This type of abstraction involves removing unnecessary information from the problem itself For example, if the problem involves calculating the number of computers needed in a lab, we may not need to know The tutor’s name The types of computer What programs the computers will be running If this information is included in the problem, we can hide it and only focus on the bits we need Problem Solving: Abstraction
4
Abstracting the Problem
For example, take this problem: Casey is playing a game with her students in school. She has six boxes in front of her, each for a subject (Maths, Biology, Physics, Chemistry, Geography, and History). She asks one of her students to roll a die, and depending on the number picks a random question from one of the boxes (1 Maths, 2 Biology, 3 Physics, 4 Chemistry, 5 Geography, 6 History) and then asks the student that rolled the die that question. If they get it right, they earn a point. If they don’t, any student can answer the question (and earn a point if they get it right). In either case, the next student rolls the die and repeats the same steps. Problem Solving: Abstraction
5
Abstracting the Problem
We can ‘cross out’ any unnecessary information (leaving only what we need to solve this problem) Casey is playing a game with her students in school. She has six boxes in front of her, each for a subject (Maths, Biology, Physics, Chemistry, Geography, and History). She asks one of her students to roll a die, and depending on the number picks a random question from one of the boxes (1 Maths, 2 Biology, 3 Physics, 4 Chemistry, 5 Geography, 6 History) and then asks the student that rolled the die that question. If they get it right, they earn a point. If they don’t, any student can answer the question (and earn a point if they get it right). In either case, the next student rolls the die and repeats the same steps. Problem Solving: Abstraction
6
Abstracting the Problem
We can also use decomposition to abstract the problem Here we can take the problem itself And break it into steps With sub-steps as needed This then makes the problem easier to read Making a solution easier to make A student rolls a die Picks a question (based off die roll) Student asked that question If they get it right, they get a point Otherwise any other student can answer (and get the point) Move on to next student Repeat from point 1 Problem Solving: Abstraction
7
Problem Solving: Abstraction
See if you can reduce the following problem to a more abstract form A student is working on creating a Checkers game. Once the game has the board set up, they need to repeat the user and the computer taking turns until one of them wins. Each turn, a player can move a piece diagonally. The game needs to consider crowning a piece if it reaches their opponents side, and letting pieces take other pieces (by jumping over them). A player wins when their opponent has no pieces left. Problem Solving: Abstraction
8
Abstracting the Solution
The other form of abstraction comes into play when we have a solution, which comes into two places Abstracting the solution itself Abstracting the data in the solution Abstracting the data means taking the data from the ‘real world’ And thinking about it in more general terms Problem Solving: Abstraction
9
Abstracting the Solution
For example, we have a cat Certain fur colour Tail length Eye colours We don’t need to know the details Only the general structure Also an example of information hiding Though more obvious on practice Used in public, private, protected Problem Solving: Abstraction
10
Abstracting the Solution
When it comes to abstracting the solution, we tend to do that during implementation Can also prepare for it during the design of a solution There are ‘sub-types’ of abstraction here, but they all affect the code we enter for the solution These are Procedural Abstraction Functional Abstraction Data Abstraction Used in programming the solution (to make it easier to read) Problem Solving: Abstraction
11
Abstracting the Solution
Procedural Abstraction involves breaking parts of a solution off into their own procedure Takes the ‘complexity’ away from the actual solution Means we don’t need to know how that part is done Only that it works as intended A very important part to any complex solution The procedure we make ends up not caring about the data used Only how it works We supply the data when we run this procedure Here register_user is the abstracted procedure Problem Solving: Abstraction
12
Abstracting the Solution
Functional Abstraction works similarly Involves functions instead of procedures That means a value is expected after running the function When designing/implementing, we still don’t care how this function works As long as it does what we expect Here length_between_points is the abstracted function Problem Solving: Abstraction
13
Abstracting the Solution
Finally, Data Abstraction comes back to what we were talking about earlier With the Cat When thinking about data (especially in the design), we don’t care how we represent this data For example, we need to represent ‘students’ in a program What information do we need for a ‘Student’ How do we store multiple ‘Students’ The solution doesn’t care how we do this It’s up for us to decide when programming Problem Solving: Abstraction
14
Other Forms of Abstraction
There are other uses of abstraction as well Not just related to problems and solutions For example, high-level programming languages They are abstractions of the more complex low- level languages They make it easier to tell the computer to do something When using high-level languages, we don’t care how the computer does something We only tell it to do something Problem Solving: Abstraction
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.