Problem Solving Concepts
Problem Solving Concepts
Concepts
Introduction
The most important skill for a computer scientist is
problem-solving:
the ability to formulate problems, think creatively about
solutions, and express a solution clearly and accurately.
Programming involves
problem solving and
translating the solutions into a computer program using
a programming language (a.k.a . coding)
A programmer skill: thinking ability to produce the
solution and knowledge about the programming language
Nature of problem
A problem in computer science is the statement of
Nature of problem
Abstract : they have no particular values to be used in
making the solution e.g.:
i) Compute the area of a circle with a given
radius
ii) Ali drove to Abus house at 60 km/h. Abus house
is 80 km away. What time should Ali leave if he wants
to arrive at a certain particular time?.
iii) Calculate the monthly payment for a given loan
amount with a specific loan duration and interest
rate.
requires an abstract/general solution which can solve
several problems when concrete information is given.
Nature of problem
Abstract problems are the more common problem (well
focus more on solving abstract problems)
Abstract problems are the types that computer
scientists are faced with every day
2 Types of Problem
Solutions
Algorithmic Solutions
Steps involved in following a set of
instructions.
Ex. Calculating your checkbook balance
2 Types of Problem
Solutions
Heuristic Solutions
Solutions that cant be reached by
following a direct set of steps.
Created by using reasoning built upon knowledge
and experience and by trial and error.
Ex. - Determining which stock is the best value
- How to decide which program to choose
Efficiency
Speed
Accuracy
Acceptability
COP1000
McManus
11
COP1000
McManus
12
COP1000
McManus
13
014
Steps in Building a
Program
Analyzing the problem
Developing an algorithm
Writing the program (by the programmer,
including internal commenting)
Testing the program (by the programmer as
well as the user)
Steps in Building a
Program
Problem Analysis:
Before writing any program, a programmer must clearly
understand the problem,what input are to be used,the
desired output,the procedure that will produce the result
and the constraints to be considered.
The analysis starts by answering these questions:
What would be considered the input data?
What would be considered the output information?
What are the formulas/processes you have to create to
solve this solution?
Are there any special conditions/constraints?
Steps in Building a
Program
Problem Analysis:
Steps in Building a
Program
Writing Algorithm:
Steps in Building a
Program
Test Algorithm:
pretend that you are the computer and follow the steps
of your algorithm explicitly while keeping track of how
the variables are changing.
hand trace the values of the variables in every steps of
your algorithm
Steps in Building a
Program
Coding:
Steps in Building a
Program
Testing/Debugging Program:
Algorithm
An algorithm is a clear stepby-step
sequence of instructions to solve a
problem
analogy: recipe (refer next slide)
In mathematics and computing, an
algorithm is a procedure (a finite set of
well-defined
instructions)
for
accomplishing some task which, given
an initial state, will terminate in a
defined end-state. (source:Wikipedia)
Algorithm
comes from the 9th century Persian
mathematician
Abu Abdullah Muhammad ibn
Musa al-Khwarizmi.
2 ways to represent algorithm:
a) pseudo code
using English-like statements to list the
steps to be taken in the solution.
b) flowchart
using diagrams that employ symbols to
describe the workflow of steps involved in
the solution.
Pseudocode
Pseudocode
Start
Output "Enter rectangle length: "
Input length
Output "Enter rectangle width: "
Input width
Calculate perimeter = 2 x(length + width)
Output perimeter
End
Flowchart
Rectangle (processing)
Diamond (decision)
Start
Input length,
width
Perimeter = 2 x
(length + width)
Output
perimeter
Stop