Introduction to Problem Solving — NCERT Class 11 Computer Science Exercise Solutions
How to Use This Page
This page provides complete solutions for all exercise questions from NCERT Class 11 Computer Science Chapter 4 — Introduction to Problem Solving. Each answer follows the CBSE marking scheme format.
Tips for best results:
- Attempt each question on your own before reading the solution
- Compare your algorithm or flowchart with the one given here
- Pay close attention to how algorithms are structured — step numbering, START/STOP, indentation
- Practise drawing flowcharts on paper; the exam requires hand-drawn diagrams
Key Concepts — Quick Review
Before the solutions, here is a brief recap of the core concepts:
| Concept | One-Line Summary |
|---|---|
| Problem Solving Steps | Understand, Analyse, Design, Code, Test, Maintain |
| Algorithm | Step-by-step procedure with finiteness, definiteness, input, output, effectiveness |
| Flowchart | Visual representation using oval (terminal), rectangle (process), parallelogram (I/O), diamond (decision) |
| Pseudocode | Structured English-like description of an algorithm |
| Syntax Error | Violation of language grammar rules; caught before execution |
| Logical Error | Program runs but gives wrong output due to flawed logic |
| Runtime Error | Program crashes during execution (e.g., division by zero) |
Exercise Questions and Answers
Q1: Write an algorithm to find the sum of two numbers.
Q2: Write an algorithm and draw a flowchart to find the maximum of three numbers.
Algorithm:
Flowchart:
Q3: Write pseudocode to calculate the factorial of a number.
Example trace for N = 4:
| Iteration | I (before) | FACT (before) | FACT (after) | I (after) |
|---|---|---|---|---|
| 1 | 1 | 1 | 1 | 2 |
| 2 | 2 | 1 | 2 | 3 |
| 3 | 3 | 2 | 6 | 4 |
| 4 | 4 | 6 | 24 | 5 |
When I becomes 5, the condition I <= N (5 <= 4) is false, so the loop stops. FACT = 24, which is 4!.
Q4: List and explain the properties of a good algorithm.
A good algorithm must possess the following five properties:
1. Finiteness: The algorithm must terminate after a finite and known number of steps. An algorithm that runs forever (infinite loop) is not valid. For example, an algorithm that keeps adding 1 to a counter without a stopping condition is not finite.
2. Definiteness: Every step of the algorithm must be precisely and unambiguously defined. There should be no room for multiple interpretations. For example, a step that says "add some number" is ambiguous, while "add A and B" is definite.
3. Input: An algorithm may have zero or more inputs. The inputs are the data values the algorithm works with. Some algorithms (like one that prints a fixed message) may have zero inputs, but most algorithms require at least one input.
4. Output: An algorithm must produce at least one output. The output is the result of the computation. An algorithm that produces no output serves no purpose and is not considered valid.
5. Effectiveness: Every step of the algorithm must be basic enough that it can be performed exactly in a finite amount of time using basic operations. For example, a step that says "find the largest number in an infinite list" is not effective because it cannot be completed.
Q5: Differentiate between syntax errors and logical errors.
| Aspect | Syntax Error | Logical Error |
|---|---|---|
| Definition | Violation of the grammatical rules of a programming language | Flaw in the algorithm or logic that produces incorrect results |
| When detected | During compilation or before execution | During execution or when checking output |
| Effect on program | Program does not run at all | Program runs but gives wrong output |
| Cause | Misspelled keywords, missing colons, unmatched brackets, wrong indentation | Wrong formula, incorrect condition, using wrong variable |
| Example | Writing pritn instead of print, forgetting a closing parenthesis | Calculating area as length + width instead of length * width |
| Ease of detection | Easy — compiler shows the exact line and error type | Difficult — the program runs without complaint; only the output is wrong |
| Fix | Correct the syntax according to language rules | Trace the logic, identify the flaw, and correct the algorithm |
Example of syntax error (Python):
# Wrong — missing colon after if
if x > 5
print("Greater")
Example of logical error (Python):
# Runs without error but gives wrong result
# Should be multiplication, not addition
area = length + width
Q6: Explain the standard flowchart symbols and their uses.
Flowcharts use standard geometric symbols defined by ANSI (American National Standards Institute) to represent different types of operations:
| Symbol Name | Shape | Purpose | Example |
|---|---|---|---|
| Terminal | Oval or rounded rectangle | Marks the beginning (START) or end (STOP) of the program | START, STOP |
| Process | Rectangle | Represents a processing step or calculation | SUM = A + B, COUNT = COUNT + 1 |
| Input/Output | Parallelogram | Represents reading input from the user or displaying output | Read N, Display RESULT |
| Decision | Diamond (rhombus) | Represents a conditional check with two possible paths (Yes/No) | Is N > 0?, Is A == B? |
| Flow Line | Arrow | Shows the direction of flow from one step to the next | Connects all symbols in sequence |
| Connector | Small circle | Connects parts of a flowchart on the same page or across pages | Used in large flowcharts to avoid crossing lines |
| Predefined Process | Rectangle with double side edges | Represents a call to a sub-program or predefined function | CALL Sort_Array, CALL Calculate_Average |
Important rules:
- The decision symbol always has one entry and two exits (Yes and No)
- The flow direction is typically top-to-bottom or left-to-right
- Every flowchart must begin with START and end with STOP
- Flow lines should not cross; use connectors if needed
Q7: Write pseudocode and draw a flowchart to check whether a given number is even or odd.
Pseudocode:
Flowchart:
Q8: Write an algorithm to find the sum of the first N natural numbers.
Verification: For N = 5, the loop runs 5 times. SUM = 1 + 2 + 3 + 4 + 5 = 15. The mathematical formula N(N+1)/2 gives 5(6)/2 = 15. The result matches.
Q9: What are the different steps involved in problem solving? Explain briefly.
Problem solving in computer science follows a systematic approach with six well-defined steps:
1. Understanding the Problem: This is the most critical step. Read the problem statement carefully and identify what is given (inputs), what is required (outputs), and any constraints or special conditions. A misunderstood problem leads to a wrong solution.
2. Analysing the Problem: Break the problem down into smaller components. Identify the relationships between inputs and outputs. Consider multiple approaches and choose the most efficient one. Think about edge cases and boundary conditions.
3. Designing the Solution: Develop the algorithm — a step-by-step procedure to solve the problem. You can represent the solution as an algorithm, flowchart, or pseudocode. This step focuses on "what to do" and "in what order."
4. Coding the Solution: Translate the algorithm or pseudocode into a programming language (Python for CBSE). Follow the syntax rules of the language. Write clean, well-commented code.
5. Testing and Debugging: Run the program with various inputs and compare the output with expected results. If errors are found, debug and fix them. Test with normal inputs, boundary values, and invalid inputs.
6. Maintenance: After the program is deployed, it may need updates for new requirements, performance improvements, or bug fixes discovered in real-world use.
Q10: Write pseudocode to find the largest element in a list of numbers.
Example trace for LIST = [12, 45, 7, 89, 23]:
| I | LIST[I] | MAX (before) | LIST[I] > MAX? | MAX (after) |
|---|---|---|---|---|
| 2 | 45 | 12 | Yes | 45 |
| 3 | 7 | 45 | No | 45 |
| 4 | 89 | 45 | Yes | 89 |
| 5 | 23 | 89 | No | 89 |
Q11: What is the difference between a runtime error and a logical error? Give examples.
| Aspect | Runtime Error | Logical Error |
|---|---|---|
| When it occurs | During program execution | During program execution or only visible in output |
| What happens | The program crashes or stops unexpectedly | The program runs completely but produces wrong results |
| Cause | Attempting an operation that cannot be performed at that moment | Incorrect logic, wrong formula, or flawed algorithm |
| Detection | The program stops with an error message | No error message; the programmer must verify output manually |
| Examples | Division by zero, accessing an array element beyond its bounds, running out of memory | Calculating average as (a + b + c) / 2 instead of /3, using < instead of <= in a loop condition |
Example of runtime error:
a = 10
b = 0
result = a / b # ZeroDivisionError — program crashes
Example of logical error:
a = 10
b = 20
c = 30
average = (a + b + c) / 2 # Wrong: should be /3
# Program runs but gives 30.0 instead of correct 20.0
Q12: Write an algorithm to find whether a given number is positive, negative, or zero.
Pseudocode version:
Related Resources
- [CBSE Class 11 Introduction to Problem Solving — Chapter Guide](/class/11/computer-science/cbse-introduction-problem-solving) — Complete chapter notes with detailed concepts, comparison tables, and exam tips
- [CBSE Class 11 Emerging Trends — Exercise Solutions](/class/11/computer-science/solutions/cbse-emerging-trends-exercise-solutions) — Chapter 3 solutions
- [CBSE Class 11 Computer Science — Computer System](/class/11/computer-science/cbse-computer-system) — Chapter 1 notes
- [CBSE Class 11 Computer Science — Getting Started with Python](/class/11/computer-science/cbse-getting-started-python) — Chapter 5 notes
