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

General Problem Solving Concepts

The document provides an overview of general problem solving concepts, including the six steps of the problem solving process: 1) identify the problem, 2) understand the problem, 3) identify alternative solutions, 4) select the best alternative, 5) list steps for the chosen solution, and 6) evaluate the solution. It also describes different types of problems, problem solving with computers, and common difficulties with problem solving. Key concepts discussed include algorithms, heuristics, constants, variables, data types, functions, and operators.

Uploaded by

Sania Kazmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

General Problem Solving Concepts

The document provides an overview of general problem solving concepts, including the six steps of the problem solving process: 1) identify the problem, 2) understand the problem, 3) identify alternative solutions, 4) select the best alternative, 5) list steps for the chosen solution, and 6) evaluate the solution. It also describes different types of problems, problem solving with computers, and common difficulties with problem solving. Key concepts discussed include algorithms, heuristics, constants, variables, data types, functions, and operators.

Uploaded by

Sania Kazmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

Chapter 1

General Problem Solving Concepts


Overview
´Problem Solving in Everyday Life
´Types of Problems
´Problem Solving with Computers
´Difficulties with Problem Solving
Learning Objectives

1. Describe difference between heuristic


and algorithmic solutions
2. List and describe SIX (6) problem-
solving steps for algorithmic solution
3. Use problem-solving steps to solve
problem
Problem Solving in Everyday Life
SIX (6) steps in problem-solving process:
1. Identify the problem
2. Understand the problem – require knowledge
base (q4 - pp20)
3. Identify alternative ways to solve problem
4. Select best alternative
5. List solution steps for alternative chosen (q2 -
pp20, q5 – pp21)
6. Evaluate solution
Problem Solving in Everyday Life
Example 1:
Let’s say you are preparing for
examination in hostel / apartment, and
you are very hungry right now.
Try to solve the problem above by using
six steps of problem solving process.
Types of Problems

Problems can be solved with:


• Algorithmic solutions
• Heuristic solutions
• Combination of algorithmic, heuristic
solutions
Algorithmic Solutions
´Can be solved with a series of actions
(in steps)
´These steps are called ALGORITHM
´Example:
´Balancing a cheque book
´Baking a cake
´Withdrawing money from ATM machine
´Paying for your parking ticket via auto pay machine
´What else?
Heuristic Solutions
´Problem which couldn’t be solved through
a direct set of steps.
´Require knowledge, experience & a
process of trial and error (repeating six steps
more than once)
´Example:
´How to buy best stock from market
´Should the company be expanded
´Baking a delicious cake
´Raising up a kid
´What else?
Combination of Both
´Most problems require a combination
of algorithmic and heuristic solutions
´Example:
´Repairing a car
´Driving a car
´To win in a computer game
´What else??
Problem Solving with Computers
Definitions:
• Solution Û instructions followed to
produce best result
• Result Û outcome, computer-assisted
answer
• Program Û instructions for solution
using computer language
Difficulties with Problem Solving

´Lack of problem solving experience


´Inadequate solution steps
´Incorrect problem definition
´Alternatives chosen incorrectly
´Invalid logic
´Incorrect solution evaluation
Beginning Problem-Solving
12
Concepts for the Computer
Lesson 2
13
3 Types of Problems
´Computational
´problems involving some kind of mathematical
processing

´Logical
´Problems involving relational or logical processing

´Repetitive
´Problems involving repeating a set of mathematical
and/or logical instructions.
14 Fundamental Concepts
´The building blocks of equations and
expressions
´Constants
´Variables
´Operators
´Functions (predefined—more about user-defined
functions later)
15 Constants
´A value
´a specific alphabetical and/or numeric value
´Does not change during the processing of all the
instructions in a solution
´Can be of any data type
´Numeric, alphabetical or special symbols
´Examples
´3, 5, 10, “Mulder”, “Scully”, “+”, “-”, “/”
´Note: “” indicates datum rather than variable name
16 Constants
´In some programming languages, constants can
be named
´Provides protection to the constant value and other
areas of the program.
´Cannot be changed once given initial value
´Note: no spaces allowed within names
´Examples
´ SALES_TAX_RATE = 6
Constant name are
´ COMMISSION_RATE = 6 usually in
ALL CAPS
17 Variables
´The name references the memory or storage
location where the value is stored
´May change during processing
´May be of any data type
´A name is assigned to each variable used in a
solution.
´ Examples
´ Age, LastName, Address, PayRate
18 Rules for Naming Variables
´ the name should be ´ Use appropriate naming
meaningful convention
´ Use PayRate not x or y or z ´ Be consistent!
´ Do not use spaces ´ Some languages are case sensitive

