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

Intro Problemsolving

Uploaded by

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

Intro Problemsolving

Uploaded by

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

Introduction to Problem Solving

Outline
• General Problem-Solving Concepts:
– Types of Problems
• Problem Solving with Sequential Structure
• Discussion & Practice of Pseudocodes
• Generating Flowcharts.

2
Types of Problem
• The simple problem
– simple and obvious.
– already been solved
• The complicated problem
– don’t know the answer, but they know how to find it.
– a known unknown
• The complex problem
– take some sort of action to see what happens before you
act again.
– answers aren’t known
Types of Problems
 Problems do not always have straightforward solutions
• Algorithmic solutions
 Problems that can be solved with a series of actions
 Ex: Baking a cake
 The solution will be the same each time the
algorithm is followed
 The solution of a problem can be reached by
completing the actions in steps. These steps are
called the algorithm.
Types of Problems –
Cont.
• Heuristic solutions
 Solutions that cannot be reached through a direct set
of steps
 Example: expanding a company
 These solutions require reasoning built on knowledge
and experience, and a process of trial and error
 The results may not produce the same results each
time the algorithm is executed
Problem Solving with Computers
 Computers
which
humansare are built
often to deal
difficult or with
very algorithmic
time solutions,
consuming for

• People are better than computers at developing heuristic


solutions.

• The field of
problems computers
is called thatintelligence.
artificial deals with heuristic types of

• Artificial
build its
language.
intelligence
own enables
knowledge bank aand
computer
speak toado
in things like
human
Programming: Plan First, Then Code
• A good programmer will plan first and write
second
– Breaking down a large programming task into
several smaller tasks
An Overview of Seven Steps
Algorithm
• Set of well-defined logical steps that must be
taken to perform a task
• For example, suppose you have been asked to write a
program to calculate and display the gross pay for an
hourly paid employee.
Here are the steps that you would take:
1. Get the number of hours worked.
2. Get the hourly pay rate.
3. Multiply the number of hours worked by the hourly pay rate.
4. Display the result of the calculation that was performed in Step 3.
Pseudocode
• Pseudocode: fake code
– Informal language that has no syntax rule
– Not meant to be compiled or executed
– Used to create model program
• No need to worry about syntax errors, can focus on program’s
design
• Can be translated directly into actual code in any programming
language
Flowcharts
• Flowchart: diagram that graphically depicts
the steps in a program
– Ovals are terminal symbols
– Parallelograms are input and output symbols
– Rectangles are processing symbols
– Symbols are connected by arrows that represent
the flow of the program
Start
Flow Chart

"Input Number of Hours Worked"GET hoursWorked

"Get Hourly Rate"GET hourRate

TotalPay ← hoursWorked * hourRate

PUT "Gross Pay of an Employee: "+TotalPay¶

End
First Four Steps

Step 1: Work an Example Yourself


Step 2: Write Down What You Just Did
Step 3: Generalize Your Steps
Step 4: Test Your Algorithm
Example-1
Draw a flowchart to compute x raised to
the y power (x y)
Step 1: Work an Example Yourself
x = 3 and y = 4, getting an answer of 3^4 = 81.
Example-1
Step 2: Write Down What You Just Did
Example-1
Step 3: Generalize Your Steps
1-Replacing this occurrence of 3 with x
Example-1
Step 3: Generalize Your Steps
2-Find repetition
Example-1
Step 3: Generalize Your Steps
Example-1
• Step 4: Test Your Algorithm
Example-1
• Step 4: Test Your Algorithm
Example 2
• A painter wants to know the amount of paint
needed to paint only the walls and the interior
side of the door in a room. The chosen paint
covers 100 square feet per gallon. There are two
windows. Test the problem with the following
data:
– The room is 12 feet long, 10 feet wide, and 8 feet
tall.
– The two windows are 5 by 3 feet, and 6 by 2 feet,
respectively.

You might also like