PROBLEM SOLVING SKILLS
Basic property of a computer (a machine):
• Computers do what we tell them to do
• Unfortunately, computer do not necessarily do what we
want them to do....
(Because we can make mistake in telling the computer
what we want to do... These mistakes are called "bugs")
Definition: algorithm
Dictionary definition:
• Algorithm = a step-by-step procedure for
solving a problem or accomplishing some
task, especially by means of a computer
Computer Algorithm:
is an algorithm that can be executed by a computer
Properties of computer algorithms:
• The steps in an algorithm must be consists of operations
that can be executed by a computer
• The step in an algorithm must be unambiguous
(Remember that a dumb machine like a computer will do
what it is told to do.
Resolving ambiguity requires some thinking (intelligence)
• Computers
cannot
which computers
cannot
do !)think.
We will now illustrate the process of developing
an algorithm
An algorithm always accomplishes some welldefined task or solves some well-defined
problem
The task/problem that we will use to illustrate
the process of developing an algorithm is:
• Replacing a burned out light bulb
Typical instructions given to humans on how to
replace a light bulb:
• Remove the burned-out bulb
• Insert a new bulb
These brief instructions assume a lot of
common sense knowledge that a machine does
not have !!!
What can go wrong if a machine uses these
instructions:
• A machine does not know how to remove a bulb
It could yank the bulb out of its socket and damage the
fixture in the process.
• A machine does not know how to insert a bulb
• A machine can replace the bulb with one that has an
inadequate wattage (too bright or too dim)
Computers have no common sense knowledge
(really dumb)
Instructions for computers must be given very
explicitly (in "baby steps")
Example of how you would instruct a computer to change a light
bulb:
[The following instructions will remove the burn-out
bulb]
repeat until (bulb comes free of socket)
{
turn bulb in counter-clockwise direction
}
[The following instructions will find a suitable bulb]
select a new bulb
repeat until (wattage of bulb selected = wattage of old
bulb)
{
discard the selected bulb select another bulb
}
[The following instructions will insert the new bulb]
repeat until (bulb is secure in socket)
{
turn bulb in clockwise direction
Lecture Objectives
Learn about problem solving skills
Explore the algorithmic approach for problem
solving
Learn about algorithm development
Become aware of problem solving process
Programming is a process of problem solving
Problem solving techniques
◦ Analyze the problem
◦ Outline the problem requirements
◦ Design steps (algorithm) to solve the problem
Algorithm:
◦ Step-by-step problem-solving process
◦ Solution achieved in finite amount of time
Step 1 - Analyze the problem
◦ Outline the problem and its requirements
◦ Design steps (algorithm) to solve the problem
Step 2 - Implement the algorithm
◦ Implement the algorithm in code
◦ Verify that the algorithm works
Step 3 - Maintenance
◦ Use and modify the program if the problem
domain changes
Thoroughly understand the problem
Understand problem requirements
◦ Does program require user interaction?
◦ Does program manipulate data?
◦ What is the output?
If the problem is complex, divide it into
subproblems
◦ Analyze each subproblem as above
The idea behind the computer program
Stays the same independent of
◦ Which kind of hardware it is running on
◦ Which programming language it is written in
Solves a well-specified problem in a general
way
Is specified by
◦ Describing the set of instances (input) it must work
on
◦ Describing the desired properties of the output
Before a computer can perform a task, it must
have an algorithm that tells it what to do.
Informally: “An algorithm is a set of steps that
define how a task is performed.”
Formally: “An algorithm is an ordered set of
unambiguous executable steps, defining a
terminating process.”
◦
◦
◦
◦
Ordered set of steps: structure!
Executable steps: doable!
Unambiguous steps: follow the directions!
Terminating: must have an end!
Correct
◦ always returns the desired output for all legal
instances of the problem.
Unambiguous
Precise
Efficient
◦ Can be measured in terms of
Time
Space
◦ Time tends to be more important
A single algorithm can be represented in
many ways:
◦
◦
◦
◦
Formulas: F = (9/5)C + 32
Words: Multiply the Celsius by 9/5 and add 32.
Flow Charts.
Pseudo-code.
In each case, the algorithm stays the same;
the implementation differs!
◦ A program is a representation of an algorithm
designed for computer applications.
◦ Process: Activity of executing a program, or execute
the algorithm represented by the program
◦ Process: Activity of executing an algorithm.
More easily
expressed
English description
More
Pseudo-code
High-level
programming
language
precise
Pseudocode is like a programming language
but its rules are less stringent.
Written as a combination of English and
programming constructs
◦ Based on selection (if, switch) and iteration (while,
repeat) constructs in high-level programming
languages
Design using these high level primitives
◦ Independent of actual programming language
Example: The sequential search algorithm in
pseudocode
The Two Steps of Program Development:
◦ 1. Discover the algorithm.
◦ 2. Represent the algorithm as a program.
Step 2 is the easy step!
Step 1 can be very difficult!
To discover an algorithm is to solve the
problem!
Problem solving techniques are not unique to
Computer Science.
The CS field has joined with other fields to try
to solve problems better.
Ideally, there should be an algorithm to
find/develop algorithms.
However, this is not the case as some
problems do not have algorithmic solutions.
Problem solving remains an art!
Working backwards
◦ Reverse-engineer
◦ Once you know it can be done, it is much easier to do
◦ What are some examples?
Look for a related problem that has been solved before
◦ Java design patterns
◦ Sort a particular list such as: David, Alice, Carol and
Bob to find a general sorting algorithm
Stepwise Refinement
◦ Break the problem into several sub-problems
◦ Solve each subproblem separately
◦ Produces a modular structure
K.I.S.S. = Keep It Simple Stupid!
Stepwise refinement is a top-down methodology
in that it progresses from the general to the
specific.
Bottom-up methodologies progress from the
specific to the general.
◦ These approaches complement each other
Solutions produced by stepwise refinement posses
a natural modular structure - hence its popularity
in algorithmic design.
Four stages to the decomposition process
◦ Brainstorming
◦ Filtering
◦ Scenarios
◦ Responsibility algorithms
A group problem-solving technique that
involves the spontaneous contribution of
ideas from all members of the group
◦ All ideas are potential good ideas
◦ Think fast and furiously first, and ponder later
◦ A little humor can be a powerful force
Brainstorming is designed to produce a list of
candidate classes
Determine which are the core classes in the
problem solution
There may be two classes in the list that have
many common attributes and behaviors
There may be classes that really don’t belong
in the problem solution
Assign responsibilities to each class
There are two types of responsibilities
◦ What a class must know about itself (knowledge)
◦ What a class must be able to do (behavior)
Encapsulation is the bundling of data and
actions in such a way that the logical
properties of the data and actions are
separated from the implementation details
The algorithms must be written for the
responsibilities
◦ Knowledge responsibilities usually just return the
contents of one of an object’s variables
◦ Action responsibilities are a little more complicated,
often involving calculations
Let’s repeat the problem-solving process for
creating an address list
Brainstorming and filtering
◦ Circling the nouns and underlining the verbs
First pass at a list of classes
Filtered list
© Copyright 2026 Paperzz