Chapter1

Page 1



Learning Outcomes Types of problem. Recognize 6 steps in problem solving. Recognize 7 steps in program development process. Pseudocode and Algorithm Difficulties with problem solving with computer


Types of problem Algorithmic solutions Can be solved with a series of actions (algorithms) Log on to an e-mail account  Withdraw cash from ATM machine 

Heuristic solutions (rule of thumb) Based on knowledge & experience Requires a process of trial and error Add Salt to food (during cooking)  Buying the best stock 


Types of problem – (cont) 6-steps can be used for both problems But step 6 (for heuristic solutions)

Correctness and appropriateness far less certain  May need to iterate (repeat) many times  Same solution may not work all the time 

Most problems require a combination of the two kinds of

solutions Driving a vehicle Fix a malfunction computer


Problem solving with computers  Computers built for dealing with algorithmic solutions Write instruction step by step

Heuristic solutions requires (Artificial) intelligence The program can make decision like human when for each

situation base on previous solution Need to transform into algorithmic format


Problem Solving in Everyday Life Problem-solving process (6 steps) –Identify the problem

What to do?

–Understand the problem

Knowledge base required

–Identify alternatives

Other acceptable methods

–Select the best way to solve the problem –List the instructions

All steps required

–Evaluate the solution

Check to see if result is correct


Problem Solving in Everyday Life Example : Y ou are doing assignment at home, and you are hungry Identify problem : you are hungry Understand the problem : you need food Identify Alternatives : 1.) look for mum  2.) go to kitchen and look for some food  3.) go to kitchen and prepare food yourself  4.) make a food delivery order  5.) go out to have a meal in restaurant / hawker center 


Problem Solving in Everyday Life Example (continued) Select the best way

Method 1 : you aren’t kid anymore   Method 2 : might be a good idea  Method 3 : you might not have time since you are doing assignment.  Method 4 : might be expensive  Method 5 : you might not have time since you are doing assignment. 

After some consideration, let say you choose method 2


Problem Solving in Everyday Life Example (continued) List out the instruction

Go out from the room  Go to kitchen  Search the table, cabinet, refrigerator for food  Consume the food 

 evaluate the solution

Is the solution help to solve the problem?  Is the solution solve the problem efficiently?  Should we follow the same solution next time? 


7 Steps of Program Development Process  Programming can be defined as the development of a

solution to an identified problem, and the setting up of a related series of instructions that will produce the desired results Define the Problem To help with initial analysis, the problem should be divided into three separate components: • the inputs • the outputs • the processing steps to produce the required outputs


7 Steps of Program Development Process 1. Define the problem

Outline the solution Develop an algorithm (based on the outline) Test the algorithm (for correctness) Code the algorithm (into a specific programming language) Run the program (on the computer) 7. Document & Maintain the program 2. 3. 4. 5. 6.


1 Define the Problem To help with initial analysis, the problem should be

divided into three separate components: • the inputs • the outputs • the processing steps to produce the required outputs Use IPO chart (Input Process Output chart)


1 Define the Problem Example: Shop A is offering a 20% discount for all products. Calculate the payment for the customers. Input  Discount rate, original price of the products  Output  payment  Process  Calculate payment 


2 Outline the Solution This initial outline is usually a rough draft of the solution

and may include: • The major processing steps involved • The major subtasks (if any) • The user interface (if any) • The major control structures (e.g. repetition loops) • The major variables and record structures • The mainline logic


2 Outline the Solution Example (step by step to solve the problem) : Get the price of product purchase by the customer Get the discount rate Calculate the discount amount Calculate the payment after discount Display the payment amount to the customer


3 Develop the Outline into an Algorithm The solution outline developed in Step 2 is expanded into

an algorithm: a set of precise steps that describe exactly the tasks to be performed and the order in which they are to be carried out Develop flow chart and pseudocode from IPO chart


4 Test the Algorithm for Correctness This step is one of the most important in the development of a program, and

yet it is the step most often forgotten The main purpose of desk checking (test the algorithm) is to identify major

logic errors early, so that they may be easily corrected Early error identification is better because will save time and cost


5 Code the Algorithm into a Specific Programming Language Only after all design considerations have been met should

you actually start to code the program into your chosen programming language (e.g c++, c , Java)


6 Run the Program on the Computer This step uses a program compiler and programmer-

designed test data to machine test the code for syntax

errors and logic errors


7 Document and Maintain the Program Program documentation should not be listed as the last

step in the program development process, as it is really an ongoing task from the initial definition of the problem to the final test result Documentation involves both external documentation and

internal documentation that may have been coded in the program


Algorithms and Pseudocode A program must be systematically and properly designed

before coding begins

This design process results in the construction of an

algorithm


What Is an Algorithm? An algorithm is like a recipe: it lists the steps involved in

accomplishing a task It can be defined in programming terms as a set of

detailed, unambiguous and ordered instructions developed to describe the process necessary to produce the desired output from a given input


Types of algorithm From algorithm, we also can have: Pseudocode (more English-like) Flowcharts Nassi-Schneiderman diagrams

As all above are all popular ways of representing algorithms


Difficulties with problem solving Why difficult to solve problem Most people do not complete adequately the problem-

solving process Problem-solving process requires time and practice Problem with writing the instruction E.g. List 5 numbers and pick the largest one. (Can you explain/list all the steps required?)  Computer (a tool) can perform only task that user can explain step by step  All steps must be in proper order 


Summary ď‚— The steps in program development were introduced and

briefly described below: 1. Define the problem 2. Outline the solution

3. Develop the outline into an algorithm 4. Test the algorithm for correctness 5. Code the algorithm into a specific programming language 6. Run the program on the computer 7. Document and maintain the program


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.