W1L2 Introduction Programming and Problem Solving
W1L2 Introduction Programming and Problem Solving
Introduction
PROGRAMMING AND PROBLEM SOLVING
Computers are everywhere
05/09/2025 2
Programming
program solve
05/09/2025 3
Programming and Problem
Solving
program solve
05/09/2025 4
Algorithmic Thinking
05/09/2025 5
Computer Programs
A computer program tells a computer the sequence of steps needed
to complete a specific task
• The program consists of a very large number of primitive (simple)
instructions
• Each program is designed to direct the computer to work on a specific task
Programming is the act of designing, implementing, and testing
computer programs
If you want a computer to perform a task, you should start by writing
an algorithm and then translate it to a computer program using a
programming languages (e.g. Python).
05/09/2025 6
Executing a Program
• Program instructions and data (such as text, numbers, audio, or video)
are stored in digital format
• When a program is started, it is brought into memory, where the CPU
can read it.
• The CPU runs the program one instruction at a time.
- The program may react to user input.
- The CPU reads data (including user input), modifies it, and writes it back to
memory, the screen, or secondary storage.
Main
Ports Memory
CPU
Network
controller
05/09/2025 7
Algorithms
A SHORT INTRODUCTION TO ALGORITHM
DEVELOPMENT
05/09/2025 8
Introduction to Algorithms
• If you want a computer to perform a task, you start by writing an
algorithm (mostly using a pen and paper)
• An Algorithm is:
- a sequence (the order mattering) of actions to take to accomplish the given
task
- An algorithm is like a recipe; it is a set of instructions written in a sequence
that achieves a goal
05/09/2025 9
A Simple Example
A simple algorithm to program a kitchen robot prepare a meal.
E.g.: Prepare a drink of orange juice
• Assumptions: for simplicity, the following are true:
• You have a clean glass in the cabinet
• You have orange juice in your refrigerator
05/09/2025 10
Second Example: Selecting a
Car
Problem Statement:
• You have the choice of buying two cars.
• One is more fuel efficient than the other, but also more
expensive.
• You know the price and fuel efficiency (in miles per
gallon, mpg) of both cars.
• You plan to keep the car for ten years.
• Which car is the better deal?
05/09/2025 11
Developing the Algorithm
1. Determine the inputs and outputs
2. From the problem statement we know:
• Car 1: Purchase price, Fuel Efficiency
• Car 2: Purchase price, Fuel Efficiency
• Price per gallon = $4.00
• Annual miles driven= 15,000
• Length of time = 10 years
05/09/2025 12
Translating the Algorithm to pseudocode
1. Break down the problem into smaller tasks
To calculate the total cost for each year we need to calculate the operating cost
• The operating cost depends on the annual fuel cost
• The annual fuel cost is the price per gallon * the annual fuel consumed
• The annual fuel consumed is the annual miles drive / fuel efficiency
05/09/2025 13
The Pseudocode
1. For each car compute the total cost:
annual fuel consumed = annual miles driven / fuel efficiency
annual fuel cost = price per gallon * annual fuel consumed
operating cost = Length of time * annual fuel cost
total cost = purchase price + operating cost
2. if total cost1 < total cost2
choose car1
else
choose car2
05/09/2025 14
Begin
The Flowchart
annFuelConsm1 = annMilesDriven1 / fuelEff1
annFuelCost1 = pricePerLiter * annFuelConsm1
opCost1 = time * annFuelCost1
A flowchart is a totalCost1 = purchasePrice1 + opCost1
type of diagram
that represents a
workflow or
annFuelConsm2 = annMilesDriven2 / fuelEff2
process. annFuelCost2 = pricePerLiter * annFuelConsm2
opCost2 = time * annFuelCost2
A flowchart is a totalCost2 = purchasePrice2 + opCost2
diagrammatic
representation of
an algorithm
yes
choose car1 totalCost1 < totalCost2
The flowchart
shows the steps
no
as boxes of
various kinds, choose car2
and their order by
connecting the End
boxes with
arrows.
05/09/2025 15
Algorithmic Thinking
- The thinking that we do before and as we start writing a computer program
1. Problem Identification
2. Decomposition
3. Pattern Recognition
4. Abstraction
05/09/2025 16
Algorithmic Thinking
- The thinking that we do before and as we start writing a computer program
1. Problem Identification
- What's the big problem you're trying to solve, and can you state this
in an adequate problem statement?
05/09/2025 17
Algorithmic Thinking
- The thinking that we do before and as we start writing a computer program
2. Problem Decomposition
- Break our large problem down into smaller and smaller sub-problems
- Solve those specific sub-problems.
- Have these different solutions all contribute to solving the large
problem.
Solving the smaller pieces can help us arrive at a solution for our original
problem statement.
05/09/2025 18
Algorithmic Thinking
- The thinking that we do before and as we start writing a computer program
3. Pattern recognition
- Have you seen solutions to similar problems that you could use here? Or
can you think of similar problems that have been solved before that can
help you address these problems?
- How is this problem the same or different from other problems you've
identified or addressed in the past? And can you use those similarities to
help arrive at a solution?
05/09/2025 19
Algorithmic Thinking
- The thinking that we do before and as we start writing a computer program
4. Abstraction
05/09/2025 20
Case Study: How to detect suspicious
behavior on an airport surveillance
videos
05/09/2025 21
Reflect
>>> What types of suspicious behavior would you
look for at an airport?
>>> How do you think computers can help us
identify suspicious behavior?
- Engage in problem solving thinking, then
- Share your thoughts on the Virtual
Classroom Forum…
05/09/2025 22
Engage in Computational Thinking: How to detect suspicious behavior
on an airport surveillance videos
1. Problem Identification:
- Is the problem a good candidate for using a computer to
generate a solution?
2. Decomposition:
- How would you break down the problem into smaller sub-
problems?
3. Pattern Recognition:
- Are there related solutions to build on?
4. Abstraction:
- Are there non-essential aspects of our problem that might
be ignored
05/09/2025 23
Programming and Problem Solving
05/09/2025 24