Skip to content

Computational Thinking | AP - Wyatt's Notes

What Is Computational Thinking? (CED Unit 1)

Section titled “What Is Computational Thinking? (CED Unit 1)”

Computational thinking is a problem-solving approach that involves breaking down complex problems, Finding patterns, abstracting details, and designing step-by-step solutions. It is not about Thinking like a computer — it is about expressing problems in a way that a computer can solve.

  1. Decomposition: Breaking a complex problem into smaller, manageable subproblems.
  2. Pattern Recognition: Finding similarities or trends within or between problems.
  3. Abstraction: Focusing on essential information while ignoring irrelevant details.
  4. Algorithm Design: Developing a step-by-step procedure to solve the problem.

Why these four matter together. Decomposition tells you what the subproblems are. Pattern Recognition tells you which subproblems are instances of problems you already know how to solve. Abstraction tells you which details matter for each subproblem. Algorithm design turns the Abstracted subproblems into precise, executable steps.

Worked Example. Design a program to manage a school library.

  • Decomposition: Book cataloguing, user management, borrowing/returning, overdue tracking, search functionality.
  • Pattern Recognition: Searching for a book and searching for a user follow the same pattern (linear or binary search on a sorted list). Borrowing and returning both modify the same data structure (a loan record).
  • Abstraction: A “book” is represented by its ISBN, title, author, and availability status. We do not need to model the physical book”s condition, shelf location, or cover colour.
  • Algorithm Design: Write pseudocode for each operation: add_book, search_book, borrow_book, return_book, calculate_fine.

Worked Example. Design a program to calculate the average exam score for a class, excluding the Highest and lowest scores.

  • Decomposition: Read scores, find min and max, remove them, calculate average.

  • Pattern Recognition: Finding min and max are the same pattern (scan all elements, track the extreme).

  • Abstraction: A “score” is a number. We do not need the student’s name or subject.

  • Algorithm Design:

    PROCEDURE trimmedAverage(scores)
    {
    min <- findMin(scores)
    max <- findMax(scores)
    sum <- 0
    count <- 0
    FOR EACH score IN scores
    {
    IF (score <> min AND score <> max)
    {
    sum <- sum + score
    count <- count + 1
    }
    }
    RETURN(sum / count)
    }

Abstraction is the process of reducing complexity by hiding unnecessary details and exposing only The essential features.

  • Simplifies complex systems by providing a manageable interface.
  • Allows programmers to work with high-level concepts without worrying about low-level implementation.
  • Enables code reuse and modularity.

Concrete example. When you drive a car, you use the steering wheel, pedals, and gear stick. You Do not need to know how the fuel injection system works, how the transmission gears mesh, or how the ABS sensors communicate with the brake controller. The car’s interface abstracts away these details. Similarly, a programmer using a sort() function does not need to know whether it uses merge sort, Quick sort, or heap sort — only that it sorts correctly.

LevelExampleDetail Level
HighA web browserVery low
MediumHTML/CSS/JavaScriptModerate
LowOperating system callsHigh
Very lowMachine code / binaryVery high
HardwareLogic gates, transistorsMaximum

Moving down the ladder reveals more detail. Moving up hides detail behind simpler interfaces. The Key insight of abstraction is that you rarely need to go all the way down — you work at the level Appropriate to the problem.

A procedure (function/method) provides a named interface that hides its implementation. The caller Only needs to know what the procedure does (its specification), not how it does it.

Benefits:

  • Readability: descriptive names document intent.
  • Reusability: write once, call many times.
  • Modifiability: change the implementation without affecting callers.

Formal notion: preconditions and postconditions. A procedure’s contract specifies what must be True before it is called (precondition) and what it guarantees after it returns (postcondition). The Implementation can change as long as it satisfies this contract.

Data abstraction separates the interface (what operations are available) from the implementation (how the data is stored and manipulated).

In Java, this is achieved through classes: private fields with public getters/setters and methods.

Information hiding is the principle that the internal details of a module should be hidden from Other modules. Only the public interface is exposed. This reduces coupling between modules, making The system easier to understand, test, and modify.

In Java, the private keyword enforces information hiding. A private field cannot be accessed Directly from outside the class, forcing callers to use the public methods.

Example of poor vs good abstraction:

// Poor: exposes internal representation
public class Student {
public int[] grades; // caller can modify directly
}
// Good: hides internal representation
public class Student {
private int[] grades;
public void addGrade(int grade) { ... }
public double getAverage() { ... }
}

AP CSP uses a specific pseudocode notation. Key constructs:

a <- 10
b <- a + 5
IF (condition)
{
<block of code>
}
ELSE
{
<block of code>
}

Nested conditionals:

IF (score >= 90)
{
DISPLAY("Grade A")
}
ELSE IF (score >= 80)
{
DISPLAY("Grade B")
}
ELSE
{
DISPLAY("Grade C or below")
}

REPEAT n TIMES:

REPEAT 5 TIMES
{
DISPLAY(i)
}

REPEAT UNTIL:

REPEAT UNTIL (condition)
{
<block of code>
}

FOR EACH:

FOR EACH item IN list
{
DISPLAY(item)
}
PROCEDURE name(parameter1, parameter2)
{
<block of code>
RETURN(value)
}
list <- [1, 2, 3, 4, 5]
list[1] <- 10
APPEND(list, 6)
REMOVE(list, 3)
INSERT(list, 2, 99)
LENGTH(list)

Computer science is about solving problems efficiently. Algorithms are like recipes - step-by-step procedures for accomplishing tasks. Data structures are containers that organise information for efficient access and modification. The art of computer science lies in choosing the right algorithm and data structure for each problem, balancing speed, memory, and complexity.