0% found this document useful (0 votes)
191 views41 pages

Problem Solving Concept by Meetendra Sir (Unit 5)

This document discusses problem solving concepts and techniques. It introduces problem solving, defines problem definition as the first step, and discusses techniques like trial and error, brainstorming, and divide and conquer. It explains problem solving involves defining the problem, analyzing it, and exploring solutions. Algorithms are defined as unambiguous instructions to solve problems, and characteristics and advantages of algorithms are provided. Finally, a flowchart example for addition is presented.

Uploaded by

Meetendra Singh
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)
191 views41 pages

Problem Solving Concept by Meetendra Sir (Unit 5)

This document discusses problem solving concepts and techniques. It introduces problem solving, defines problem definition as the first step, and discusses techniques like trial and error, brainstorming, and divide and conquer. It explains problem solving involves defining the problem, analyzing it, and exploring solutions. Algorithms are defined as unambiguous instructions to solve problems, and characteristics and advantages of algorithms are provided. Finally, a flowchart example for addition is presented.

Uploaded by

Meetendra Singh
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/ 41

UNIT-5

Problem Solving Concepts


Meetendra Singh Chahar
Astt. Professor
R.B.S.M.T.C, Agra
MEETENDRA SINGH CHAHAR

INTRODUCTION
A problem obstructs and hinders the progress or movement
in achieving of an objective.
The nature of the problem depends on the situation.
In problem solving each individual may have his or her own
unique way.

MEETENDRA SINGH CHAHAR

PROBLEM DEFINITION
Problem definition is the first and most important step in
determining information needs.
Information needs of software can be determined by:
1.

Studying the existing system

2. Using questionnaires
3. Stating the tentative information needs
4. Suggesting interpretation of information needs with
users.

MEETENDRA SINGH CHAHAR

PROBLEM SOLVING TECHNIQUES


For solving a problem there are many techniques available,
some of popular techniques are:
1.

Trail & Error Method

2. Brain Storming Method


3. Divide & Conquer Method

MEETENDRA SINGH CHAHAR

1. TRAIL & ERROR METHOD


This is an iterative method.

It is based on the idea of successive approximation.


Starting with initial approximation to the root.
It is the most natural technique because in this sequence
of steps is repeated over and over again.

MEETENDRA SINGH CHAHAR

2. BRAINSTORMING METHOD
Brainstorming is a group activity designed to increase the
quantity of fresh ideas.
or
Brainstorming is a group method for obtaining new ideas and
business solutions.
The groups are organized for sitting together and stimulate
greater creativity by exchange of mutual experiences and
participating in the discussions.
The brainstorming ideas are canalized to a particular
segment of product line or services.

MEETENDRA SINGH CHAHAR

Method of Conducting Brainstorming Sessions


The group should be informed of the broad areas of the
subject or area of discussions.
The group should consist of people drawn from different
streams of knowledge such as marketing, production, quality
control, planning, finance, costing, stores, handling, taxation
and the like. The group also should consist of different
levels of officers, supervisors from the organization.
The brainstorming session should be held in a good place
with ambience. So, that the group comes open with their
ideas.
To be continued

MEETENDRA SINGH CHAHAR

The member should have no inhibitions about their status in


the organization or department where they serve. The
session should be frank and be fun. The brainstorming
sessions are held where no individual or group dominate the
discussions and no boss-subordinate relationships.
Day dreaming or wild ideas to be encouraged.
There should not be any negative comments or criticisms
against any particular individuals or groups or departments.
The ideas of one can be improved by others but no
repetition of ideas. Each individual may be given a chance to
three ideas and these ideas being recorded on a flip chart
or black board. All the ideas are recorded on the flip chart
even if one idea is not practical or ill-logical.

MEETENDRA SINGH CHAHAR

3. DIVIDE & CONQUER METHOD


Steps in Divide and Conquer Algorithm
Divide Step: In this step of the algorithm, the input is
partitioned into p 1 parts, each of size strictly less than n,
the size of the original instance. The most common value of
p is 2, although other small constants greater than 2 are
not uncommon.
Conquer Step: This step consists of performing p recursive
call(s) if the problem size is greater than some pre-defined
threshold n0 . This threshold is derived by mathematical
analysis of the algorithm. Once it is found, it can be
increased by any constant amount without affecting the
time complexity of the algorithm.
Combine Step: In this step, the solutions to the p recursive
call(s) are combined to obtain the desired output. The
combine step in a divide-and-conquer algorithm may consist
of merging, sorting, searching, finding the maximum or
minimum, matrix addition, etc.
MEETENDRA SINGH CHAHAR

Divide-and-conquer algorithm consists of


following major phases:
1.

Breaking the problem into several sub-problems that


are similar to the original problem but smaller in size.

2. Solve the sub-problem recursively (successively and


independently), and then,

3. Combine these solutions to sub-problems to create a


solution to the original problem.

MEETENDRA SINGH CHAHAR

10

A Problem of Size
n (Instance)

Subproblem 1 of
Size n/2

Subproblem 2 of
Size n/2

A Solution to
Subproblem 2

A Solution to
Subproblem 1

