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

Problem Sovling Techniques Assignment 1

The document outlines problem-solving techniques in computing, emphasizing the importance of understanding and clearly defining problems before instructing a computer. It details the steps involved in problem-solving, including understanding, analyzing, developing solutions, and coding. Additionally, it discusses algorithms, flowcharts, and pseudo code as tools for representing solutions, along with their properties and advantages.

Uploaded by

sayyedmoiz2006
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)
4 views

Problem Sovling Techniques Assignment 1

The document outlines problem-solving techniques in computing, emphasizing the importance of understanding and clearly defining problems before instructing a computer. It details the steps involved in problem-solving, including understanding, analyzing, developing solutions, and coding. Additionally, it discusses algorithms, flowcharts, and pseudo code as tools for representing solutions, along with their properties and advantages.

Uploaded by

sayyedmoiz2006
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/ 8

Problem Solving Techniques

INTRODUCTION

A computer is a very powerful and versatile machine capable of performing a multitude of


different tasks, yet it has no intelligence or thinking power. The intelligence Quotient (I.Q) of
a computer is zero. A computer performs many tasks exactly in the same manner as it is told
to do. This places responsibility on the user to instruct the computer in a correct and precise
manner, so that the machine is able to perform the required job in a proper way. A wrong or
ambiguous instruction may sometimes prove disastrous. In order to instruct a computer
correctly, the user must have clear understanding of the problem to be solved. A part from
this he should be able to develop a method, in the form of series of sequential steps, to solve
it. Once the problem is well-defined and a method of solving it is developed, then instructing
he computer to solve the problem becomes relatively easier task. Thus, before attempt to
write a computer program to solve a given problem. It is necessary to formulate or define the
problem in a precise manner. Once the problem is defined, the steps required to solve it, must
be stated clearly in the required order.

Procedure (Steps Involved in Problem Solving)

A computer cannot solve a problem on its own. One has to provide step by step solutions of
the problem to the computer. In fact, the task of problem solving is not that of the computer.
It is the programmer who has to write down the solution to the problem in terms of simple
operations which the computer can understand and execute.

In order to solve a problem by the computer, one has to pass though certain stages or steps.
They are

1. Understanding the problem

2. Analyzing the problem

3. Developing the solution

4. Coding and implementation.

1. Understanding the problem: Here we try to understand the problem to be solved in


totally. Before with the next stage or step, we should be absolutely sure about the objectives
of the given problem.

2. Analysing the problem: After understanding thoroughly the problem to be solved, we


look different ways of solving the problem and evaluate each of these methods. The idea here
is to search an appropriate solution to the problem under consideration. The end result of this
stage is a broad overview of the sequence of operations that are to be carries out to solve the
given problem.

Page | 1
3. Developing the solution: Here the overview of the sequence of operations that was the
result of analysis stage is expanded to form a detailed step by step solution to the problem
under consideration.

4. Coding and implementation: The last stage of the problem solving is the conversion of
the detailed sequence of operations in to a language that the computer can understand. Here
each step is converted to its equivalent instruction or instructions in the computer language
that has been chosen for the implantation

ALGORITHM

Definition

A set of sequential steps usually written in Ordinary Language to solve a given problem is
called Algorithm.

It may be possible to solve to problem in more than one ways, resulting in more than one
algorithm. The choice of various algorithms depends on the factors like reliability, accuracy
and easy to modify. The most important factor in the choice of algorithm is the time
requirement to execute it, after writing code in High-level language with the help of a
computer. The algorithm which will need the least time when executed is considered the best.

Steps involved in algorithm development

An algorithm can be defined as “a complete, unambiguous, finite number of logical steps


for solving a specific problem”

Step1. Identification of input: For an algorithm, there are quantities to be supplied called
input and these are fed externally. The input is to be identified first for any specified problem.

Step2: Identification of output: From an algorithm, at least one quantity is produced, called
for any specified problem.

Step3: Identification the processing operations: All the calculations to be performed in


order to lead to output from the input are to be identified in an orderly manner.

Step4: Processing Definiteness: The instructions composing the algorithm must be clear and
there should not be any ambiguity in them.

Step5: Processing Finiteness: If we go through the algorithm, then for all cases, the
algorithm should terminate after a finite number of steps.

Step 6: Possessing Effectiveness: The instructions in the algorithm must be sufficiently basic
and in practice they can be carries out easily.

An algorithm must possess the following properties

1. Finiteness: An algorithm must terminate in a finite number of steps

2. Definiteness: Each step of the algorithm must be precisely and unambiguously stated
Page | 2
3. Effectiveness: Each step must be effective, in the sense that it should be primitive easily
convert able into program statement) can be performed exactly in a finite amount of time.

4. Generality: The algorithm must be complete in itself so that it can be used to solve
problems of a specific type for any input data. 5. Input/output: Each algorithm must take zero,
one or more quantities as input data produce one or more output values. An algorithm can be
written in English like sentences or in any standard representation sometimes, algorithm
written in English like languages are called Pseudo Code

Example

1. Suppose we want to find the average of three numbers, the algorithm is as follows

Step 1: Read the numbers a, b, c

Step 2: Compute the sum of a, b and c

Step 3: Divide the sum by 3

Step 4: Store the result in variable d

Step 5: Print the value of d

Step 6: End of the program

Algorithms for Simple Problem

Write an algorithm for the following

1. Write an algorithm to calculate the simple interest using the formula.

Simple interest = P*N* R/100.

Where P is principle Amount, N is the number of years and R is the rate of interest.

Step 1: Read the three input quantities’ P, N and R.

Step 2 : Calculate simple interest as Simple interest = P* N* R/100

Step 3: Print simple interest.

Step 4: Stop

