• No results found

General Problem Solving Concepts

N/A
N/A
Protected

Academic year: 2020

Share "General Problem Solving Concepts"

Copied!
80
0
0

Loading.... (view fulltext now)

Full text

(1)

UNIT I

General Problem Solving

(2)

Overview

■ Problem Solving in Everyday Life

■ Type of Problems

■ Problem Solving with Computers

(3)

Objectives

■ Describe the difference between heuristic

and algorithm solution to problems

■ List and describe the six problem-solving

steps to solve a problem that has an algorithmic solution

■ Use the six problem-solving steps to solve

(4)

Problem Solving in Everyday Life

■ People make decision every day to solve

problem that affect their lives.

■ Bad decision is made, time and resources

are wasted.

(5)

Six Steps in Problem Solving

■ There are six steps to follow to ensure the

best decision

■ Identify the Problem

■ Understand the Problem

■ Identify alternative ways to solve the

problem

■ Select the best way to solve the problem

from the list of alternative solution

■ List instructions that enable you to solve the

problem using the selected solution

(6)

How to Avoid Bad Decision

■ https://www.youtube.com/watch?v=ASY4

(7)

Activity Think Pare and Share

■ Take the Problem of What to do this

(8)

■ STEP I:n Identify the problem

■ Step II: Understand the Problem

■ Step III: Identify alternative Solution

■ Solution Pros Cons ■ A.

■ B.

■ Step IV: Select the Best Solution

■ Step V: List a set of step by step

instruction to attain the solution

■ 1. ■ 2

(9)

Type of Problems

■ The Problem do not always have straight

forward solution

■ Some problem can be solved series of

actions is called Algorithm

■ The Solutions can be reached by

completing the actions in steps

■ A process of solving a problem in trial and

(10)

Problem Solving with Computers

■ Solution: It means the instruction listed

during steps of problem solving

■ The Instruction that must be followed to

produce the best results

■ Results: It Means the outcome or the

completed computer assisted answers

■ Program: The set of instruction that make

up the solution after they have been

(11)

■ Computer are build to deal with

algorithmic solutions which are often

difficult and time consuming for humans

■ People are better than computer at

developing heuristic solution

■ But computer are good for solving difficult

problems example sorting 10000 data in ascending order

■ Artificial Intelligence: The field of

(12)
(13)

Difficulties with Problem

Solving

■ Lack of Problem Solving Experience

■ Inadequate Solution Steps

■ Incorrect Problem Definition

■ Alternative Chosen Incorrectly

■ Invalid Logic

(14)

Difficulties with Problem Solving

■ People Have many problem to Problem

Solving

■ Not been taught how to solve problems

■ Fear in making decision

■ One or more steps inadequate

■ They may define the problem correctly

■ Not generated list of alternatives

■ Problem solving is not easy it time

(15)

Questions

■ What are the six steps of problem solving

■ What is an algorithm solution to a problem

■ What is a heuristic solution to a problem

■ What is Program?

■ What is Instruction?

■ What is Artificial Intelligence?

(16)

Summary

■ General Problem Solving

■ Six Steps for Problem Solving

■ Algorithm

(17)
(18)

Overview

■ Constants and Variables

■ Rules for Naming and Using Variables

■ Data Types

■ Numeric Data

■ Character Data – Alphanumeric Data ■ Logical Data

■ Other Data Types

■ Rules for Data Types ■ Example of Data Types

■ Functions ■ Operators

(19)

Objectives

■ Differentiate between variables & constants.

■ Differentiate between character, numeric and

logical data types.

■ Identify operators, operands and resultants.

■ Identify and use functions.

■ Identify and use operators according to their

placement in the hierarchy chart.

■ Set up an evaluate expressions and equations

(20)

Problem types in Computer

■ Problems that can be solved on computers

generally consists of:

■ Computational problems

■ Involve some kind of mathematical processing

■ Logical problems

■ Involve relational and logical processing

■ Repetitive problems

■ Involve repeating set of mathematical or logical

(21)

Constants and Variables

■ A constant is a value that never change

during the processing.

■ Constants can be of any data types –

numeric, alphabetical or special symbols.

■ Eg: PI = 3.14

■ A variable may change during processing.

■ Also called as identifiers.

(22)

