lesson

Updated 6 days ago ยท 2 views
Imagine trying to build a giant Lego spaceship with one thousand pieces all at once. If you dump all the bricks out and try to snap them together in one second, it feels impossible!
In computer science, decomposition means breaking a big problem down into smaller, easier pieces called sub-problems.
๐Interactive diagram
How do we use this decomposition superpower to solve tricky story problems?
Step-by-Step Story Problems
Read this puzzle: "Leo has 12 apples. He picks 8 more in the garden, and then gives 5 apples to Maya. How many apples does Leo have now?"
Instead of guessing the final number right away, we split the story into two smaller steps.
๐Interactive diagram
By solving Step 1 first, we found Leo had 20 apples. Then Step 2 was simple: 20 minus 5 gives our final answer of 15.
What does this look like when we want a computer to solve the steps for us?
Writing Steps in Code
Programmers write each sub-problem as a single instruction using a variable, which is a labeled container that stores a value.
๐Interactive diagram