CBSETest.comby Bimal Publications

Need help with Introduction to Problem Solving?

Practice Tests
Class 11 · Computer Science NCERT Class 11 Computer Science · Ch. 45 min read · 15 questions

Introduction to Problem Solving

Computer Science

Introduction to Problem Solving

Before writing a single line of code, a good programmer must understand the problem thoroughly and plan a clear solution. This chapter introduces systematic approaches to problem solving: algorithms, flowcharts, and pseudocode.

Steps in Problem Solving

  1. 1.Understand the problem: Read carefully; identify inputs, expected outputs, and constraints.
  2. 2.Analyse the problem: Break it into smaller sub-problems. Identify patterns and relationships.
  3. 3.Design an algorithm: Write a step-by-step procedure to solve the problem.
  4. 4.Code the solution: Translate the algorithm into a programming language.
  5. 5.Test and debug: Run the program with various inputs; find and fix errors.
  6. 6.Document: Write clear comments and user documentation.

What is an Algorithm?

An algorithm is a finite, ordered sequence of well-defined, unambiguous steps that solves a problem and always terminates.

  • Properties of a good algorithm:
  • Input: Zero or more inputs.
  • Output: At least one output.
  • Definiteness: Each step is clear and unambiguous.
  • Finiteness: Must terminate after a finite number of steps.
  • Effectiveness: Each step must be basic enough to be carried out.

Flowcharts

A flowchart is a graphical representation of an algorithm using standard symbols:

| Symbol | Shape | Use |
|--------|-------|-----|
| Start/End | Oval (Terminator) | Begin or end of algorithm |
| Process | Rectangle | Computation / assignment |
| Decision | Diamond | Yes/No question or condition |
| Input/Output | Parallelogram | Read input or display output |
| Arrow | Line with arrowhead | Flow of control |

Pseudocode

Pseudocode is a simplified, language-independent description of an algorithm using English-like statements. It is more structured than plain English but easier to read than code.

Common pseudocode keywords: START, STOP, READ, PRINT, SET, IF...THEN...ELSE...END IF, WHILE...DO...END WHILE, FOR...TO...END FOR.

Decomposition

Decomposition is breaking a large, complex problem into smaller, more manageable sub-problems. Each sub-problem can then be solved independently and combined to form the complete solution.

Worked Examples

Example 1

Write an algorithm to find the largest of two numbers A and B.
Step 1: START
Step 2: READ A, B
Step 3: IF A > B THEN PRINT "A is larger" ELSE PRINT "B is larger or equal"
Step 4: STOP

Example 2

Write pseudocode to calculate the sum of first N natural numbers.
START
READ N
SET sum = 0
SET i = 1
WHILE i ≤ N DO
SET sum = sum + i
SET i = i + 1
END WHILE
PRINT sum
STOP

Example 3

Draw flowchart logic (describe in words) to check if a number is odd or even.
START → READ N → DECISION: Is N mod 2 = 0? → YES: PRINT "Even" → STOP; NO: PRINT "Odd" → STOP

Example 4

Write an algorithm to swap two numbers A and B using a temporary variable.
Step 1: START
Step 2: READ A, B
Step 3: SET temp = A
Step 4: SET A = B
Step 5: SET B = temp
Step 6: PRINT A, B
Step 7: STOP

Example 5

Apply decomposition to the problem "Build a student result management system."
Sub-problems: (a) Input student data, (b) Calculate marks and percentages, (c) Determine grade, (d) Generate report card, (e) Store records. Each part can be designed and tested independently.

Example 6

Write pseudocode to find whether a given year is a leap year.
START
READ year
IF (year mod 4 = 0 AND year mod 100 ≠ 0) OR (year mod 400 = 0) THEN
PRINT "Leap Year"
ELSE
PRINT "Not a Leap Year"
END IF
STOP

Example 7

Write an algorithm to find the factorial of a positive integer N.
Step 1: START
Step 2: READ N
Step 3: SET fact = 1, i = 1
Step 4: WHILE i ≤ N: SET fact = fact x i; SET i = i + 1
Step 5: PRINT fact
Step 6: STOP
For N=4: fact = 1x1x2x3x4 = 24.

Common mistakes

> A very common mistake is writing an algorithm that lacks a clear termination condition in loops — this creates an infinite loop. Always ensure loop variables are updated and the exit condition will eventually be met. Also, pseudocode is not a programming language and does not need to follow exact syntax — clarity is the goal.

Summary

Problem solving in Computer Science follows a systematic process: understand, analyse, design, code, test, and document. Algorithms must be finite, definite, and effective. Flowcharts use standard symbols to represent algorithm logic visually. Pseudocode bridges natural language and programming code. Decomposition helps manage complexity by dividing large problems into smaller parts.

Practice Problems

15 questions with instant feedback.

Question 1 of 15Score 0

An algorithm must always: