ICS 2175 Lecture 3 Problem Solving Process
ICS 2175 Lecture 3 Problem Solving Process
Programming
Lecture 3- Problem
Solving
1
Today’s Class
• What’s an Algorithm?
2
Defn: 1. What is Computer Science?
• It is the discipline that seeks to build a scientific foundation for such
topics as computer design, computer programming, information
processing, and algorithmic solutions of problems.
• A computer is a machine that stores data, interact with devices,
execute programs, and provides computing capabilities to its users).
• Computing is the execution of an “algorithm”.
2. What is an Algorithm?
A set of steps that define how a task is performed. In other
words, it is an ordered set of unambiguous, executable steps
that define a terminating activity.
3
How do we solve problems?
• We "just do"
• Guesswork-and-luck
• Trial-and-error
• Experience (possibly someone else's)
• "Scientifically“......
– Define the problem
– Identify possible solutions and select one
– Develop an algorithm and test and improve
4
The Problem-solving Process
Analysis
Problem
specification
Design
Algorithm
Implementation
Program
Computer language
Compilation 01001110101100101010101010010
10101010100110010101010101001
011010011101010101010010010111
Executable 010011110101010111110101010001
(solution) 10100001101...
5
Problem Solving: A creative process
• 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!
What is an algorithm?
EXAMPLE:
Algorithm for converting from Celsius to Fahrenheit can be represented as
1. F = (9/5) C + 32 (algebraic equation)
2. “ Multiply the temperature reading in Celsius by 9/5 and then add 32
to the product”
14
Important Properties of Algorithms
• Correct
– always returns the desired output for all
legal instances of the problem.
• Unambiguous
• Precise
• Efficient….cost…use finite resources
– Can be measured in terms of
• Time
• Space
– Time tends to be more important
Representation of Algorithms
• English description
More
More easily
• Pseudo-code precise
expressed
• High-level
programming
language
Pseudocode
22
Programming Process
Problem-solving phase
• Analysis and specification ( understand and define problem, and
what is expected of solution)
• General solution (algorithm: a logical sequence of steps that
solves the problem)
• Verification (Follow steps to make sure solution solves the
problem)
Implementation phase
• Concrete solution (Program in a Programming language)
• Testing (make sure the program produces the desired results)
Maintenance phase
• Use Program
• Maintain Program (meet changing requirements)
23
Programming Process
General solution
(algorithm)
Testing
Verification
Maintenance Phase
24
Problem Solving
• The purpose of writing a program is to solve a problem
• The general steps in problem solving are:
– Understand the problem
– Dissect the problem into manageable pieces
– Design a solution
– Analyze the complexity of the algorithm
– Consider alternatives to the solution and refine it
– Implement the solution
– Test the solution and fix any problems that exist
25
Problem Solving
• Many software projects fail because the developer didn't
really understand the problem to be solved
• We must avoid assumptions and clarify ambiguities
• As problems and their solutions become larger, we must
organize our development into manageable pieces
• This technique is fundamental to software development
• In java, we will dissect our solutions into pieces called
classes and objects, taking an object-oriented approach
26
Problem Solving Techniques
• You follow algorithms every day in your life. So, we need to learn
how to design algorithms not simply follow them.
• So, what is Problem Solving Process?
1. Analysis 2. Design
3. Implementation 4. Testing
Hard problem
Easy Easy
subproblem subproblem
28
An Example
Compute the area of a circle
Problem statement
We need an interactive program (user will input data) that computes the area of a
circle. Given the circle radius, the circle area should be displayed on the screen
Input/Output description
Input Circle radius
Output Circle area
Algorithm development (set of steps, decomposition outline)
1. Read value of circle radius (r)
2. Compute circle area as pi* r2
3. Print the value of circle area
How do we represent more complex algorithms
Pseudocode, flowcharts
29
An Example (continued)
A divide and conquer block diagram of our problem
Circle area
Pseudocode
Prompt the user for the circle radius (put a message on the screen)
Read radius
Assign Circle area the value pi * radius2
Write Circle area on the screen
Stop
30