Latest Problem Solving Class 11 Notes includes Problem Solving, steps, algorithm and its need, flow chart, pseudo code with lots of examples.

Contents

**What is Problem Solving?**

Problem solving is the process of identifying a problem, analyze the problem, developing an algorithm for the identified problem and finally implementing the algorithm to develop program.

**Steps for problem solving**

There are 4 basic steps involved in problem solving

- Analyze the problem
- Developing an algorithm
- Coding
- Testing and debugging

**Analyze the problem**

Analyzing the problem is basically understanding a problem very clearly before finding its solution. Analyzing a problem involves

- List the principal components of the problem
- List the core functionality of the problem
- Figure out inputs to be accepted and output to be produced

**Developing an Algorithm**

- A set of precise and sequential steps written to solve a problem
- The algorithm can be written in natural language
- There can be more than one algorithm for a problem among which we can select the most suitable solution.

**Coding**

Algorithm written in natural language is not understood by computer and hence it has to be converted in machine language. And to do so program based on that algorithm is written using high level programming language for the computer to get the desired solution.

**Testing and Debugging**

After writing program it has to be tested on various parameters to ensure that program is producing correct output within expected time and meeting the user requirement.

There are many standard software testing methods used in IT industry such as

- Component testing
- Integration testing
- System testing
- Acceptance testing

**What is Algorithm?**

- A set of precise, finite and sequential set of steps written to solve a problem and get the desired output.
- Algorithm has definite beginning and definite end.
- It lead to desired result in finite amount of time of followed correctly.

**Why do we need Algorithm?**

- Algorithm helps programmer to visualize the instructions to be written clearly.
- Algorithm enhances the reliability, accuracy and efficiency of obtaining solution.
- Algorithm is the easiest way to describe problem without going into too much details.
- Algorithm lets programmer understand flow of problem concisely.

**Characteristics of a good algorithm**

**Precision**— the steps are precisely stated or defined.**Uniqueness**— results of each step are uniquely defined and only depend on the input and the result of the preceding steps.**Finiteness**— the algorithm always stops after a finite number of steps.**Input**— the algorithm receives some input.**Output**— the algorithm produces some output.

**What are the points that should be clearly identified while writing Algorithm?**

- The input to be taken from the user
- Processing or computation to be performed to get the desired result
- The output desired by the user

**Representation of Algorithm**

An algorithm can be represented in two ways:

- Flow chart
- Pseudo code

**Flow chart**

- Flow chart is visual representation of an algorithm.
- It’s a diagram made up of boxes, diamonds and other shapes, connected by arrows.
- Each step represents a step of solution process.
- Arrows in the follow chart represents the flow and link among the steps.

**Flow Chart Examples**

**Example 1:** **Write an algorithm to divide a number by another and display the quotient.**

**Input:** Two Numbers to be divided**Process:** Divide number1 by number2 to get the quotient**Output:** Quotient of division

**Algorithm**

Step 1: Input a two numbers and store them in num1 and num2

Step 2: Compute num1/num2 and store its quotient in num3

Step 3: Print num3

**Flow chart**

**Pseudo code**

- Pseudo code means ‘not real code’.
- A pseudo code is another way to represent an algorithm. It is an informal language used by programmer to write algorithms.
- It does not require strict syntax and technological support.
- It is a detailed description of what algorithm would do.
- It is intended for human reading and cannot be executed directly by computer.
- There is no specific standard for writing a pseudo code exists.

**Keywords used in writing pseudo code**

- INPUT
- COMPUTE
- INCREMENT
- DECREMENT
- IF/ELSE
- WHILE
- TRUE/FALSE

**Pseudo Code Example**

**Example: write an algorithm to display the square of a given number.**

**Input, Process and Output Identification**

**Input: **Number whose square is required**Process:** Multiply the number by itself to get its square**Output: **Square of the number

**Algorithm**

Step 1: Input a number and store it to num.

Step 2: Compute num * num and store it in square.

Step 3: Print square.

**Pseudo code**

INPUT num

COMPUTE square = num*num

PRINT square

**Flow chart**