A Solution to the
Original Problem

MEETENDRA SINGH CHAHAR

Divide-and-Conquer Strategy

11

STEPS IN PROBLEM SOLVING


There are mainly three steps to solving a problem-

1.

Defining the Problem

2. Analyze the Problem


3. Explore Solution

MEETENDRA SINGH CHAHAR

12

1. DEFINING THE PROBLEM


When a problem is to be solved, two question arise,
1.

What to do ?

2. How to do ?
This phase answer the first question.
Here, the programmer has to defined the task
precisely(correctly) and check for completeness.
There should not be any ambiguity(confusion).

The imprecisely or arbitrarily defined problem may result in


wrong analysis and design.
To be continued

MEETENDRA SINGH CHAHAR

13

Different programmers may program this problem as peer


their understanding.
The problem definition skill is directly proportional to the
depth of understanding of the programmer.
In the problem definition phase, the programmer has to
reflect all the possibilities that need decision-making.

MEETENDRA SINGH CHAHAR

14

2. ANALYZE THE PROBLEM


This is the programmers talent-testing phase.

A good analysis may result in good designing and coding.


In this phase, the programmer has to answer the second
question, How to do?
This is the initial investigation of the problem.
The programmer has to declare the computational
strategies to analyze the defined problem with the help of
available tools.
Programming techniques like sequence, selection and
iteration can be used to develop the logic for analysis.
To be continued
MEETENDRA SINGH CHAHAR

15

The primary operations that are performed on data are


arithmetic, logical and relational.
The mostly used database operations are searching, sorting,
inserting, merging, etc.
Once we analyze the problem, the next phase is to design
the program.

MEETENDRA SINGH CHAHAR

16

3. EXPLORE SOLUTION
When programmer complete the analysis then he/she will
explore (or design) the different solution of the problem
and the best or optimum solution is chooses by the
development team.

Once the problem is defined and the idea of how to solve it


is developed, the programmer can begin designing algorithm.
Before starting designing, the problem must be refined
step-wise. This is known as the top-down design.

It is a strategy where the problem is divided into a


hierarchical structure.
To be continued

MEETENDRA SINGH CHAHAR

17

A separate sub-program may be designed for each module.


The top-down approach provides a method of handling the
inherent logical complexity.
This allows the programmer to build solution in a step-wise
manner.

MEETENDRA SINGH CHAHAR

18

Steps of using a Computer as a ProblemSolving Tool


Develop an Algorithm and a Flowchart.
Write the program in a computer language. (i.e. C, C++, etc.)
Enter the program into the computer.
Test and debug the program.
Run the program, input data and get the results from the
computer.

MEETENDRA SINGH CHAHAR

19

ALGORITHMS
An algorithm is any well-defined computational procedure
that takes some value, or set of values, as input and
produces some value, or set of values, as output.

An algorithm is thus a sequence of computational steps


that transform the input into the output.
or

An algorithm is a sequence of unambiguous instructions for


solving a problem.
Obtaining a required output for any valid input in a
finite amount of time.

Procedural solutions to problems.


To be continued

MEETENDRA SINGH CHAHAR

20

Computer is capable of understanding and following the


instructions given.

An input specifies an instance of the problem, the algorithm


solves.
Problem

Algorithm

Input

Computer

Output

Notion of Algorithm
MEETENDRA SINGH CHAHAR

21

The word algorithm comes from the name of the 9 th


century Persian Muslim mathematician Abu Abdullah
Muhammad ibn Musa Al Khwarizmi.

An algorithm is an effective method for solving a problem


using a finite sequence of instructions.
The computational complexity and efficient implementation
of the algorithm are important in computing and this
depends on suitable data structure.
Each algorithm is a list of well-defined instructions for
completing a task.

MEETENDRA SINGH CHAHAR

22

Format of an Algorithm
Input:

Step 1:

Step 2:

Step 3:

..
..
..
Step n:

Output:

MEETENDRA SINGH CHAHAR

23

Characteristics of an Algorithm
Finiteness: Terminates after a finite number of steps.
Definiteness: Rigorously and unambiguously specified.
Input: Valid inputs are clearly specified.
Output: Can be proved to produce the correct output given
a valid input.
Effectiveness: Steps are sufficiently simple and basic.

MEETENDRA SINGH CHAHAR

24

Advantages of an Algorithm
Provides step by step procedure to understand easily.
Algorithm is easy to write.
Solves those problems which are complex and not solve by
simple methods.
Algorithm in general, can be directly coded in a
programming language.

MEETENDRA SINGH CHAHAR

25

Example- Addition of two numbers.


Algorithm

Step 1: START
Step 2: Initialize x, y and z
Step 3: Read x, y
Step 4: Calculate z = x + y
Step 5: Print Sum of two numbers, z
Step 6: STOP

MEETENDRA SINGH CHAHAR

26

FLOWCHARTS
A flowchart is a graphical representation of an algorithm.
or
A flowchart is a diagram that is prepared by the
programmer which represents the sequence of steps
involved in solving a problem.
It is an aid to solve a complex problem easily and
efficiently.
It is also used to correct and debug a program flow after
the coding part is completed.
To be continued