Rules for Naming and Using

Variables

■ Name a variable according to what it represents.

Eg: hours for hours worked.

■ Do not use spaces in a variable name. eg: Hours

Worked

■ Start a variable name with a letter

■ Do not use a dash or any symbol used as a

(23)

Rules for Naming and Using

Variables

■ Once the variable name is specified the

same is used in all places.

■ Be consistent when using upper and

lowercase characters.

■ Use the naming conventions specified by

(24)
(25)

Data Types

■ Data are unorganized facts.

■ They go into the computer as input and

are processed by the program.

■ Output is the information

(26)

Data Types

Data Data Processed into

Information Report

Input Output

Check deposits & Bank

Charges

Calculates the

balance Balance Sheet

(27)

Numeric Data

■ Numeric data includes all types of

numbers.

■ The subtype of numeric includes integers

and real numbers.

■ A data set is the set of values that are

(28)

Character Data

■ Character data set consists of letters and

special characters available to computer.

■ Also called alphanumeric when consists of

single digit numbers.

■ Character data or string data can be

(29)

Logical Data

■ Logical data consists of two values in the

data set – true and false.

■ These are used in making the decisions

ie:- yes or no.

■ The logical data set true and false are not

(30)

Other Data Types

■ Date Data Types

■ The use of this data type allows the user to

perform mathematical calculations on any date.

■ User – defined Data Types

■ Data types defined by the programmers.

■ User must specify the items in the data set for

(31)

Rules for Data Types

■ The data define the value of a variable or a

constant will be most commonly be one of the three data types: numeric, character or logical.

■ The programmer designates the data type

during the programming process.

■ Data types cannot be mixed.

■ Each of the data types uses a data set. ■ Any numeric item that must be used in

(32)
(33)

Functions

■ Functions are small set of instructions that

perform specific tasks and return values.

■ Functions are used as parts of instructions

in a solution

■ Syntax for a function:

functionname(data)

■ data listed as a part of the functions are

(34)

Functions

■ Functions are divided into following classes:

■ Mathematical Functions: mostly used in business

and science.

■ Square root, random number, abs, sign

■ String Functions

■ Copy, length, concatenation, left, right

■ Conversion Functions

■ Type conversion (string to numeric)

■ Statistical Functions

■ Maximum values, minimum values,sum,avg

■ Utility Functions

(35)

Contd…

■ Functions names are not allowed to used

(36)

Operators

■ Operators are the data connectors within

expressions and equations.

■ Used to process the data.

■ Also specify the type of processing.

■ Types of operators:

■ Mathematical ( +, - , *, / , %, ^) ■ Relational (>, <, =, <=, >= )

(37)

Operators

■ Operands are the data that the operator

connects and process.

■ Resultant is the answer that results when

the operations is completed.

■ Operands can be constant or variable.

■ Data type of operands and resultants

(38)

Operators

■ All operators have a hierarchy or precedence, an

order in which their operations take place.

■ To reorder the normal processing sequence the

programmer uses parenthesis.

■ The processing of the operands always starts

(39)
(40)

Expressions and Equations

■ An expression processes data, the

operands through the use of operators.

■ Eg: length * width

■ An equation stores the resultant of an

expression in a memory location in the computer through the equal (=) sign.

(41)

Evaluate Expressions

■ Example 1: Setting Up a Numeric Expression

■ A programmer is given following expression to

use in solving the problem.

■ X(3Y + 4) – 4Y/X+6

■ The above expression is rewritten as:

■ X * (3 * Y + 4) – 4 * Y / (X + 6)

■ Parenthesis are added when the hierarchy has

(42)

Evaluate Expressions

■ Write all parentheses, operands and

operators on a single line with the dividend first followed by the divisor.

X ( 3Y + 4) – 4Y/X+6

■ Insert all implied operators.

X * ( 3 * Y + 4) – 4 * Y / X + 6

■ Insert all parentheses where the hierarchy

needs to be reordered.

(43)

Evaluate Equations

■ Example 2: Setting up a Mathematical

Equation

■ A mathematical equation is given to the

programmer as:

Y + 3 = X ( Z + 5 )

■ Programmer modify it into assignment

instruction as:

(44)

Example 2

■ Following steps are performed:

