ITS D002 - Problem Solving Lesson 01 (Ver 3.0)
ITS D002 - Problem Solving Lesson 01 (Ver 3.0)
ITSD002
Problem Solving
Topic 1
Introduction to Problem Solving
• Well-defined problem
• All information necessary to solve the problem is either explicitly
given or can be inferred
• Example:
• What is the result of the following multiplication?
234 x 124
Types of Problems
• Ill-defined problem
• There is uncertainty in either the given information, the permissible
operations/actions, or the final state
• Example:
• Given 16 matches arranged in 5 squares as shown, move 3 matches to
form 4 squares
Types of Problems
• Knowledge-rich problem
• It requires prior specialized or domain-specific knowledge to solve the
problem
• Example:
• What is the best way to stack the containers in a container ship?
• Knowledge-lean problem
• It can be solved by using domain-general knowledge
• Strategies and methods that apply to many types of problems
Types of Problems
• Knowledge-lean problem
• Example
• Starting with the arrangement of dots given below:
The jailer puts a hat on the head of each prisoner and says,
“if you can deduce the color of your own hat, you will be freed”.
Each prisoner can see the hats of the other two prisoners but not his
own.
The first prisoner says, “I cannot tell the color of my hat”.
The second prisoner says, “I cannot tell the color of my hat”.
The third prisoner, who is blind, is able to determine the color of his hat
and freed.
Problem Solving Principles
• Identify the problem
• Completely understand the problem
• Identify alternative ways to solve the problem; select the best
alternative
• Devise a plan to solve the problem; list solution steps
• Carry out the plan
• Evaluate solution
• Review the results
Problem Solving Process
• Combination of algorithmic and/or heuristic solutions
• Machine Languages
• A set of primitive instructions built into every computer
• The instructions consist only of sequences of 0s and 1s
• Program with native machine language is a tedious process, moreover,
the programs are highly difficult to read and modify
• Examples:
• 0110110111110111 0000000100000000 0000000100000000
Programming and Scripting Languages
• Assembly Languages
• Developed to make programming easy
• Symbolic representation of machine language
• Uses short words that are known as mnemonic
• Since the computer cannot understand assembly language, however, a
program called assembler is used to convert assembly language
programs into machine code
• Example: add two numbers
• ADD R1, R2, R3
Assembly Source File
Machine Code File
…
ADDF3 R1, R2, R3
Assembler …
1101101010011010
… …
Programming and Scripting Languages
• High-Level Languages
• Contains English words and phrases and algebraic expressions
• Easy to learn and program, without knowing how the CPU works
• Example: computes the area of a circle with radius 5
• area = 5 * 5 * 3.1415;
• Popular high-level languages:
• C; C++; C#; COBOL; FORTRAN; BASIC; Pascal; Ada; Objective C;
Java; Visual Basic; Delphi
• Python
Programming and Scripting Languages
• Compiling source code
• A program written in a high-level language is called a source
program
• Since a computer cannot understand a source program. Program called
a compiler is used to translate the source program into a machine
language program called an object program
• The object program is often then linked with other supporting library
code before the object can be executed on the machine
Library Code
Compiling a High-level Program and Executing
It
Executing a High-level Program with an
Interpreter
• An interpreter is a program that both translates and executes the
instructions in a high-level language program
Programming and Scripting Languages
• Scripting Languages
• Interpreted, not compiles
• Client-side (such as JavaScript)
• Server-side (such as PHP or ASP)
Writing Programs
• To write a program in a high-level language, you need:
• Appropriate software
• A text editor to type and edit program statements
• A debugger to help find errors in program code
• A compiler or interpreter to translate the program into machine
language
Programming Logic and Design
• All programming languages use basic programming logic
• If you understand this logic, it will be much easier to learn any
specific language
• The purpose of programming logic and design is to focus on
flowcharts and pseudocode
• The design is the foundation of a good program
Useful Resources
Python:
• https://www.python.org/
• https://www.w3schools.com/python/
• https://wingware.com
References
Textbook:
• Necaise, R. D. (2011). Data Structures and Algorithms using Python. John
Wiley & Sons. [Chapter 1]
Supplementary Reading:
• Miller, B., and Ranum, D. (2011). Problem Solving with Algorithms and
Data Structures using Python (2nd Edition). John Wiley & Sons. [Chapter 1]
• Venit, S., and Drake, E. (2015). Prelude to Programming (6th Edition).
Pearson. [Chapter 0, 1, 3]
Thank you