Computational Thinking - Chapter 1: Problem-Formulation and Analysis
Hello everyone! Welcome to your study notes for "Problem-Formulation and Analysis". This is the very first and most important step in the world of programming and problem-solving. Think of it like being a detective: before you can solve a mystery, you first need to understand exactly what the case is about!
In this chapter, we'll learn how to look at a problem, break it down, and plan our attack before writing a single line of code. Getting this part right makes everything that follows much, much easier. Let's get started!
1. Defining the Problem and its Scope
Before you can solve a problem, you must know exactly what you're trying to achieve. This sounds obvious, but it's a step that many people rush through!
Problem Definition is the process of clearly and precisely stating the problem you want to solve. What is the main goal?
Scope means defining the boundaries of your problem. What is included, and just as importantly, what is not included? This prevents the project from becoming too big and complicated.
Analogy: Planning a Birthday Party
Imagine you're asked to "plan a birthday party". That's a bit vague! A good problem definition would be:
Problem: "Organise a surprise birthday party for my friend, Chan Tai Man."
Scope: "The party will be for 15 guests, held on a Saturday night, with a budget of $2000. We need to handle invitations, food, and a birthday cake. We will NOT be arranging transport for the guests."
See? Now the task is crystal clear. In ICT, defining the problem and scope means you know exactly what your program is supposed to do, and what it's not supposed to do.
**************************************************
QUICK REVIEW
**************************************************
- Define the Problem: What is the main goal? Be specific!
- Define the Scope: What are the limits and boundaries? What are we NOT doing?
**************************************************
2. The IPO Model: Your Problem-Solving Blueprint
Once we know our problem, we need to figure out the major parts of the solution. We use a simple but powerful model called IPO, which stands for Input, Process, and Output.
Analogy: Baking a Cake
Think about baking a cake. You can't just get a cake out of thin air! You need ingredients, you need to follow a recipe, and then you get your final product.
- INPUT: The ingredients you need. (e.g., flour, sugar, eggs, milk)
- PROCESS: The steps you take. (e.g., mix the ingredients, put it in the oven, bake for 30 minutes)
- OUTPUT: The final result. (e.g., a delicious cake!)
Computer programs work in the exact same way!
Breaking down IPO for ICT Problems
Input: What information or data does the program need from the user or a sensor to get started?
Process: What calculations, steps, or operations does the program need to perform on the inputs?
Output: What is the final result that the program shows to the user?
Example from the Syllabus: BMI Calculator
Let's analyse the problem of "Find the Body Mass Index (BMI) to monitor healthy weight" using the IPO model.
- Input: To calculate BMI, the program needs two things from the user:
- The user's weight (e.g., in kg)
- The user's height (e.g., in metres)
- Process: The program takes the inputs and performs a calculation. The formula for BMI is Weight ÷ (Height x Height).
- Calculation: BMI = weight / (height * height)
- Output: The program displays the result of the calculation.
- The calculated BMI value (e.g., 22.5)
- A message to the user (e.g., "Your weight is in the healthy range.")
Key Takeaway
Always think IPO! For any problem, ask yourself: What do I need to start with (Input)? What do I need to do (Process)? What should the final result be (Output)? This simple structure will help you organise your thoughts for any programming task.
3. Decomposition: Making Big Problems Small
Don't worry if a problem seems huge and impossible at first! We use a technique called decomposition, which is just a fancy word for breaking a large problem down into smaller, more manageable sub-problems.
Analogy: Building with LEGO
When you build a big LEGO model of a car, you don't try to stick all 500 pieces together at once. The instruction manual shows you how to build smaller parts first:
- Sub-problem 1: Build the chassis (the base).
- Sub-problem 2: Build the wheels and attach them.
- Sub-problem 3: Build the body of the car.
- Sub-problem 4: Build the interior and the roof.
By solving each sub-problem one by one, you eventually solve the big problem of building the entire car.
Decomposition in ICT
We can decompose a problem by breaking it down into its IPO steps, or even breaking those steps down further.
Example: A Simple Vending Machine Program
Big Problem: Create a program to simulate a simple vending machine.
Let's decompose this:
- Sub-problem 1 (Input): Display the drinks available and ask the user to make a choice. - Sub-problem 2 (Input): Ask the user to insert money. - Sub-problem 3 (Process): Check if the user inserted enough money. - Sub-problem 4 (Process): If they did, calculate the change. - Sub-problem 5 (Output): Dispense the drink (show a message). - Sub-problem 6 (Output): Give back the correct change.
By tackling these six smaller problems, the overall task becomes much less scary!
Key Takeaway
Decomposition is your best friend for complex tasks. If a problem feels overwhelming, break it down! Solve the small pieces first, and then put them together.
4. Pattern Recognition: Finding Similarities
The final step in analysing a problem is to look for patterns. Pattern recognition is about identifying common elements or similarities across different problems (or even within the same problem).
Why do this? Because if you've solved something similar before, you can reuse parts of that solution! It's all about working smarter, not harder.
Analogy: Learning Recipes
Once you learn the basic pattern for making a stir-fry (heat oil, add garlic, add vegetables, add protein, add sauce), you can create hundreds of different dishes. The pattern is the same; you just change the specific ingredients. You don't need to learn a completely new method for chicken stir-fry and then another for beef stir-fry.
Example from the Syllabus: Sorting Students
- Problem A: Sort a group of students by their height in ascending order (shortest to tallest). - Problem B: Sort the same group of students by their exam score in descending order (highest to lowest).
What's the pattern?
The core process is the same for both problems: you compare two students at a time and swap them if they are in the wrong order.
How can we reuse the solution?
The basic sorting algorithm is identical. The only things that change are:
1. The piece of data you are comparing (height vs. score).
2. The comparison logic (less than for ascending vs. greater than for descending).
Example from the Syllabus: Programming a Robot
- Problem A: Program a robot to move in a square. - Problem B: Program a robot to move in a triangle.
What's the pattern?
The general pattern for drawing a regular shape is: "Repeat N times: move forward a set distance, then turn a certain angle."
How can we reuse the solution?
- For a square: Repeat 4 times (move forward, turn 90 degrees).
- For a triangle: Repeat 3 times (move forward, turn 120 degrees).
By recognizing this pattern, you can easily modify your square program to make the robot draw a triangle, a pentagon, or any other polygon, just by changing the number of repeats and the turning angle.
Did you know?
Pattern recognition is a key part of how services like Netflix and Spotify recommend movies and music to you. They look for patterns in what you like and find other users with similar tastes to suggest what you might like next!
Key Takeaway
Always look for patterns and similarities. It allows you to reuse existing solutions, saving you time and effort, and helps you solve new problems more efficiently.