ICT Lecture 16

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 21

CSC101 – Applications of Information and

Communication Technologies

Problem Solving
Lecture 16
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 are built to deal with algorithmic solutions,
which are often difficult or very time consuming for
humans

• People are better than computers at developing heuristic


solutions.

• The field of computers that deals with heuristic types


of problems is called artificial intelligence.

• Artificial intelligence enables a computer to do things


like build its own knowledge bank and speak in a
human language.
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