´ Do not use special symbols, ´ Either combine terms (PayRate) or


include an underscore to separate
except the underscore (Pay_Rate)
´ Examples
´ PayRate, Pay_Rate, PAYRATE, or
PAY_RATE
19 Data Types
´Most common types
´Numeric
´Character
´Logical (True/False)
´Most languages include other data types
´Date
´Currency
´User-defined
´Strings
20 Rules for Data Types
´All data to be used in calculations must be declared
as a numeric data type
´Each data type uses a data set or domain
´Integers - -32768 -> 0 -> 32767 but is programming
language dependent
´Characters – all alphanumeric characters included in
the computer’s coding scheme
´Logical – the words “true” and “false”
´Data types cannot be mixed
´Programmer designates the data type
Data Types & Data Sets

Data Type Data Set Examples


Integer All whole numbers 3456
-43
Real All real numbers (whole + 3456.78
decimal) -123.45
0.000123
Character (uses All letters, numbers, and “A”, “a”, “1”, “+”, “%”
quotation marks) special symbols
String (uses Combinations of more than “Mulder”
quotation marks) one character “123-45-6789”
Logical True or False True
False

21
22 Numeric Types
´Includes all types of numbers
´Natural Numbers - The set of positive (counting) numbers
´ Ex. {1,2,3,4,5,…}

´Integers - The set of real numbers consisting of the natural


numbers, their additive inverses, and zero
´ Ex. 3, 5, -5, 0, -1 and 32,767

´Real numbers (floating point numbers)


´ Ex. 3.1459, 1.618039887, -5745 & Scientific Notation
23 Character Types

´Alphanumeric data set


´Consists of
´ all single-digit numbers,
´ letters, and
´ special characters available to the computer

´contained within quotation marks


24 String Data Type
´Made up of one or more characters.
´Contained within quotation marks
´Cannot be used within calculations
´There is some debate about using strings…
´The new consensus is that if the value will be used in a
mathematical calculation, make it a number, otherwise make it
a string.
´The alternative view (older view) is to look at the amount of
storage that is needed for the value. A number generally takes
up less memory space than a string.
25 Strings - Caution
´“123” is not the same thing as 123
´The first one is a string
´The second one is a number
´Becomes important when deciding when a
piece of data is a string or a number
´Ex. Social Security Numbers
´ The first one contains 11 characters and is left aligned
whereas the second contains 9 numbers and is right aligned
26 Concatenation

´Joins character or string data together


´Operators: + and &
´ Dependent on programming language
´ & can mix data types
´ + cannot mix data types
´ Examples
´ FName & “ ” & MI & “ ” & LName
´ “James” + “ ” + “T.” + “ ” + “Kirk” = “James T. Kirk”
´ “James” & “ ” & “T.” & “ ” & “Kirk” = “James T. Kirk”
´ Note the space at the end of the T.
27 Logical (Boolean) Data Type

´Consists just two pieces of data


´True and False
´Different programming languages also allow
´ Yes and No
´ 1 (True) and 0 (False)
´ On and Off
28 Functions

´Small sets of instructions that perform specific tasks


and return values.
´Two types:
´Pre-defined
´ Built into a computer language or application

´User-defined
´ More about these later
29 Functions
´Benefits
´Reduces the amount of code that needs to be written,
thus reducing errors of repetition
´Shortens the development time
´Improves readability
30 Function Parameters

´Data usually placed within parentheses that the