■ Write all parentheses, operands and

operators in a single line: Y + 3 = X (Z + 5)

■ Use of mathematical rules to complete the

equation so that there is one variable on left side.

Y = X (Z + 5) – 3

■ Follow the steps in example 1 to complete

(45)

Example 3

Setting Up a Relational Expression

■ A relational expression is used to make

decisions.

X is less than Y + 5

■ The programmer would change its form to

the following:

(46)

Example 4

Setting Up a Logical Expression

■ The expression is of the form A OR B.

■ The operands A and B are of logical data

(47)

Example 5

Evaluating a Mathematical Expression

■ Consider the expression:

5 * (X + Y) – 4 * Y/(Z+6)

■ The programmer uses any valid values

like:

(48)

Example 6

Evaluating a Relational Expression

■ Consider the expression:

A – 2 > B

■ Programmer can use any valid value like:

A = 6 and B = 8

■ The result of any relational expression will

(49)

Example 7

Evaluating a Logical Expression

■ Consider the expression:

( A AND B ) OR (C AND A)

■ Programmer can use any valid value like:

(50)

Example 8

Evaluating an Equation that uses

both Relational and Logical

Operators

■ Consider the equation:

■ F = NOT ( A < B) AND ( C OR D)

■ Programmer can use any valid value like:

(51)

Example 9

■ Developing a table of all possible Resultants

of a Logical Expression

■ The programmer can also figure out the

resultants for all the possible combinations of the values of the variables in an expression.

■ No. of possible combinations = double the

(52)

Example 9

■ Let the expression be: NOT A OR B

A B NOT A OR B

T T F

T F F

F T F

(53)

Example 10

■ Developing a logical expression from a

given problem.

■ A programmer can form a logical

expression based on some criteria.

■ Identification of the data items on which

(54)

Example 10

■ Problem: A large department store has its own

charge card. The policy for a customer to charge an item is that the customer must have a valid charge card and either a balance of less than $500 or a charge amount of less than $50.

■ First list the items:

■ The charge card (logical data type)

■ The balance (numeric data type)

(55)

Example 10

■ Second list the condition on the data items:

■ ChargeCard Balance < 500 Amount <50

■ Third put the logical operators and

parentheses:

(56)

Example 10

■ Created logical expression can be used in

following ways:

■ In assignment statement:

■ OkToChg = ChargeCard AND (Balance < 500

OR Amount <50)

■ In a decision statement:

■ If ChargeCard AND (Balance < 500 OR Amount

<50) then

Print “ Ok to Charge” Or Else

(57)

Part C

Programming Concepts

■ Objectives:

■ List and describe six basic tools used to aid in development of solution to a problem.

■ Use of problem analysis chart to consolidate data for a problem.

■ Use an interactive chart to designate the modules used in the solution to problem.

■ Use an IPO chart to designate the input, processing , module number and output for a solution of a problem.

■ Use of algorithms and flowcharts to develop instructions for solution to problem.

(58)

How the Computer Stores Data

■ Data is stored internally in memory

locations.

■ Also stored in external storage when

required in future.

■ There are basically two types of files:

■ Program Files: contains the instructions to tell

computer what to do.

■ Data files: contains the data required to

(59)

Communicating with the

Computer

■ Communication with the computer is

achieved through instructions.

■ Syntax refers to the rules governing the

computer operating system, the language and the application.

■ An error is called a bug.

■ A bug must be found and corrected, a

(60)

Organizing the Problem

■ Organizational tools will help the computer

to solve problems.

■ Following are the tools:

■ Problem Analysis Chart

■ Structure Chart or Interactivity Chart

■ IPO Chart ■ Algorithms

(61)

Analyzing the problem

■ To organize solution , the programmer has to

understand and analyze the requirements of the

problem.

■ To analyze a problem separate it into four parts:

■ The given Data

■ The required results

(62)

Analyzing the problem

Given Data Required Results

Section 1: Data given in the problem or provided by the user. These can be known values or general names for data, such as price, quantity, and so forth.

Section 2: Requirements for the output reports. This includes the information needed and the format required.

Processing Required Solution Alternatives

Section 3: List of processing required. This includes equations or other types of processing such as sorting,

searching and so forth.

Section 4: List of ideas for the solution of the problem