2. Area of Triangle: Write an algorithm to find the area of the triangle.

Let b, c be the sides of the triangle ABC and A the included angle between the given sides.

Step 1: Input the given elements of the triangle namely sides b, c and angle between the sides
A.

Step 2: Area = (1/2) *b*C* sin A

Page | 3
Step 3: Output the Area

Step 4: Stop.

3. Write an algorithm to find the largest of three numbers X, Y,Z.

Step 1: Read the numbers X,Y,Z.

Step 2: if (X > Y)

Big = X

else BIG = Y

Step 3 : if (BIG < Z)

Step 4: Big = Z

Step 5: Print the largest number i.e. Big

Step 6: Stop.

4. Write down an algorithm to find the largest data value of a set of given data values Algorithm
largest of all data values:

Step 1: LARGE  0

Step 2: read NUM

Step 3: While NUM > = 0 do

3.1 if NUM > LARGE then

LARGE  NUM

3.2. read NUM

Step 4: Write “largest data value is”, LARGE

Step 5: end.

5. Write an algorithm which will test whether a given integer value is prime or not.
Algorithm prime testing:
Step 1: M  2
Step 2: read N
Step 3: MAX  SQRT (N)
Step 4: While M < = MAX do
4.1 if (M* (N/M) = N 4.1.1 then
4.1.1.1 go to step 7
4.2. M  M + 1
Step 5: Write “number is prime”
Step 6: go to step 8

Page | 4
Step 7: Write “number is not a prime”
Step 8: end.

6. Write algorithm to find the factorial of a given number N

Step 1: PROD  1
Step 2: I  0
Step 3: read N
Step 4: While I < N do
4.1 I  I + 1
4.2. PROD  PROD* I
Step 5: Write “Factorial of”, N, “is”, PROD
Step 6: end.
7. Write an algorithm to find sum of given data values until negative value is entered.
Algorithm Find – Sum

Step 1: SUM  0
Step 2: I  0
Step 3: read NEW VALUE
Step 4: While NEW VALUE < = 0 do
4.1 SUM  SUM + NEW VALUE
4.2 1  I + 1 4.3 read NEW VALUE
Step 5: Write “Sum of”, I, “data value is, “SUM
Step 6: END

7. Write an algorithm to find sum of given data values until negative value is entered.
Algorithm Find – Sum
Step 1: SUM  0
Step 2: I  0
Step 3: read NEW VALUE
Step 4: While NEW VALUE < = 0 do
4.1 SUM  SUM + NEW VALUE
4.2 1  I + 1
4.3 read NEW VALUE
Step 5: Write “Sum of”, I, “data value is, “SUM
Step 6: END

FLOWCHART

A flow chart is a step by step diagrammatic representation of the logic paths to solve a given
problem. Or A flowchart is visual or graphical representation of an algorithm.
The flowcharts are pictorial representation of the methods to be used to solve a given
problem and help a great deal to analyze the problem and plan its solution in a systematic and
orderly manner.

Page | 5
A flowchart when translated in to a proper computer language, results in a complete program.
Advantages of Flowcharts
1. The flowchart shows the logic of a problem displayed in pictorial fashion which felicitates
easier checking of an algorithm.
2. The Flowchart is good means of communication to other users. It is also a compact means
of recording an algorithm solution to a problem.
3. The flowchart allows the problem solver to break the problem into parts. These parts can
be connected to make master chart.
4. The flowchart is a permanent record of the solution which can be consulted at a later time.

Table 1: Flow chart

Name Symbol Use in flow chart


Oval Use to start or stop the
algorithm
Arrow Use to show the direction of
flow
Parallelogram Use to perform the input or
output (Input from keyboard
and output to monitor)

Rectangle Use to indicate operation is


to be performed (i.e.
addition, subtraction,
multiplication or division)

Diamond Use to take decision It has


one input and two outputs
based on condition checked
is true or false.

A flowchart is a graphical representation of the algorithm as discussed earlier. The flowchart


gives a very nice idea of the flow of the algorithm in sequence as well as the conditional
changes in the sequence. Before drawing the flowcharts, we need to know the symbols used
for making the flowchart. Table 1 shows the various symbols used for drawing the
flowcharts. As shown in the Table 1 various symbols are used for performing the different
operations as indicated in the last column of the table.

Example

Draw the flow chart to add two numbers

Page | 6
Flow chart 1

As shown in the Flowchart 1, initially two numbers are accepted from user, this is shown
using a parallelogram. The two numbers are then added, shown using a rectangle. The result
is displayed, again shown using parallelogram. The start and stop are shown in using oval.

Practice Questions:
1) Draw a flow chart for product of two numbers
2) Draw a flow chart to find the square of a number
3) Draw the Flowchart to find Roots of Quadratic equation ax2+ bx + c = 0. The
coefficients a, b, c are the input data
4) Draw a flowchart to find out the biggest of the three unequal positive numbers.
5) Draw a flowchart for adding the integers from 1 to 100 and to print the sum.
6) Draw a flowchart to find the factorial of given positive integer N.

Pseudo code
The Pseudo code is neither an algorithm nor a program. It is an abstract form of a
program. It consists of English like statements which perform the specific operations.
It is defined for an algorithm. It does not use any graphical representation. In pseudo
code, the program is represented in terms of words and phrases, but the syntax of
program is not strictly followed.
Advantages: * Easy to read, * Easy to understand, * Easy to modify.
Example:
Write a pseudo code to perform the basic arithmetic operations.
Read n1, n2
Sum = n1 + n2

Page | 7
Diff = n1 – n2
Mult = n1 * n2
Quot = n1/n2
Print sum, diff, mult, quot
End

Page | 8

You might also like