function uses without altering the data
´In Sqrt(n), the n represents the parameter, in this case
a number
31 Function Types
´Mathematical (sqrt, abs, round, etc.,)
´String (length, mid, left, etc.,)
´Conversion (string, int)
´Statistical (Average, max, min, sum)
´Utility (Date, Time)
´Specific to each programming language

COP1000 McManus
32 Operands, Resultants
& Operators

´Operands ´Operators
´The data that the operator ´The data connectors within
connects and processes expressions and equations.
´Resultant ´Two types of operations
´The answer that results when ´Unary
the operation is executed ´ Negation

´Binary
´ Addition, Subtraction, Multiplication,
Floating Point Division and Integer
Division
33 Operator Types
´Mathematical
´+, -, *, /
´//, Mod {Integer Division & Modulo}
´^, {Exponentiation}
´Relational
´<, >, <=, >=, =, <>
´Logical
´And, Or, Not
34 The Boolean Data Type

´Returns either the keywords True or False or


´Returns a non-zero or zero value.
´-9, -1, 1, 2 are equivalent to True
´0 is equivalent to False
´Is stored in two bytes
35 Relational Operators

´Perform comparisons
´Ex. If Y > Z then ...
= equal
<> not equal
< less than
> greater than
<= less than or equal to
>= greater than or equal to
36 Logical (Boolean) Operators

´And, Or, Not


´Boolean Expressions are used
´To create more complicated Boolean Expressions.
´If a = b AND c < d Then …
´They are defined by using Truth Tables…
´Know the significance of each!
37 The AND Operator

´Significance: The only time the result is True is if


both A and B are True.

A= B= then A AND B
True True True
True False False
False True False
False False False
38 The OR Operator

´Significance: The only time the result is False is if


both A and B are False.

A= B= then A OR B
True True True
True False True
False True True
False False False
39 The NOT Operator

Significance: Whatever the value of A is, NOT A will


be the opposite.

A= NOT A
True False
False True
40 Hierarchy of Operations

´Data and Operators are combined to form


expressions and equations
´To evaluate these in the proper order, a hierarchy
of operations, or Order of Precedence, is used.
´Note: Different programming languages use different
Order of Precedence…
´Note: Whenever you want to clarify an equation, use
the parentheses!
41 The Order of Precedence
OPERATOR TYPE NAME
( ) Parentheses Parentheses
^ Arithmetic Exponent (Powers)
*/ Arithmetic Multiplcation, floating-point division
\ Arithmetic Integer division
Mod Arithmetic Modulus
+- Arithmetic Addition, subtraction
= <> Comparison (all Equal to, not equal to, less than or equal to,
<= >= have same level of greater than or equal to, greater than, less
> < precedence than
NOT Logical Logical Negation
AND Logical Logical And
OR Logical Logical Or
XOR Logical Logical Exclusive Or
EQV Logical Logical Equivalent
COP1000 McManus
42 Expressions & Equations

´Expressions
´Process the data and the operands, through the use
of the operators
´Does not store the resultant (answer)
´Examples
´Price * SalesTaxRate
´(Hours – 40) * Wage * 1.5
´Height * Width
43
Equations

´Same as an expression, except the equation


stores the resultant (answer) in a memory
location (must be on the left side of Assignment
Operator)
´Examples
SalesTax = Price * SalesTaxRate
OvertimePay = (Hours – 40) * Wage * 1.5
Area = Height * Width
Planning Your Solution
44 Lesson 3
Analyzing the Problem

Understand requirements:
1. The given data
2. The required results
3. The processing that is required in the problem
4. A list of solution alternatives
Flowchart Symbols
Flowchart Symbols
Flowchart Symbols
Figure 3.9 Flowchart Symbols
The Algorithms and Flowcharts for the
Payroll Problem
The Algorithms and Flowcharts for the
Payroll Problem
The Algorithms and Flowcharts for the
Payroll Problem
The Algorithms and Flowcharts for the
Payroll Problem
Order of Execution of Instructions
Problem Analysis Chart
Problem Analysis Chart for the Payroll
Problem
The IPO(input-processing-output) Chart
The IPO Chart for the Payroll Problem

You might also like