0% found this document useful (0 votes)
2 views

ICS 2175 Lecture 3 Problem Solving Process

The document provides an introduction to computer programming, focusing on problem-solving techniques and algorithms. It defines computer science and algorithms, outlines the problem-solving process, and emphasizes the importance of understanding problems before designing solutions. Additionally, it discusses various methods for representing algorithms and the programming process, which includes analysis, implementation, and maintenance phases.

Uploaded by

johnkenmacharia
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

ICS 2175 Lecture 3 Problem Solving Process

The document provides an introduction to computer programming, focusing on problem-solving techniques and algorithms. It defines computer science and algorithms, outlines the problem-solving process, and emphasizes the importance of understanding problems before designing solutions. Additionally, it discusses various methods for representing algorithms and the programming process, which includes analysis, implementation, and maintenance phases.

Uploaded by

johnkenmacharia
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

ICS 2175: Introduction to Computer

Programming

Lecture 3- Problem
Solving
1
Today’s Class

• What’s Computer Science?

• What’s an Algorithm?

• Problem solving techniques

• Overview of computer programming process

• Problem solving techniques

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?

• 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
What is an algorithm? (Cont’d)

• 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!
What is an algorithm? (Cont’d)

A set of finite steps(step by step procedure) of solving a


particular problem in finite time( using finite resources.
Algorithm Discovery

• 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
• 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
Problem Solving Process

• 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
Analyze the Problem

• Thoroughly understand the problem


• Understand problem requirements (IPO
configuration)
– 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
Algorithm Representation
• An algorithm can be represented using some sort
of language, such as the flowcharts, pseudocode
(precisely defined textual structures)
• An algorithm is abstract and it can be represented
in many ways.

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

• 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!
Representation of Algorithms (Cont’d)
– 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.
Expressing Algorithms

• English description
More
More easily
• Pseudo-code precise
expressed

• High-level
programming
language
Pseudocode

• 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
Pseudocode (Cont’d)

Example: The sequential search algorithm in pseudocode


Example: An algorithm for starting the car

To run the car, we follow the following steps:


1. Insert the key in ignition
2. Make sure transmission is in Park (or Neutral)
3. Depress the gas pedal
4. Turn key to start position
5. If engine starts within six seconds, release key to
ignition position
6. If engine does not start in six seconds, release key and
gas pedal, wait ten seconds, and repeat steps 3 through
6, but not more than five times
7. If the car does not start, call the garage
21
Programming Process
Computer program is a sequence of instructions to be
performed by a computer.
Computer programming is the process of planning a sequence
of steps for a computer to follow
Programming Process has the following three phases:
• Problem-solving phase
• Implementation phase
• Maintenance phase

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

Analysis and Concrete solution


Specification
(Program)

General solution
(algorithm)
Testing

Verification

Maintenance Phase

Documentation: writing program documentation, and user manuals

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

Some Strategies to solve Determine


Analysis
problems problem features
• Ask questions Rethink as
Describe objects appropriate
Design
and methods
• Look for things that
are familiar Produce the
Implementation
classes and code
• Means-Ends Analysis
Examine for Testing
correctness
• Divide and Conquer
27
Strategies: Divide and Conquer
Break up large problems into smaller problems that are easier to handle
(Top-Down approach)

Hard problem

Easy Hard Easy


subproblem subproblem subproblem

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

Read radius Compute area Print 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

You might also like