Programming in Python · Lesson 1
Computational Thinking
Algorithms, decomposition, pattern identification, and abstraction as foundations for Python problem solving.
Lesson purpose
Computational thinking turns an everyday problem into a precise, testable solution. Python programs are implementations of algorithms, so planning the logic before writing syntax reduces errors and makes solutions easier to improve.
Learning objectives
- Define an algorithm and a computer program.
- Evaluate algorithms for input, output, finiteness, precision, and effectiveness.
- Use structural, functional, and object-oriented decomposition.
- Recognize fill-in-the-blank, repetitive, and classification patterns.
- Use abstraction and black-box thinking at an appropriate level of detail.
1. Algorithms
An algorithm is a finite series of clear steps for solving a problem or completing a task. A computer program is those instructions expressed in a programming language and executed by a device. Everyday examples include route planning, search ranking, login verification, and a recipe.
A dependable algorithm has:
- Input: the allowed starting data.
- Output: one or more results.
- Finiteness: it eventually stops.
- Precision: each step is unambiguous.
- Effectiveness: it produces the correct result.
There can be several correct algorithms for one task. Computer scientists compare efficiency because a solution that works for ten records may become impractical for ten million. Ask students to write two ways to travel to a familiar location and identify which uses fewer decisions or repeated actions.
2. Decomposition
Decomposition divides a complex application or problem into smaller, understandable parts. It lowers cognitive load and allows a team to work on cohesive pieces with fewer dependencies.
Structural decomposition
Identify a hierarchy of building blocks. Use a top-down diagram and label nodes with nouns or noun phrases. For a mobile banking app, units might include accounts, transfers, authentication, notifications, and reporting.
Functional decomposition
Break a unit into actions, processes, or steps. Use verb phrases and sequence them left to right: authenticate user → choose account → enter amount → validate transfer → display confirmation.
Object-oriented decomposition
Identify objects representing people, places, or things. Each object has attributes (nouns such as balance or address) and methods (verbs such as deposit or verify). Connections show where objects share data.
Good decomposition minimizes dependencies—changing one part should not force unrelated changes—and maximizes cohesion—each part performs one logical task or represents one entity.
3. Pattern identification
Pattern identification finds similarities among procedures or data so a common solution can be reused. A fill-in-the-blank pattern replaces a changing value with a named placeholder. A repetitive pattern can be expressed as “repeat this step” instead of listing the same step many times. A classification pattern groups things with shared attributes and can lead to a reusable class or template.
Check: What pattern appears in a program that validates every item in a list? What attributes would identify all students in a roster?
4. Abstraction and black boxes
Abstraction hides unnecessary detail, substitutes a general idea for a specific value, and lets one algorithm work with many inputs. A descriptive placeholder such as last_number is more useful than hard-coding one particular number.
A class such as LoginCredentials can abstract the shared structure of many accounts: user_id, user_password, and mobile_number. A black box accepts input, performs a process, and returns output without requiring the user to know its internal implementation. Python’s built-in functions are familiar black boxes.
Choose the right level: hiding too little overwhelms the reader; hiding too much makes the plan unusably vague. Ask students to explain what a navigation app hides from a rider and what detail a developer still needs to specify.
Classroom application
- In groups, write a travel algorithm for walking, biking, driving, or taking a bus to a familiar destination.
- Exchange algorithms and critique missing inputs, ambiguous steps, or steps that never terminate.
- Decompose a campus event-registration app structurally, then choose one unit and decompose it functionally.
- Rewrite one repeated procedure with a placeholder and explain what the placeholder abstracts.
Common misconceptions
- An algorithm is the logic; Python is one way to express that logic.
- Decomposition is how a problem is divided; it is not the same thing as the step-by-step algorithm produced afterward.
- A black box is not mysterious or unsafe; it is an interface that intentionally hides implementation detail.
- “More detailed” is not always better. The best abstraction exposes what the current reader needs.
Lesson summary
Computational thinking provides a repeatable path from problem to program: define a good algorithm, decompose complexity, identify reusable patterns, and abstract details to the level that supports the task.
Course Notes