(63)

Analyzing the problem

■ Calculate the gross pay of employee.

Given Data Required Results

Hours PayRate

Gross Pay

Processing Required Solution Alternatives

GrossPay = Hours * PayRate

1. Define the hours worked and pay rate as

constants.

(64)

Developing the Interactivity

(Structure) chart

■ The next step is to divide the processing

into subtasks called modules

■ Connect these modules together to show

the interaction of processing between the modules.

■ Each module is responsible for executing a

(65)

Developing the Interactivity

(Structure) chart

■ Control module controls the flow to most

of the other modules.

■ The interactivity chart shows how the

modules interact with each other.

■ The interactive chart shows what will

(66)

Interactivity Chart

Module 1

Control Module

Module 2 Module 3 Module 4 Module 5

(67)

Interactivity Chart

Payroll Control

Read Calculate Print

(68)

Developing the IPO Chart

■ IPO chart extends and organizes the

information in the problem analysis chart.

■ It show in more detail what data item are

(69)

IPO Chart

■ IPO chart has four sections:

■ Input: contains all input data from the PAC

■ Processing: all processing (section 3 and 4 of

PAC)

■ Module Reference: the number from the

interactivity chart in which each step processing is completed.

■ Output: required output designated by the

(70)

IPO Chart

Input Processing Module

Reference

Output

Hours Worked Pay Rate

1. Enter hours

worked

2. Enter pay rate 3. Calculate Pay

4. Print Pay

(71)

Algorithms

■ Developing set of instructions for the

computer

■ To complete all of the algorithms needed

to solve a problem programmer writes the separate set of instruction for each module

■ The algorithms pull the interactivity chart

(72)

Drawing the Flowcharts

■ From the algorithms the programmer

develops the flowcharts.

■ Flowcharts shows the flow of the

processing from beginning to the end of a solution.

■ Algorithms and flowcharts are the final

(73)

Rules for drawing flowcharts

■ Write the instructions inside the blocks

■ If there is something to remember, write a note

besides a block. (annotated flowchart)

■ A flowchart always start at the top of the page

and flows to the bottom.

■ Use flowchart template to draw the symbols and

straightedge to draw the flowlines.

■ Make the blocks big enough to write instructions ■ Put the module number and the name from the

(74)

Algorithms and Flowchart for

Payroll problem

Algorithm Control Module ■ Repeat Process Read Process Calculate Process Print

(75)

Algorithms and Flowchart for

Payroll problem

Algorithm

Read Module

■ Read hours, Pay Rate

(76)

Algorithms and Flowchart for

Payroll problem

Algorithm

Calculate Module

■ GrossPay =

HoursWorked * PayRate

■ Exit

Calculate

GrossPay = HoursWorked * PayRate

Exit

(77)

Algorithms and Flowchart for

Payroll problem

Algorithm

Print Module

■ Print Pay

■ Exit

Print

Print GrossPay

Exit

(78)

Internal and External

Documentation

■ Internal documentation consists of

remarks written with the instructions to explain what is being done in the program.

■ External documentation is made up of the

(79)

Testing the solution

■ Test the solution to make sure it meets

the requirements of the user and to check

the errors.

(80)

References

Related documents

We have introduced a general framework for active testing that minimizes human vetting effort by actively selecting test examples to label and using performance estimators that adapt

Within this context, to contribute to the existing literature related to smart cities, this paper focuses on the philosophical aspects of building sustainable SCs and a SC

The fact that a parent may exercise “control” of the corporate actions of a foreign subsidiary should not, without more, expose the parent company to liability under the

«Work package» (WP 2) also included for each partner a proposal of literature review and analysis of : theoretical and empirical research findings; public

The results range from a high 94 per cent of listeners who identify the chocolate example as clearly or more like advertising than other program content, to a more moderate 70

In Pakistan, a recent study among the adolescents and adults of a Kara- chi squatter settlement reported that 40% of the popula- tion was using at least one chewable product of

This condition can occur because the fertilizers used are N and P fertilizers, after soaking into the paddy fields can seep into the caren land, which can spur

 Based on the outputs of the workshop, Myanma Railways has made conceptual plan for Railway container transport along the Yangon-Mandalay Railway Trunk Line... Myanmar would like