Introduction to Problem Solving - Class 11 Computer Science - Chapter 4 - Notes, NCERT Solutions & Extra Questions
Renews every month. Cancel anytime
Your personal doubt-solving assistant
Chatterbot AI gives you 100% accurate answers to your questions in an instant.
Notes - Introduction to Problem Solving | Class 11 NCERT | Computer Science
Comprehensive Introduction to Problem Solving: Class 11 Notes
Understanding Problem Solving in Computer Science
Problem solving is a crucial skill for computer science students. It involves identifying a problem, designing a solution, and implementing that solution effectively. In today’s digital age, computers are everywhere, assisting us in performing various tasks efficiently. Learning problem solving equips students with the capability to instruct computers to perform tasks accurately and quickly.
Key Steps in the Problem Solving Process
Identifying and Analysing the Problem
The first step is to clearly understand the problem. Misinterpreting the problem can lead to ineffective solutions. Therefore, analysing the problem to comprehend its principal components and core functionalities is vital.
Developing an Algorithm
An algorithm is a step-by-step procedure to solve a problem. It’s like a recipe that guides you through the steps to achieve a desired result. Once an algorithm is formulated, it needs to be refined to ensure it covers all aspects of the solution.
Implementing the Algorithm with Code
After developing an algorithm, it’s translated into a programming language that computers can understand. This step is known as coding.
Testing and Debugging the Solution
Testing ensures that the program meets user requirements and responds appropriately. Debugging involves identifying and fixing any errors in the program.
Algorithms: The Heart of Problem Solving
Definition and Characteristics of a Good Algorithm
An algorithm is defined by several characteristics:
Precision: Steps are clearly stated.
Uniqueness: Each step has a unique outcome.
Finiteness: The algorithm terminates after a finite number of steps.
Input: The algorithm receives some input.
Output: It produces some output.
Steps to Develop an Algorithm
Analysing the Problem: Understand the inputs and expected outputs.
Designing the Algorithm: Create a step-by-step solution.
Refining the Algorithm: Ensure it covers all scenarios.
Implementing the Algorithm: Write it in a programming language.
Here is a simple example of an algorithm for finding the Greatest Common Divisor (GCD) of two numbers:
1. Find the numbers (divisors) which can divide the given numbers.
2. Identify the largest common number from these two lists.
3. The largest common number is the GCD.
Representation of Algorithms
Flowcharts: A Visual Representation
A flowchart visually represents an algorithm using standardised symbols like boxes and arrows. Here’s a flowchart illustrating the steps to find the square of a number:
graph TD;
A[Start] --> B[Input Number];
B --> C[Compute square of the number];
C --> D[Print square];
D --> E[End];
Pseudocode: A Textual Representation
Pseudocode is a non-formal way of describing an algorithm in a language understandable to humans. It outlines the logical steps to follow. Here’s a pseudocode for calculating the area and perimeter of a rectangle:
INPUT length
INPUT breadth
COMPUTE Area = length * breadth
PRINT Area
COMPUTE Perimeter = 2 * (length + breadth)
PRINT Perimeter
Flow of Control in Problem Solving
Sequence
Statements are executed one after another in order.
Selection
Algorithms involve decision-making by selecting alternatives based on conditions. Example:
IF age >= 18 THEN
PRINT "Eligible to vote"
ELSE
PRINT "Not eligible to vote"
Iteration (Repetition)
Certain steps are repeated based on conditions until a particular state is achieved. Example:
SET sum = 0
FOR i = 1 TO 10
sum = sum + i
END FOR
PRINT sum
Coding: Translating Algorithms into Programs
Coding translates the algorithm into a programming language. The code must adhere to the syntax rules of the chosen language. High-level programming languages such as Python, Java, and C++ are commonly used due to their readability and portability.
Testing and Debugging
Testing involves running the algorithm with various inputs to ensure it produces the correct output. Debugging is the process of identifying and correcting errors within the code.
Verifying the Correctness of Algorithms
Verifying the correctness of algorithms is crucial. It involves testing the algorithm with different inputs to ensure it consistently produces the correct output.
Comparison and Optimisation of Algorithms
Algorithms can be optimised for efficiency. This involves comparing algorithms based on:
Time Complexity: The amount of time needed.
Space Complexity: The amount of memory used.
Problem Decomposition
Decomposing a complex problem into smaller sub-problems makes it easier to solve. For example, a railway reservation system can be broken down into modules such as booking, scheduling, and ticketing.
Example of Decomposition:
graph TD;
A[Railway Reservation System] --> B[Booking Module];
A --> C[Scheduling Module];
A --> D[Ticketing Module];
Breaking down tasks allows for detailed examination and individual solutions, which can be integrated to form a complete solution.
Summary
Problem solving involves identifying a problem, developing an algorithm, coding, testing, and debugging.
Algorithms are central to problem solving and must be precise, unique, and finite.
Flowcharts and pseudocode are useful tools for representing algorithms.
The flow of control, coding, testing, and debugging are essential steps in problem solving.
Algorithm optimisation focuses on improving time and space efficiency.
Decomposition helps manage complex problems by breaking them into simpler sub-problems.
By mastering these concepts, Class 11 computer science students can develop effective problem-solving skills, essential for their academic and professional growth.
🚀 Learn more about Notes with Chatterbot AI
Extra Questions - Introduction to Problem Solving | NCERT | Computer Science | Class 11
Shakuntala says, "If you reverse my age, it displays my husband's age in reverse. Indeed, he is older than me in age, and the difference in our ages is 1/11th of the product of our ages." Find out Shakuntala's age.
Option 1) 23 years
Option 2) 34 years
Option 3) 45 years
Option 4) None of these
The correct option is C:
45 years
Explanation:
Let's denote the digits of Shakuntala's age by $x$ (tens place) and $y$ (units place). Thus, Shakuntala's age can be expressed as $10x + y$ years. Conversely, her husband's age can be written as $10y + x$ years.
Given that the difference in their ages is $\frac{1}{11}$ of the product of their ages, we start by formulating and simplifying the given problem:
[ \begin{align*} \text{Age Difference} &= |(10y + x) - (10x + y)| = (10y + x + 10x + y) / 11 \ |9y - 9x| &= 11(x + y) \ 9y - 9x &= 11(y + x) \ 9y - 9x &= x + y \ 10x &= 8y \ \end{align*} ]
From the equation $10x = 8y$, we derive $x = \frac{4y}{5}$, implying that $x$ must be a whole number. Therefore, $y$ should be a number that, when multiplied by 4, gives a product divisible by 5.
Given $y$ as a single digit, the value that satisfies this condition is $y = 5$. Consequently, $x = 4$.
Therefore, Shakuntala's age is:
[ \text{Shakuntala's age} = 10x + y = 10(4) + 5 = 45 \text{ years} ]
Thus, the correct answer is Option C: 45 years.
💡 Have more questions?
Ask Chatterbot AINCERT Solutions - Introduction to Problem Solving | NCERT | Computer Science | Class 11
Write pseudocode that reads two numbers and divide one by another and display the quotient.
Here is the pseudocode to read two numbers, divide one by another, and display the quotient:
BEGIN
PRINT "Enter the first number:"
INPUT num1
PRINT "Enter the second number:"
INPUT num2
IF num2 != 0 THEN
quotient = num1 / num2
PRINT "The quotient is ", quotient
ELSE
PRINT "Division by zero is not allowed."
END
Two friends decide who gets the last slice of a cake by flipping a coin five times. The first person to win three flips wins the cake. An input of 1 means player 1 wins a flip, and a 2 means player 2 wins a flip. Design an algorithm to determine who takes the cake.
Here is a pseudocode to determine who takes the cake:
INITIALIZE player1_wins to 0
INITIALIZE player2_wins to 0
REPEAT 5 TIMES
PRINT "Enter the result of the flip (1 for player 1, 2 for player 2):"
INPUT flip_result
IF flip_result == 1 THEN
INCREMENT player1_wins
IF player1_wins == 3 THEN
PRINT "Player 1 wins the cake!"
EXIT LOOP
ELSE IF flip_result == 2 THEN
INCREMENT player2_wins
IF player2_wins == 3 THEN
PRINT "Player 2 wins the cake!"
EXIT LOOP
IF player1_wins == 3 THEN
PRINT "Player 1 wins the cake!"
ELSE IF player2_wins == 3 THEN
PRINT "Player 2 wins the cake!"
ELSE
PRINT "No player has won after 5 flips!"
Explanation:
This pseudocode follows these steps:
Initialize counters for both players to keep track of their wins.
Loop for a maximum of 5 flips.
Within each loop iteration:
Take input for the result of the coin flip.
Update counters based on the result.
Check if any player has won three times to announce the winner and early exit from the loop.
Post loop check:Re-validate and announce the winner if any.Print a message if no player reaches 3 wins after 5 flips.
Write the pseudocode to print all multiples of 5 between 10 and 25 (including both 10 and 25).
Here’s the pseudocode to print all multiples of 5 between 10 and 25, inclusive:
PRINT "Multiples of 5 between 10 and 25:"
FOR number FROM 10 TO 25 STEP 1
IF (number MOD 5 == 0) THEN
PRINT number
END IF
NEXT number
This pseudocode uses a loop that iterates through each number from 10 to 25 and checks if it is a multiple of 5 by using the modulus operator. If the condition is true, the number is printed.
Give an example of a loop that is to be executed a certain number of times.
Let's take the example of a loop that prints the numbers from 1 to 10. This loop will be executed exactly 10 times, once for each number from 1 to 10.
Pseudocode
SET count = 1
WHILE count <= 10
PRINT count
INCREMENT count by 1
Explanation
Initialization: Set the initial value of the
count
variable to 1.Condition: Continue the loop while the
count
is less than or equal to 10.Body: Print the current value of
count
and then incrementcount
by 1.Increment: Increase the value of
count
by 1 after each iteration.
Output
The numbers 1 to 10 will be printed on the screen. This loop executes exactly 10 times.
Suppose you are collecting money for something. You need ₹200 in all. You ask your parents, uncles and aunts as well as grandparents. Different people may give either ₹10 , ₹20 or even ₹50 . You will collect till the total becomes 200. Write the algorithm.
Here is the algorithm to collect money until the total reaches ₹200:
Algorithm to Collect ₹200
Initialize total to 0.
total = 0
While total is less than 200, repeat steps 3 to 5:
WHILE total < 200 REPEAT
Ask for money contribution:
INPUT contribution
Check if contribution is ₹10, ₹20, or ₹50:
IF contribution == 10 OR contribution == 20 OR contribution == 50 THEN
Add the contribution to total:
total = total + contribution
End the loop.
END WHILE
Print the total amount collected:
PRINT total
Pseudocode:
total = 0
WHILE total < 200 REPEAT
INPUT contribution
IF contribution == 10 OR contribution == 20 OR contribution == 50 THEN
total = total + contribution
END IF
END WHILE
PRINT total
Explanation:
Initialize: Start by setting the
total
amount collected to 0.Loop: Keep asking for contributions in a loop until the
total
collected is at least ₹200.Input: Get the contribution amount from a family member.
Condition: Verify if the contribution is one of the valid amounts ₹10, ₹20, or ₹50.
Update: Add the contribution to the
total
collected.End: Exit the loop once the total reaches or exceeds ₹200 and print the total amount collected.
Write the pseudocode to print the bill depending upon the price and quantity of an item. Also print Bill GST, which is the bill after adding $5 \%$ of tax in the total bill.
Here is the pseudocode to print the bill and the bill including GST:
INPUT price
INPUT quantity
COMPUTE total_bill = price * quantity
PRINT total_bill
COMPUTE bill_GST = total_bill + (0.05 * total_bill)
PRINT bill_GST
Explanation:
Input: Obtain the
price
andquantity
of the item.Compute Total Bill: Calculate
total_bill
by multiplyingprice
byquantity
.Print Total Bill: Display the
total_bill
.Compute Bill GST: Calculate
bill_GST
by adding 5% tax tototal_bill
.Print Bill GST: Display the
bill_GST
.
Write pseudocode that will perform the following:
a) Read the marks of three subjects: Computer Science, Mathematics and Physics, out of 100
b) Calculate the aggregate marks
c) Calculate the percentage of marks
Here is a pseudocode that performs the tasks:
START
PRINT "Enter marks for Computer Science out of 100"
INPUT CS_marks
PRINT "Enter marks for Mathematics out of 100"
INPUT Maths_marks
PRINT "Enter marks for Physics out of 100"
INPUT Physics_marks
// Calculate aggregate marks
SET aggregate_marks = CS_marks + Maths_marks + Physics_marks
// Calculate percentage of marks
SET percentage = (aggregate_marks / 300) * 100
PRINT "Aggregate Marks: ", aggregate_marks
PRINT "Percentage: ", percentage
END
Here are the key steps highlighted:
Input marks for three subjects.
Calculate aggregate marks by summing up the marks.
Calculate percentage by dividing the aggregate marks by the total possible marks (300) and multiplying by 100.
Print the results for both aggregate marks and the percentage.
Write an algorithm to find the greatest among two different numbers entered by the user.
Here's the algorithm to find the greatest among two different numbers entered by the user:
Algorithm
INPUT
num1
INPUT
num2
IF
num1 > num2
THENPRINT "num1 is greater"
ELSE
PRINT "num2 is greater"
Pseudocode
INPUT num1
INPUT num2
IF num1 > num2 THEN
PRINT "num1 is greater"
ELSE
PRINT "num2 is greater"
Explanation
Step 1 & 2: Take two input numbers from the user.
Step 3: Compare the first number (
num1
) with the second number (num2
).Step 4: Print the result based on the comparison. If
num1
is greater, print "num1 is greater"; otherwise, print "num2 is greater".
Write an algorithm that performs the following: Ask a user to enter a number. If the number is between 5 and 15, write the word GREEN. If the number is between 15 and 25, write the word BLUE. if the number is between 25 and 35 , write the word ORANGE. If it is any other number, write that ALL COLOURS ARE BEAUTIFUL.
Here is the algorithm to achieve the mentioned task:
Input: A number from the user
Process: Check which range the number falls into and determine the appropriate output
Output: Depending on the range, output the corresponding word or phrase
Pseudocode
PRINT "Enter a number"
INPUT number
IF 5 <= number < 15 THEN
PRINT "GREEN"
ELSE IF 15 <= number < 25 THEN
PRINT "BLUE"
ELSE IF 25 <= number < 35 THEN
PRINT "ORANGE"
ELSE
PRINT "ALL COLOURS ARE BEAUTIFUL"
Explanation
Ask the user to enter a number: Start by prompting the user to enter a number.
Check the range of the number:
If the number is between 5 and 15 (inclusive of 5 and less than 15), print "GREEN".
If the number is between 15 and 25 (inclusive of 15 and less than 25), print "BLUE".
If the number is between 25 and 35 (inclusive of 25 and less than 35), print "ORANGE".
If the number does not fall into any of these ranges, print "ALL COLOURS ARE BEAUTIFUL".
Each step ensures that the correct message is printed based on the range in which the entered number falls.
Write an algorithm that accepts four numbers as input and find the largest and smallest of them.
Here is the algorithm to find the largest and smallest of four numbers:
Pseudocode:
INPUT num1, num2, num3, num4
SET largest = num1
SET smallest = num1
IF num2 > largest THEN
SET largest = num2
IF num3 > largest THEN
SET largest = num3
IF num4 > largest THEN
SET largest = num4
IF num2 < smallest THEN
SET smallest = num2
IF num3 < smallest THEN
SET smallest = num3
IF num4 < smallest THEN
SET smallest = num4
PRINT "Largest number is ", largest
PRINT "Smallest number is ", smallest
Explanation:
Input: Read four numbers (num1, num2, num3, num4).
Initialize:
Set 'largest' variable to the first number (num1).
Set 'smallest' variable to the first number (num1).
Finding the Largest:
Compare num2 with 'largest' and update 'largest' if num2 is greater.
Compare num3 with 'largest' and update 'largest' if num3 is greater.
Compare num4 with 'largest' and update 'largest' if num4 is greater.
Finding the Smallest:
Compare num2 with 'smallest' and update 'smallest' if num2 is smaller.
Compare num3 with 'smallest' and update 'smallest' if num3 is smaller.
Compare num4 with 'smallest' and update 'smallest' if num4 is smaller.
Output: Print the 'largest' and 'smallest' values.
Write an algorithm to display the total water bill charges of the month depending upon the number of units consumed by the customer as per the following criteria:
for the first 100 units @ 5 per unit
for next 150 units @ 10 per unit
more than 250 units @ 20 per unit
Also add meter charges of 75 per month to calculate the total water bill .
Algorithm to Calculate Total Water Bill Charges
INPUT: Number of units consumed
PROCESS:
If units <= 100:
Total charges = units * 5
Else if 100 < units <= 250:
Total charges = (100 * 5) + ((units - 100) * 10)
Else:
Total charges = (100 * 5) + (150 * 10) + ((units - 250) * 20)
Add meter charges of 75
OUTPUT: Total water bill charges
Pseudocode
INPUT units
SET totalCharges = 0
IF units <= 100 THEN
totalCharges = units * 5
ELSE IF units <= 250 THEN
totalCharges = (100 * 5) + ((units - 100) * 10)
ELSE
totalCharges = (100 * 5) + (150 * 10) + ((units - 250) * 20)
END IF
totalCharges = totalCharges + 75
PRINT totalCharges
Explanation
Input: Accept the number of units consumed by the customer.
Process:
For the first 100 units: The charge is 5 per unit, so multiply units by 5.
For next 150 units: If units are more than 100 but less than or equal to 250, calculate the charge for the first 100 units and add the charge for the remaining units at 10 per unit.
For units beyond 250: Calculate the charge for the first 100 units, the next 150 units, and add the charge for the remaining units at 20 per unit.
Add meter charges: A fixed meter charge of 75 per month is added to the total charges.
Output: Print the total water bill charges.
What are conditionals? When they are required in a program?
Conditionals are statements in a program that help make decisions based on certain conditions. They can be used to control the flow of execution by evaluating expressions and executing different blocks of code depending on whether the specified condition is true
or false
.
When are conditionals required in a program?
Conditionals are required:
When making decisions in code:
They allow the program to execute certain actions only if a specific condition is met.
Example: Determining if a user is eligible to vote based on their age.
To handle different scenarios and outcomes:
They help in handling multiple possible scenarios by specifying different actions for different conditions.
Example: Checking if a number is even or odd and performing different actions accordingly.
For branching and looping logic:
Conditionals are used in loops to keep iterating until a certain condition is satisfied.
Example: Running a loop to collect user inputs until a valid input is provided.
By using conditionals, programmers can write code that is flexible and can respond to various inputs and situations dynamically.
Example of conditionals in pseudocode:
IF age >= 18 THEN
PRINT "Eligible to vote"
ELSE
PRINT "Not eligible to vote"
In the code above, the execution depends on the condition age >= 18
. If it is true
, the program prints "Eligible to vote"; otherwise, it prints "Not eligible to vote".
Match the pairs
Flowchart Symbol | Functions |
---|---|
Flow of Control | |
Process Step | |
Start/Stop of the Process | |
Data | |
Decision Making |
Here are the matched pairs:
Flowchart Symbol | Function |
---|---|
![]() | Start/Stop of the Process |
![]() | Process Step |
![]() | Data |
![]() | Decision Making |
![]() | Flow of Control |
Following is an algorithm for going to school or college. Can you suggest improvements in this to include other options?
Reach_School_Algorithm
a) Wake up
b) Get ready
c) Take lunch box
d) Take bus
e) Get off the bus
f) Reach school or college
The algorithm for reaching school or college can be improved to include other regular options that a student might take, such as checking the schedule, catching a different mode of transport (e.g., cycling, walking, or carpooling), and handling missed buses/trains. Here's a more comprehensive version of the algorithm:
Reach_School_Algorithm
Wake up
Get ready
Take lunch box
Check Schedule
If early, then relax or revise
Else, proceed to next step
Choose Mode of Transport
If bus:
Walk to bus stop
Wait for bus
Board bus
Else if cycling:
Take bicycle
Start cycling
Else if walking:
Start walking
Else if carpool:
Wait for carpool
Board carpool
During Transport
If bus:
Ensure not to miss the stop
Get off the bus
If cycling:
Lock bicycle at bike stand
If walking:
Ensure shortest possible path
If carpool:
Ensure not to miss destination
Reach school or college
This enriched algorithm *covers multiple scenarios* and provides *more flexibility in terms of transport* and *time management.*
Write a pseudocode to calculate the factorial of a number (Hint: Factorial of 5, written as $5!=5 \times 4 \times 3 \times 2 \times 1$ ) .
Here is the pseudocode to calculate the factorial of a number:
Pseudocode to Calculate Factorial:
INPUT number
SET factorial = 1
FOR counter FROM 1 TO number DO
SET factorial = factorial * counter
END FOR
PRINT factorial
Explanation:
INPUT number: Read the number for which you need to find the factorial.
SET factorial = 1: Initialize a variable
factorial
to 1 which will hold the result.FOR counter FROM 1 TO number DO: Loop from 1 to the
number
.SET factorial = factorial * counter: Multiply
factorial
with the loop variablecounter
at each step.END FOR: End the loop when
counter
reaches thenumber
.PRINT factorial: Output the calculated factorial.
Draw a flowchart to check whether a given number is an Armstrong number. An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3+ 7**3+1 **3=371.
Here is the flowchart:
Following is an algorithm to classify numbers as "Single Digit", "Double Digit" or "Big".
Classify_Numbers_Algo
INPUT Number
IF Number < 9
"Single Digit"
Else If Number < 99
"Double Digit"
Else
"Big"
Verify for $(5,9,47,99,100200)$ and correct the algorithm if required
Based on the given algorithm, let's verify and correct the classification for the numbers (5), (9), (47), (99), and (100200).
Verification:
Number = 5
Condition:
5 < 9
is true.Output: "Single Digit"
Number = 9
Condition:
9 < 9
is false.Next Condition:
9 < 99
is true.Output: "Double Digit" (Expected: "Single Digit")
Number = 47
Condition:
47 < 9
is false.Next Condition:
47 < 99
is true.Output: "Double Digit"
Number = 99
Condition:
99 < 9
is false.Next Condition:
99 < 99
is false.Else Condition: True.
Output: "Big" (Expected: "Double Digit")
Number = 100200
Condition:
100200 < 9
is false.Next Condition:
100200 < 99
is false.Else Condition: True.
Output: "Big"
Corrections:
To correctly classify the numbers, we need to adjust the conditions:
"Single Digit" should be for numbers less than 10, not 9.
"Double Digit" should be for numbers less than 100, not 99.
Here’s the corrected algorithm:
Classify_Numbers_Algo
INPUT Number
IF Number < 10 THEN
PRINT "Single Digit"
ELSE IF Number < 100 THEN
PRINT "Double Digit"
ELSE
PRINT "Big"
Summary:
(5): Correctly classified as "Single Digit".
(9): Expected "Single Digit", and corrected algorithm classifies it correctly.
(47): Correctly classified as "Double Digit".
(99): Expected "Double Digit", and corrected algorithm classifies it correctly.
(100200): Already correctly classified as "Big".
Thus, the corrected algorithm now accurately classifies all given test cases.
For some calculations, we want an algorithm that accepts only positive integers upto 100 .
Accept_1to100_Algo
INPUT Number
IF (0<= Number) AND (Number <= 100)
ACCEPT
Else
REJECT
a) On what values will this algorithm fail?
b) Can you improve the algorithm?
a) On what values will this algorithm fail?
The algorithm will accept 0
as a valid input even though it requires only positive integers. 0
is not a positive integer, so the algorithm fails for 0
.
b) Can you improve the algorithm?
Yes, the algorithm can be improved by changing the condition to ensure that only positive integers greater than 0
and up to 100
are accepted:
Accept_1to100_Algo
INPUT Number
IF (0 < Number) AND (Number <= 100)
ACCEPT
Else
REJECT
Explanation:
Condition Change: The condition has been changed from
(0 <= Number)
to(0 < Number)
.Reason: This ensures that
0
is no longer accepted and only positive integers (1
to100
) meet the criteria to be accepted.
💡 Have more questions?
Ask Chatterbot AI