Class 11 Ch 4 Introduction to Problem Solving Notes Important Points
Class 11 Ch 4 Introduction to Problem Solving Notes Important Points
Class XI & XII IP Syllabus 2024-25
Class XI & XII CS Syllabus 2024-25
Introduction
Today, computers are all around us. We use them for doing various tasks in a faster and more accurate manner. It is only due to the use of computers that today, the booking of the train tickets has become easy.
Computers are used for solving various day-to-day problems and thus problem solving is an essential skill that a computer science student should know.
We know that computers themselves cannot solve a problem. Thus, the success of a computer in solving a problem depends on how correctly and precisely we define the problem, design a solution (algorithm) and implement the solution (program) using a programming language.
Problem Solving can be defined as the process of identifying a problem, developing an algorithm for the identified problem and finally implementing the algorithm to develop a computer program.
Steps for Problem Solving
When problems are straightforward and easy, we can easily find the solution. But a complex problem requires a methodical approach to find the right solution. In other words, we have to apply problem solving techniques.
Key steps required for solving a problem using a computer are:
1. Analysing the problem
By analysing a problem, we would be able to figure out what are the inputs that our program should accept and the outputs that it should produce.
2. Developing an Algorithm
The solution of a problem represented in natural language is called an algorithm. An algorithm is like a very well-written recipe for a dish, with clearly defined steps that, if followed, one will end up preparing the dish.
For a given problem, more than one algorithm is possible and we have to select the most suitable solution.
3. Coding
In this step, we will convert the algorithm( designed in previous step) into the format which can be understood by the computer to generate the desired solution. Various high level programming languages can be used for
writing a program.
4. Testing and Debugging
The program created should be tested on various parameters. The program should meet the requirements
of the user. It should generate correct output for all possible inputs.
Software industry follows standardised testing methods like unit or component testing, integration testing, system testing, and acceptance testing while developing complex applications. This is to ensure that the software meets all the business and technical requirements and works as expected.
The errors or defects found in the testing phases are debugged or rectified and the program is again tested.
Algorithm
In our day-to-day life we perform activities by following certain sequence of steps. Examples of activities include getting ready for school, making breakfast and so on. For example
Example 1: Steps for ‘riding a bicycle’:
1) Remove the bicycle from the stand,
2) Sit on the seat of the bicycle,
3) Start peddling,
4) Use breaks whenever needed and
5) Stop on reaching the destination.
Example 2: Steps to Find Greatest Common Divisor (GCD) of two numbers 45 and 54.
1) Find the numbers (divisors) which can divide the given numbers
Divisors of 45 are: 1, 3, 5, 9, 15, and 45
Divisors of 54 are: 1, 2, 3, 6, 9, 18, 27, and 54
2) Then find the largest common number from these two lists.
Therefore, GCD of 45 and 54 is 9
NOTE: GCD is the largest number that divides both the given numbers.
Hence, it is clear that we need to follow a sequence of steps to accomplish the task. Such a finite sequence of steps required to get the desired output is called an algorithm.
Why do we need an Algorithm?
A programmer writes a program to instruct the computer to do certain tasks as desired. Therefore, the programmer first prepares a road map of the program to be written, before actually writing the code. Without a road map, the programmer may not be able to clearly visualise the instructions to be written. Such a roadmap is nothing but the algorithm which is the building block of a computer program.
When we have an algorithm to solve a problem, we can write the computer program for giving instructions to the computer in high level language. If the algorithm is correct, computer will run the program correctly, every time.
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.
Representation of Algorithms
The software designers or programmers first analyse the problem and identify the logical steps that need to be followed to reach a solution. Once the steps are identified, the need is to write down these steps along with the required input and desired output. There are two common methods of representing an algorithm
- Flowchart
- Pseudocode.
Flowchart: Visual Representation of Algorithms
A flowchart is a diagram made up of boxes, diamonds and other shapes, connected by arrows. Each shape represents a step of the solution process and the arrow represents the link among the steps.
Standard Symbols to draw flowcharts are given below:
Example 3: Write an algorithm to and also draw flowchart to find the square of a number.
Algorithm to find square of a number.
- Input a number and store it to num1 (a variable).
- Compute num1 * num1 and store it in square (a variable)
- Print square
The algorithm to find square of a number can be represented pictorially using flowchart as shown below
Example 4: Draw a flowchart to find the area of circle.
Example 5: Draw a flowchart to find the Perimeter of rectangle.
Pseudocode
The word “pseudo” means “not real,” so “pseudocode” means “not real code”. It is considered as a non-formal language that helps programmers to write algorithm.
No specific standard for writing a pseudocode exists. Following are some of the frequently used keywords while writing pseudocode:
- INPUT
- COMPUTE
- INCREMENT
- DECREMENT
- IF/ELSE
- WHILE
- TRUE/FALSE
Example 6: Write an algorithm to display the sum of two numbers entered by user, using both pseudocode and flowchart.
Pseudocode for the sum of two numbers will be:
input num1
input num2
COMPUTE Result = num1 + num2
PRINT Result
The flowchart for this algorithms is given below
Example 7: Write an algorithm to calculate area and perimeter of a rectangle, using both pseudocode and flowchart.
Pseudocode for calculating area and perimeter of a rectangle is given below:
input length
input breadth
compute Area = length * breadth
print Area
compute Perim = 2 * (length + breadth)
print Perim
The flowchart for this algorithm is given below:
Benefits of Pseudocode
- It is written in simple language so it is easy to understand.
- It can be written in any language.
Flow of Control
The flow of control depicts the flow of events as represented in the flow chart. The events can flow in the following ways:
1. Sequence
Those algorithms where all the steps are executed one after the other are said to execute in sequence. In all the above examples of Flowchart or Algorithm the statements are executed one after another, i.e., in a sequence.
2. Selection
Those algorithm in which execution of steps depend on certain condition are said to follow Selection type flow of control. For example
(i) Checking eligibility for voting.
If age is greater than or equal to 18, the person is eligible to vote.
OR
If age is less than 18, the person is not eligible to vote
(ii) Checking for Senior Citizen
If age is greater than or equal to 60, the person is senior citizen.
OR
If age is less than 18, the person is not senior citizen
(iii) Checking for Even number or Odd number
If number is divisible by 2 then the number is even
OR
If number is not divisible by 2 then the number is odd
In all the above examples, any one of the alternatives is selected based on the outcome of a condition. The program checks one or more conditions and perform operations (sequence of actions) depending on true or false value of the condition.
Conditionals are written in the algorithm as follows:
If <Condition> then
steps to be taken when the condition is true/fulfilled
There are situations where we also need to take action when the condition is not fulfilled. To represent that, we can write:
If <Condition> is true then
steps to be taken when the condition is true/fulfilled
otherwise
steps to be taken when the condition is false/not fulfilled
In programming languages, ‘otherwise’ is represented using Else keyword.
Example 8: Write an algorithm to check whether a number is odd or even. Also write pseudocode and draw flowchart.
Algorithm
Input: Any number
Process: Check whether the number is even or not
Output: Message “Even” or “Odd”
Pseudocode
PRINT "Enter the Number"
INPUT number
IF number MOD 2 == 0 THEN
PRINT "Number is Even"
ELSE
PRINT "Number is Odd"
Flowchart
Example 9: Write a pseudocode and draw a flowchart where multiple conditions are checked to categorise a person as either child, teenager or adult, based on age specified:
Age Criteria | Result to display |
<13 | Child |
>=13 but <20 | Teenager |
>20 | Adult |
Pseudocode
INPUT Age
if Age < 13 then
PRINT "Child"
else if Age < 20 then
PRINT "Teenager"
else
PRINT "Adult"
Flowchart
3. Repetition
In programming, repetition is also known as iteration or loop. A loop in an algorithm means execution of some program statements repeatedly till some specified condition is satisfied.
Example 10: Write pseudocode and draw a flowchart to accept 5 numbers and find their average.
Pseudocode
Step 1: Set count = 0, sum = 0
Step 2: While count < 5 , repeat steps 3 to 5
Step 3: Input a number to num
Step 4: sum = sum + num
Step 5: count = count + 1
Step 6: Compute average = sum/5
Step 7: Print average
Flowchart
In above example a counter called “count” keeps track of number of times the loop has been repeated.
After every iteration of the loop, the value of count is incremented by 1 until it performs the specified number of repetitions.
Some situations where we are not aware beforehand about the number of times a set of statements need to be repeated, such situations are handled using WHILE construct.
Example 11: Write pseudocode and draw flowchart to accept numbers till the user enters 0 and then find their average.
Pseudocode
Step 1: Set count = 0, sum = 0
Step 2: Input num
Step 3: While num is not equal to 0, repeat Steps 4 to 6
Step 4: sum = sum + num
Step 5: count = count + 1
Step 6: Input num
Step 7: Compute average = sum/count
Step 8: Print average
Flowchart
Verifying Algorithms
We know that the formula for the sum of first N natural numbers is N(N+1)/2 , but how can we verify it? Well, we can check this for small numbers, for which we can manually calculate the sum. Let N = 6, then the
sum is 1 + 2 + 3 + 4 + 5 + 6 = 21
Using formula we get sum = 6x(6+1)/2 = 21
We can also try with some more numbers to ensure that the formula works correctly.
Similarly a written algorithm can be verified by taking different input values and go through
all the steps of the algorithm to yield the desired output for each input value.
The method of taking an input and running through the steps of the algorithm is sometimes called
dry run. Such a dry run will help us to:
1. Figure out missing details or specifics in the algorithm
2. Identify any incorrect steps in the algorithm
NOTE: In case all possible input values are not tested, then the program will fail
Suppose we develop some software without verifying the underlying algorithm and if there are errors in the algorithm, then the software developed will not run. Hence, it is important to verify an algorithm.
Comparison of Algorithm
There can be more than one approach to solve a problem using computer and hence we can have more than one algorithm. Then one may ask which algorithm should be used?
Algorithms can be compared and analysed on the basis of the amount of processing time they need to run and the amount of memory that is needed to execute the algorithm. These are termed as time complexity and space complexity, respectively.
The choice of an algorithm over another is done depending on how efficient they are in terms of proecssing time required (time complexity) and the memory they utilise (space complexity).
Coding
Once an algorithm is finalised, it should be coded in a high-level programming language for example C, C++, Java, Python, etc. These languages are close to natural languages and are easier to read, write, and maintain, but are not directly understood by the computer hardware.
An advantage of using high-level languages is that they are portable, i.e., they can run on different types of computers with little or no modifications.
A program written in a high-level language is called source code. We need to translate the source code into machine language using a compiler or an interpreter, so that it can be understood by the computer.
Programs are developed not only to work on a computer, mobile or a web browser, but it may also be written for embedded systems like digital watch, mp3 players, traffic signals or vehicles, medical equipment and other smart devices. In such cases, we have to look for other specialized programming tools or sometimes write programs in assembly languages.
Decomposition
Sometimes a problem may be complex, in such cases, we need to decompose it into simpler parts. The basic idea of solving a complex problem by decomposition is to ‘decompose’ or break down a complex problem into smaller sub problems. These sub problems are relatively easier to solve than the original problem.
There are many real life problems which can be solved using decomposition. Examples include solving problems in mathematics and science, events management in school, weather forecasting, delivery management system, etc
SUMMARY:
1. An algorithm is defined as a step-by-step procedure designed to perform an operation which will lead to the desired result, if followed correctly.
2. Algorithms have a definite beginning and a definite end, and a finite number of steps.
3. A good algorithm, which is precise, unique and finite, receives input and produces an output.
4. In order to write effective algorithms we need to Notes identify the input, the process to be followed and the desired output.
5. A flowchart is a type of diagram that represents the algorithm graphically using boxes of various kinds, in an order connected by arrows.
6. An algorithm where all the steps are executed one after the other is said to execute in sequence.
7. Decision making involves selection of one of the alternatives based on outcome of a condition.
8. An algorithm may have a certain set of steps, which are repeating for a finite number of times, such an algorithm is said to be iterative.
9. There can be more than one approach to solve a problem and hence we can have more than one algorithm for a particular problem.
10. The choice of algorithm should be made on the basis of time and space complexity.
Class XI & XII IP Syllabus 2024-25
Class XI & XII CS Syllabus 2024-25
Chapter Wise MCQ
2. Flow of Control (Loop and Conditional statement)
3. 140+ MCQ on Introduction to Python
4. 120 MCQ on String in Python
7. 100+ MCQ on Flow of Control in Python
8. 60+ MCQ on Dictionary in Python
Important Links
100 Practice Questions on Python Fundamentals
120+ MySQL Practice Questions
90+ Practice Questions on List
50+ Output based Practice Questions
100 Practice Questions on String
70 Practice Questions on Loops
70 Practice Questions on if-else
Disclaimer : I tried to give you the simple notes of ” Class 11 Ch 4 Introduction to Problem Solving Notes Important Points” , but if you feel that there is/are mistakes in the handouts or explanation of “Class 11 Ch 4 Introduction to Problem Solving Notes Important Points“ given above, you can directly contact me at csiplearninghub@gmail.com. The above Notes of “Class 11 Ch 4 Introduction to Problem Solving Notes Important Points ” are created by referring NCERT Book of Class 11. Screenshots used in this article are taken from NCERT book.
Class 11 Ch 4 Introduction to Problem Solving Notes
Class 11 Ch 4 Introduction to Problem Solving Notes
Class 11 Ch 4 Introduction to Problem Solving Notes
Class 11 Ch 4 Introduction to Problem Solving Notes
Class 11 Ch 4 Introduction to Problem Solving Notes
Class 11 Ch 4 Introduction to Problem Solving Notes
Class 11 Ch 4 Introduction to Problem Solving Notes
Class 11 Ch 4 Introduction to Problem Solving Notes
Class 11 Ch 4 Introduction to Problem Solving Notes