**Example: Write an algorithm to calculate area and perimeter of a rectangle, using both pseudo code and flowchart.**

**Pseudo code**

INPUT L

INPUT B

COMPUTER Area = L * B

PRINT Area

COMPUTE Perimeter = 2 * ( L + B )

PRINT Perimeter

**Flow Chart**

**Flow of Control**

An algorithm is considered as finite set of steps that are executed in a sequence. But sometimes the algorithm may require executing some steps conditionally or repeatedly. In such situations algorithm can be written using

- Sequence
- Selection
- Repetition

**Selection**

Selection in algorithm refers to Conditionals which means performing operations (sequence of steps) depending on True or False value of given conditions. Conditionals are written in the algorithm as follows:

If <condition> then

Steps to be taken when condition is true

Otherwise

Steps to be taken when condition is false

**Algorithm, Pseudocode, Flowchart with Selection ( Using if ) Examples**

**Example: write an algorithm, pseudocode and flowchart to display larger between two numbers**

**Input, Process and Output Identification**

INPUT: Two numbers to be compared

PROCESS: compare two numbers and depending upon True and False value of comparison display result

OUTPUT: display larger no

**Algorithm**

STEP1: read two numbers in num1, num2

STEP 2: if num1 > num2 then

STEP 3: display num1

STEP 4: else

STEP 5: display num2

**Pseudo code**

INPUT num1 , num2

IF num1 > num2 THEN

PRINT “num1 is largest”

ELSE

PRINT “num2 is largest”

ENDIF

**Flow Chart**

**Example: write pseudocode and flowchart to display largest among three numbers**

**Input, Process and Output Identification**

INPUT: Three numbers to be compared

PROCESS: compare three numbers and depending upon True and False value of comparison display result

OUTPUT: display largest number

**Pseudocode**

INPUT num1, num2, num3

PRINT “Enter three numbers”

IF num1 > num2 THEN

IF num1 > num3 THEN

PRINT “num1 is largest”

ELSE

PRINT “num3 is largest”

END IF

ELSE

IF num2 > num3 THEN

PRINT “num2 is largest”

ELSE

PRINT “num3 is largest”

END IF

END IF

**Flow chart**

**Repetition**

- Repetition in algorithm refers to performing operations (Set of steps) repeatedly for a given number of times (till the given condition is true).
- Repetition is also known as Iteration or Loop

Repetitions are written in algorithm is as follows:

While <condition>, repeat step numbers

Steps to be taken when condition is true

End while

**Algorithm, Pseudocode, Flowchart with Repetition ( Loop ) Examples**

**Example: write an algorithm, pseudocode and flow chart to display “Techtipnow” 10 times**

**Algorithm**

Step1: Set count = 0

Step2: while count is less than 10, repeat step 3,4

Step 3: print “techtipnow”

Step 4: count = count + 1

Step 5: End while

**Pseudocode**

SET count = 0

WHILE count<10

PRINT “Techtipnow”

Count = count + 1

END WHILE

**Flow chart**

**Example: Write pseudocode and flow chart to calculate total of 10 numbers**

**Pseudocode**

Step 1: SET count = 0, total = 0

Step 2: WHILE count < 10, REPEAT steps 3 to 5

Step 3: INPUT a number in var

Step 4: COMPUTE total = total + var

Step 5: count = count + 1

Step 6: END WHILE

Step 7: PRINT total

**Flow Chart**

**Example: Write pseudo code and flow chart to find factorial of a given number**

Step 1: SET fact = 1

Step 2: INPUT a number in num

Step 3: WHILE num >=1 REPEAT step 4, 5

Step 4: fact = fact * num

Step 5: num = num – 1

Step 6: END WHILE

Step 7: PRINT fact

**Flow chart**

**Decomposition**

- Decomposition means breaking down a complex problem into smaller sub problems to solve them conveniently and easily.
- Breaking down complex problem into sub problem also means analyzing each sub problem in detail.
- Decomposition also helps in reducing time and effort as different subprograms can be assigned to different experts in solving such problems.
- To get the complete solution, it is necessary to integrate the solution of all the sub problems once done.

Following image depicts the decomposition of a problem