Lecture 2:  Problem Solving Concepts.

 

Overview:

q       Problem Solving is a creative act and cannot be completely explained

q       There are many methods that help structure our thoughts as we solve problems

q       The Prominent are:  Analytic, Algorithmic & Software engineering

 

Objective of this Lecture:

q       Discuss two problem solving methods – Analytic &  Algorithmic

q       Solve  example problems using each of these methods

 

Common Components (steps)

Each of these two methods consists of four basic components

q       Problem:-   Specification of the problem to be solved

q       Reasoning:-      Comprehension of the problem (Analysis)

q       Solution:- Specification of the solution (Design)

q       Test:         Checking that the solution is correct

 

The Analytic approach

q       It is used to solve mathematic, physics and similar sciences & engineering problems

q       The method (solution component) involves :

Ø      Isolating the given quantities, denoting them by some variables

Ø      Identifying the relation (equation) connecting the quantities

Ø      Solving the equation by applying some algebraic rules and/or applying existing formulae

Example :

Problem:  A school needs 12 identical computers for a laboratory.  Carpeting & furniture is budgeted at $6,000.00.  If the total budget is 90,000.00, write an algorithm that finds the highest cost of the most affordable computer the school can buy.

 

Reasoning:  To find the highest cost of the most affordable computer, first we subtract the cost of carpeting & furniture from the total budget and then divide the result by 12.

 

Solution:  Let x be the cost of one such computer.  Then the cost of 12 such computers is 12x.  The budget for the 12 computers is the total budget less the cost of carpeting and furniture.

i.e.     12x = total – cost of carpeting & furniture

i.e.     12x = 90000 – 6000

i.e.     12x = 84000

so that          x = 84000/12

                 = 7000

 

Test:  To test the solution, we Substitute in the first equation:

   LHS = 12 x 7000 = 84000 = RHS

 

Note:  Many problems cannot be solved analytically, for example, the polynomial :

   Ax5 + bx4 + cx3 + dx2 + ex + f = 0 ,  f¹0.

 

The Algorithmic Approach

q       This was first developed by an Arab mathematician called Al-Khuwarizmi.

q       It involves breaking down a solution into a sequence of executable instruction with the following properties:

Ø      There is no ambiguity in any instruction.

Ø      There is no ambiguity in the order of execution.

Ø      The sequence is finite

Ø      Execution terminates after a finite number of steps.

q       Algorithmic solutions are not unique and are not restricted to mathematical problems.

q       In the reasoning step, the problem is summarized by generating a formal statement.  This specifies:

Ø      The input needed

Ø      The output to be produced &

Ø      The process to be performed to get the output

q       In the solution step, the actions needed to solve the problems are listed in sequence.  Some of these actions may be skipped depending on certain condition (selection) and the entire sequence of actions of part of the sequence may be repeated (repetition).

 

q       The test step involved applying the algorithm to various input data to ensure that it works.

 

Elements of an Algorithmic Language.

The sequence of instruction in an algorithm are written using pseudocodes – words that resemble high label programming language.  The table below summarises these words:

 

LANGUAGE ELMTS.

MEANING

INPUT

Accept data from user

OUTPUT

Send results to the user

=

Assign the result of the expression on the right to the variable on the left

STOP

End the algorithm

IF ELSE

For selection

LOOP

For repetition involving a specified number of times

WHILE

For repetition that terminates based on a condition (unspecified number of times)

  

 Example 1:

 

Problem:  Write an algorithm to compute the volume of a sphere.  The algorithm should check that the radius is greater than 0. (Take p = 3.14159)

 

Reasoning:  We need to  use the formula for computing the volume of a sphere. We need to use selection so that we only compute the volume for positive radius

 

   Formal Statement:  Volume of a sphere problem

   Input:  radius

   Ouput: volume

   Process: Volume = (4/3)*3.14159*radius*radius*radius

 

Solution:

Step1: INPUT radius

Step2: IF radius > 0

a.  volume = (4/3)*3.14159*radius*radius*radius

b.  OUTPUT volume

Step3: STOP

 

Test:  The algorithm can be checked by trying it with positive and negative values of the radius.

 

Example 2:

 

Problem :  Modify example 1 to allow the user to repeatedly enter values for the radius and print the volume of the corresponding sphere, and terminates when the radius is less than or equal to zero.

 

Reasoning: Same as example 1 except that we need to use repetition.

 

Solution:

Step1: INPUT radius

Step2: WHILE radius > 0

a.  volume = (4/3)*3.14159*radius*radius*radius

b.  OUTPUT volume

Step3: STOP

 

Test:  The algorithm can be checked by trying it with a number of positive and negative values of the radius.