MEETENDRA SINGH CHAHAR

27

It is one of the best tool for testing and maintaining a


software.
A flowchart is sometimes called as a logic diagram in a
programming parlance.

Its diagrammatic representation can give a step-by-step


solution to a given problem.
It provides not only a detailed view of a program flow but
also used as a blueprint of the software project that shows
the general plan, architecture and essential details of the
proposed software structure.

MEETENDRA SINGH CHAHAR

28

Flowchart Symbols
In constructing flowcharts, standard symbols are used.
The American National Standard Institute(ANSI) symbols
are normally used.
Some important flowchart symbols are given here:

MEETENDRA SINGH CHAHAR

29

Symbols

Name(Attribute)
Process
Terminator
Decision
Delay

MEETENDRA SINGH CHAHAR

Description
An operation or action step.
A start or stop point in a process.
A question or branch in the process.
A waiting period.

Data(I/O)

Indicates data inputs and outputs to


and from a process.

Alternate
Process

An alternate to the normal process


step.

Flow Line

Indicates the direction of flow for


materials and/or information

Flowchart Symbols

30

Symbols

Name(Attribute)
Predefined
Process

A formally defined sub-process

Document

A document or report

Multi-Document

Same as Document, except, well,


multiple documents

Preparation

A preparation or set-up process


step

Display

MEETENDRA SINGH CHAHAR

Description

A machine display

Manual Input

Manually input into a system

Stored Data

A general data storage flowchart


symbol

Flowchart Symbols

31

Symbols

Name(Attribute)

Description

Punched Tape

An old computer punched tape input

Merge (Storage)

Merge multiple processes into one.

Extract
(Measurement)

Extract(split process) or more


commonly a measurement

Magnetic Disk
(Database)

A database

Direct Access
Storage

Storage on a hard disk

Internal Storage Data stored in memory


Sequential
Access Storage

MEETENDRA SINGH CHAHAR

An old reel of tape

Flowchart Symbols

32

Example- Addition of two numbers.


Flowchart
START

Initialize sum
& Read x, y

sum = x +y

Print sum

STOP
MEETENDRA SINGH CHAHAR

33

PSEUDO CODE
Pseudo code is an artificial and informal language that helps
programmers to develop algorithms.
Pseudo code is a text-based detail (algorithmic) design
tool.
It is a compact and informal high-level description of a
computer programming algorithm that uses the structural
conventions of a programming language, but is intended for
human reading rather than machine reading.
Pseudo code typically omits details that are not essential
for human understanding of the algorithm, such as variable
declaration, etc.
To be continued
MEETENDRA SINGH CHAHAR

34

The purpose of using pseudo code is that it is easier for


humans to understand than conventional programming
language code.
It is commonly used in textbooks and scientific publications
that are documenting various algorithms and also in planning
of computer program development, for sketching out the
structure of the program before the actual coding takes
place.

MEETENDRA SINGH CHAHAR

35

Conventions for Pseudo Code


Pseudo code should be clear and easy to understand.
Give a valid name for the pseudo code procedure.
Use the line numbers for each line of code.
Use proper indentation for every statement in a block
structure.
For a flow control statements use if-else. Always end an if
statement with an end-if. Both if-else and end-if should be
aligned vertically in same line.
For example,
if(condition expression)
statements

else statements
end-if
To be continued
MEETENDRA SINGH CHAHAR

36

Use = or

operator for assignment statements.

For example
i = j or i

Array elements can be represented by specifying the array


name followed by the index in square brackets.
For ex., A[i] indicates the i th element of the array A.

MEETENDRA SINGH CHAHAR

37

Loops in pseudo code


For looping or iteration use for or while statements.
Always end a for loop with end-for and a while with endwhile.
The conditional expression of for or while can be written.
We can separate two or more conditions with an and.

MEETENDRA SINGH CHAHAR

38

Example- Finding maximum no.


Algorithm: arrayMax(a[1...n], n)

Step 1: max = a[1]


Step 2: For i = 2 to n do
Step 3:

If a[i] > max, then

Step 4:

max = a[i]

Step 5:

Endif

Step 6: Endfor
Step 7: Return max

MEETENDRA SINGH CHAHAR

39

TIME COMPLEXITY
Time Complexity of an algorithm is the amount of computer
time it needs to run to completion.
This is the sum of compile time and run time.
Some of the reasons for studying time complexity are:
1.

We may be interested to know in advance that whether


an algorithm/program will provide a satisfactory real
time response.

2. There may be several possible solutions with different


time requirements.
To be continued

MEETENDRA SINGH CHAHAR

40

We can found complexity of any algorithm using following


notation:
Big-Oh notation: Big-Oh is the formal method of
expressing the upper bound of an algorithms running
time. It is the measure of the longest amount of time it
could possibly take for the algorithm to complete. More
formally, for non-negative functions, f(n) and g(n), if
there exists an integer n 0 and a constant c > 0 such that
for all integers n > n 0
f(n) c.g(n)
Then f(n) is Big-Oh of g(n). This is denoted as

f(n) O(g(n))

MEETENDRA SINGH CHAHAR

41

You might also like