Presentation is loading. Please wait.

Presentation is loading. Please wait.

Problem Solving Skill Area 305.1

Similar presentations


Presentation on theme: "Problem Solving Skill Area 305.1"— Presentation transcript:

1 Problem Solving Skill Area 305.1
Materials Prepared by Dhimas Ruswanto, BMm Skill Area 305.1 Problem Solving

2 Lecture Overview Problem Solving Algorithm Dry Run

3 PROBLEM SOLVING Problem-Solving methodology: Define the problem
Outline the solution Develop an algorithm Test the algorithm

4 DEFINE THE PROBLEM Have a thorough understanding of the problem
State the problem in clear and concise terms to avoid any confusion or misunderstanding Examples: Calculate the sum and the average of two numbers 25 & 45

5 OUTLINE THE SOLUTION The problem can be divided into three components:
Inputs – What do you have? Outputs – What do you want to have? Processing – How do you go from inputs to outputs? Examples: Calculate the sum and the average of two numbers 25 & 45

6 OUTLINE THE SOLUTION (cont’d)
Inputs = First number = a = 25 Second number = b = 45 Outputs = sum average Processing = sum = a +b Average = a+b 2

7 ALGORITHM An algorithm is a written step by step solution to a problem. Why bother writing an algorithm? For your own use in the future. You won’t have to rethink the problem. So others can use it, even if they know very little about the principles behind how the solution was derived

8 ALGORITHM (cont’d) An algorithm is a finite set of unambiguous, executable instructions that directs a terminating activity. GOAL: To find a single set of instructions that can be used to solve any problem of a particular type (a general solution).

9 EXAMPLE OF ALGORITHM MAKE A CALL

10 EXAMPLES OF ALGORITHM

11 ALGORITHM REPRESENTATION
Syntax: The grammar of the language The way in which we construct sentences by following principles and rules Semantics: The meaning The interpretations of and meanings derived from the sentence transmission and understanding of the message

12 SYNTAX AND SEMANTIC Sentence : “Baby milk drinks”
Does not have a syntactic meaning But through semantics most people would interpret it as meaning “Baby drinks milks”, therefore we can find a meaning from key words.

13 SYNTAX AND SEMANTIC (CONT’D)
In programming language: Syntax defines how logical entities expressed in characters Semantics describe the logical entities of a programming language and their interactions Examples: x = 0 - 1; y = - 1; the syntax for the "-" token is the same, but, it has a different meaning ("semantic), depending where its used. In the "x" assignment, "-" means the "subtraction" operation, In the "y" assignment, "-" means the "negative sign" operation.

14 DEVELOP AN ALGORITHM Decompose the problem into simpler steps and expresses the solution in terms of actions to be executed order in which these actions are to be executed Examples: Calculate the sum and the average of two numbers 25 & 45

15 DEVELOP AN ALGORITHM (CONT’D)
Declare two variables, a and b Initialise both variables to 0 a= 0, b= 0 Ask user to enter first number Assign user input to a variable Ask user to enter second number Assign user input to second b variable Add first num to second num Print the sum Divide the sum by 2 Print the average

16 TEST THE ALGORITHM The programmer must make sure that the algorithm is correct. The objective is to identify major logic errors early, so that they may be easily corrected. Test data should be applied to each step, to check whether the algorithm actually does what it is supposed to.

17 DRY RUN You can test your program without using a computer by dry running it on paper Dry runs involves the execution of code segments. You act as the computer – following the instructions of the program, recording the valves of the variables at each stage You can do this with a table

18 DRY RUN (Cont’d) The table with have column headed with the names of the variables in the program Each row in the table will be labelled with a line number form the program. The entries of each row in the table will be values of the variables after the execution of the statement on that line You don’t need a row for every line in the program, just those lines where some significant change to the state of the program occurs e.g a variable gets a new value

19 DRY RUN (Cont’d) In this table you can record all relevant changes to the variables as the program progresses, thereby test the logic of the program / algorithm Do a dry run before you code your program on computer this way any logic errors will come to light during the dry run

20 Example of DRY RUN L1 Declare two variables, a and b
L2 Initialise both variables to 0 L3 a= 0, b= 0 L4 Ask user to enter first number L5 Assign user input to a variable L6 Ask user to enter second number L7 Assign user input to second b variable L8 Add first num to second num L9 Print the sum L10 Divide the sum by 2 L11 Print the average Do a Dry run for this program assuming the user enters 18 for first number and 24 for the second

21 A Sample of DRY RUN table
After execution First num Second num Sum Average Line 2 Line 5 18 Line 7 24 Line 8 42 Line 10 21

22 SUMMARY An algorithm is a finite set of unambiguous, executable instructions that directs a terminating activity. Syntax: The grammar of the language Semantics: The meaning Dry runs involves the execution of code segments.


Download ppt "Problem Solving Skill Area 305.1"

Similar presentations


Ads by Google