FUNDAMENTALS OF COMPUTATIONAL THINKING
Module 1
Syllabus
Logical and Algorithmic Thinking- Objectives and [Link] Solving and
Decomposition-Defining the problem, Problem decomposition, Patterns and Generalization.
Logical Thinking
Logical thinking is the ability to analyze situations, identify relationships, apply
rules, and draw valid conclusions in a structured and systematic manner.
It focuses on “why” and “how” a solution works, rather than just the final answer.
Objectives of Logical Thinking
The main objectives are:
• To understand the problem clearly
• To separate relevant and irrelevant information
• To apply conditions and rules correctly
• To arrive at error-free conclusions
• To form the basis for algorithm design and programming
Characteristics
a) Sequential reasoning
b) Use of conditions (if–then–else)
c) Elimination of irrelevant information
d) Step-by-step analysis
(a) Sequencing
Arranging actions in a correct order.
Example (Daily Activity):
1. Wake up
2. Brush teeth
3. Take bath
4. Have breakfast
Wrong sequencing leads to illogical results.
(b) Conditions (Decision Making)
Making decisions based on true/false conditions.
Example:
• If marks ≥ 50 → Pass
• Else → Fail
Used extensively in if–else logic.
(c) Comparison
Comparing values to make decisions.
Example:
• Check whether A > B
• Find the largest among numbers
(d) Cause–Effect Reasoning
Understanding how one action affects another.
Example:
• If attendance < 75%, student is not allowed for exam.
Logical Thinking in Problem Solving
Logical thinking helps to:
• Identify inputs and outputs
• Decide what operations are required
• Choose the correct control structures
Examples of Logical Thinking
Example 1: Even or Odd Number
Logic:
• A number divisible by 2 → Even
• Otherwise → Odd
Example 2: Traffic Signal Logic
• Red → Stop
• Yellow → Get Ready
• Green → Go
Example 3: Eligibility for Voting
• Age ≥ 18 → Eligible
• Else → Not Eligible
Algorithmic Thinking
Algorithmic Thinking
Algorithmic thinking is the ability to convert logical reasoning into a clear, finite,
step-by-step procedure (algorithm) that can be executed by a computer.
It answers “how to solve the problem step by step”.
Objectives of Algorithmic Thinking
• To design precise and unambiguous solutions
• To ensure solutions are finite and efficient
• To prepare logic for coding
• To automate problem solving
What is an Algorithm?
An algorithm is a finite sequence of well-defined steps used to solve a problem or perform a
task.
Characteristics of a Good Algorithm
1. Input – Takes zero or more inputs
2. Output – Produces at least one output
3. Definiteness – Each step is clear
4. Finiteness – Ends after finite steps
5. Effectiveness – Steps are simple and executable
Structure of an Algorithm
A typical algorithm contains:
• Input
• Processing logic
• Output
Relationship Between Logical and Algorithmic Thinking
Logical Thinking Algorithmic Thinking
Decides what to do Decides how to do
Based on reasoning Based on steps
Human-oriented Machine-oriented
Uses conditions Uses structured steps
Logical thinking forms the foundation, and algorithmic thinking builds on it.
Algorithmic Thinking – Detailed Examples
Example 1: Algorithm to Add Two Numbers
Logical Steps:
• Take two numbers
• Add them
• Display result
Algorithm:
1. Start
2. Read A, B
3. Sum ← A + B
4. Print Sum
5. Stop
Example 2: Algorithm to Find Largest of Two Numbers
Logic:
• Compare A and B
Algorithm:
1. Start
2. Read A, B
3. If A > B
o Print A
Else
o Print B
4. Stop
Example 3: Algorithm to Find Factorial of a Number
Logic:
• Factorial of n = n × (n−1) × … × 1
Algorithm:
1. Start
2. Read n
3. fact ← 1
4. For i = 1 to n
o fact ← fact × i
5. Print fact
6. Stop
Example 4: Algorithm to Check Prime Number
Logical Thinking:
• Prime number has only two factors: 1 and itself
Algorithm:
1. Start
2. Read n
3. If n ≤ 1 → Not Prime
4. For i = 2 to √n
o If n mod i = 0 → Not Prime
5. Else → Prime
6. Stop
Real-Life Example Combining Both
Problem: Making Tea
Logical Thinking:
• Water must be boiled before adding tea powder
• Milk should be added after tea decoction
Algorithm:
1. Start
2. Pour water into vessel
3. Boil water
4. Add tea powder
5. Add milk and sugar
6. Boil and serve
7. Stop
Problem Solving
Meaning of Problem Solving
Problem solving is a systematic process of understanding a problem, analyzing it, and
applying logical steps to arrive at an effective solution.
In computing, problem solving focuses on converting real-world problems into logical
and algorithmic solutions that can be implemented using programs.
Importance of Problem Solving in Computing
• Forms the foundation of programming and algorithm design
• Encourages logical and analytical thinking
• Reduces errors in program development
• Enables efficient and scalable solutions
• Essential in areas like AI, Data Science, and Software Engineering
Defining the Problem
Meaning of Defining the Problem
Defining the problem is the process of clearly identifying what needs to be solved,
including inputs, outputs, constraints, and objectives.
A well-defined problem ensures that:
• The solution addresses the actual requirement
• There is no ambiguity in interpretation
• The solution is measurable and verifiable
Components of Problem Definition
1. Problem Objective
What exactly needs to be achieved?
2. Inputs
What data is required to solve the problem?
3. Outputs
What result is expected?
4. Constraints
What limitations or conditions must be considered?
5. Assumptions
Any predefined conditions assumed to be true.
Example 1: Student Grade Calculation
Problem Objective:
Determine the grade of a student based on marks.
Inputs:
Marks obtained
Outputs:
Grade (A, B, C, etc.)
Constraints:
Marks range from 0 to 100
Assumptions:
Grading policy is predefined
Example 2: Traffic Signal Control (Real-World)
Problem Objective:
Improve traffic flow at intersections.
Inputs:
Vehicle count in each direction
Outputs:
Signal timing duration
Constraints:
Minimum and maximum green time
Assumptions:
Sensors provide accurate data
Advantages of Proper Problem Definition
• Prevents solving the wrong problem
• Saves time and resources
• Ensures correct algorithm design
• Leads to effective decomposition
Problem Decomposition
Meaning of Problem Decomposition
Problem decomposition is the process of breaking a complex problem into smaller,
simpler sub-problems that can be solved independently.
Each sub-problem handles one specific part of the overall task.
Objectives of Problem Decomposition
• Simplifies complex problems
• Improves clarity and understanding
• Enables modular design
• Facilitates testing and debugging
• Supports parallel development
Types of Problem Decomposition
1 Functional Decomposition
Dividing the problem based on functions or tasks to be performed.
Example: Online Examination System
Main Problem: Conduct an online exam
Sub-problems:
1. User authentication
2. Display questions
3. Capture answers
4. Evaluate responses
5. Generate result
Each function performs a single responsibility.
2 Process (Step-wise) Decomposition
Breaking the problem into sequential steps.
Example: ATM Cash Withdrawal
1. Insert card
2. Enter PIN
3. Select withdrawal option
4. Enter amount
5. Dispense cash
6. Update balance
3 Data Decomposition
Dividing the problem based on data elements.
Example: Payroll System
Data Elements:
• Basic salary
• Allowances
• Deductions
Sub-problems:
• Calculate allowances
• Calculate deductions
• Compute net salary
Benefits of Decomposition
• Reduces cognitive load
• Improves program structure
• Enhances reusability
• Makes maintenance easier
PATTERNS
Meaning of Patterns
A pattern refers to a repetitive structure or behavior observed in a problem or its
solution.
Recognizing patterns allows us to:
• Avoid repeated effort
• Optimize solutions
• Identify loops and reusable logic
Types of Patterns
1. Repetition Patterns
Tasks that repeat multiple times.
Example:
Printing numbers from 1 to 10
2. Decision Patterns
Repeated decision-making logic.
Example:
Checking eligibility conditions for multiple users
3. Structural Patterns
Similar arrangement of data or steps.
Example:
Processing records in a database
Example: Sum of First n Numbers
Pattern Observed:
Addition of consecutive numbers
General Observation:
1 + 2 + 3 + ... + n
This pattern leads to efficient solutions.
Importance of Pattern Recognition
• Improves efficiency
• Reduces redundancy
• Forms the basis of loops and functions
• Essential for scalable solutions
GENERALIZATION
Meaning of Generalization
Generalization is the process of extending a solution from a specific case to a broader
class of problems.
It enables solutions to work for any valid input, not just fixed values.
Example of Generalization
Specific Problem:
Find the sum of first 10 numbers.
Generalized Problem:
Find the sum of first n numbers.
General Formula:
Sum=n(n+1)2\text{Sum} = \frac{n(n+1)}{2}Sum=2n(n+1)
Example 2: Largest Number
Specific Case:
Find the largest of 3 numbers.
Generalized Case:
Find the largest among n numbers.
Importance of Generalization
• Makes solutions reusable
• Enhances scalability
• Improves algorithm efficiency
• Supports dynamic input handling
Relationship Between Decomposition, Patterns, and Generalization
Concept Role
Defining the Problem Clarifies what to solve
Decomposition Breaks problem into parts
Patterns Identifies repetition
Generalization Extends solution
Together, they form the core of computational thinking.
Integrated Example
Problem: Student Result Processing
Step 1: Define the Problem
• Input: Marks
• Output: Grade
Step 2: Decompose
• Input marks
• Calculate total
• Assign grade
Step 3: Identify Pattern
• Same grading logic for all students
Step 4: Generalize
• Works for any number of students
EXAMPLES
Scenario I
A city transportation department wants to improve traffic flow at major intersections during
peak hours. They plan to install an automated traffic signal control system that adjusts signal
timings based on traffic volume. Currently, traffic police manually observe each intersection
and adjust signal timings, which is inefficient and inconsistent. The new system should
analyze data such as the number of vehicles in each direction and dynamically decide how
long each signal stays green.”
i) Clearly define the core problem the transportation department is trying to solve.
ii) Break down the overall problem into smaller, manageable sub-problems required to
design the system
SOLUTION
Core Problem Definition
Core Problem:
The transportation department is facing inefficient and inconsistent traffic management at
major intersections during peak hours due to manual observation and adjustment of traffic
signals by traffic police.
Explanation:
• Manual control is time-consuming and subjective
• Signal timings do not adapt effectively to real-time traffic volume
• Leads to traffic congestion, delays, and poor traffic flow
Clearly Defined Problem Statement:
The core problem is the lack of an intelligent, automated system that can analyze real-time
traffic data and dynamically adjust signal timings to optimize traffic flow at major
intersections during peak hours.
ii) Problem Decomposition
To design the automated traffic signal control system, the overall problem is broken down
into smaller, manageable sub-problems.
Decomposed Sub-Problems:
1. Traffic Data Collection
o Collect real-time data on the number of vehicles in each direction using
sensors or cameras.
2. Data Preprocessing
o Filter, validate, and organize traffic data for analysis.
3. Traffic Volume Analysis
o Determine traffic density and congestion level for each direction.
4. Decision-Making Logic
o Decide signal priority based on traffic volume.
o Determine how long each signal should remain green.
5. Signal Timing Adjustment
o Dynamically adjust green, yellow, and red signal durations.
6. System Monitoring
o Continuously monitor traffic changes and update decisions.
7. Fail-Safe and Manual Override
o Allow manual intervention during emergencies or system failures.
Scenario II
A university examination cell wants to improve the process of allocating examination halls
during semester [Link], hall allocation is done manually using spreadsheets, which
often results in uneven student distribution, last-minute changes, and seating conflicts.
The examination cell plans to develop an automated hall allocation system that assigns
students to halls based on hall capacity, department, and exam schedule, ensuring fair
distribution and avoiding clashes.
Questions
i) Clearly define the core problem the examination cell is trying to solve.
ii) Break down the overall problem into smaller, manageable sub-problems required to design
the automated system.
Solution
i) Core Problem Definition
Core Problem:
The examination cell faces inefficiency, errors, and inconsistencies in manual examination
hall allocation, leading to poor space utilization and student inconvenience.
Clearly Defined Problem Statement:
The core problem is the absence of an automated system that can systematically allocate
examination halls by considering student strength, hall capacity, and exam schedules, thereby
eliminating manual errors and conflicts.
ii) Problem Decomposition
The overall problem is decomposed into the following sub-problems:
1. Student Data Collection
o Collect student details such as register number, department, and enrolled
subjects.
2. Hall Information Management
o Store details of available halls, seating capacity, and location.
3. Exam Schedule Analysis
o Identify subject-wise exam dates and time slots.
4. Allocation Logic
o Match students to halls based on capacity and exam schedule.
o Ensure no over-allocation or conflicts.
5. Seating Arrangement Generation
o Assign seat numbers systematically.
6. Conflict Detection and Resolution
o Detect overlapping schedules or capacity violations.
7. Output Generation
o Generate hall allocation lists for students and invigilators.
8. Monitoring and Updates
o Allow last-minute changes and re-allocation if required.