Study Guide

Algorithms and Flowcharts, CBSE Class 11 CS Problem Solving

Learn algorithms and flowcharts for CBSE Class 11 CS. Covers algorithm writing, flowchart symbols, pseudo code, and solved examples for exam preparation.

Problem solving is the first step in computer science. Before writing any program, you need to understand the problem and plan a solution using algorithms and flowcharts. This chapter is important in CBSE Class 11 CS and helps you think logically.

What is Problem Solving?

Problem solving is the process of identifying a problem, developing a step-by-step solution, and implementing it. In computer science, we follow these steps:

  1. Understanding the problem - What is the input? What output do we need?
  2. Developing an algorithm - Step-by-step solution
  3. Drawing a flowchart - Visual representation
  4. Writing the program - Implementing in a programming language
  5. Testing - Verifying the solution works correctly

What is an Algorithm?

An algorithm is a finite set of well-defined instructions to solve a specific problem. It takes input, processes it, and produces the desired output.

Properties of a Good Algorithm

Property Meaning
Finiteness Must terminate after a finite number of steps
Definiteness Each step must be precisely defined
Input Must accept zero or more inputs
Output Must produce at least one output
Effectiveness Each step must be basic enough to be carried out

Algorithm Examples

Algorithm 1: Find the sum of two numbers

Step 1: START
Step 2: Read two numbers A and B
Step 3: Calculate SUM = A + B
Step 4: Print SUM
Step 5: STOP

Algorithm 2: Check if a number is even or odd

Step 1: START
Step 2: Read a number N
Step 3: Calculate R = N mod 2
Step 4: If R = 0, then print "Even"
Step 5: Else print "Odd"
Step 6: STOP

Algorithm 3: Find the largest of three numbers

Step 1: START
Step 2: Read three numbers A, B, C
Step 3: If A > B and A > C, then print "A is largest"
Step 4: Else if B > A and B > C, then print "B is largest"
Step 5: Else print "C is largest"
Step 6: STOP

Algorithm 4: Find the factorial of a number

Step 1: START
Step 2: Read number N
Step 3: Set FACT = 1
Step 4: Set I = 1
Step 5: If I > N, go to Step 8
Step 6: FACT = FACT * I
Step 7: I = I + 1, go to Step 5
Step 8: Print FACT
Step 9: STOP

Algorithm 5: Check if a number is prime

Step 1: START
Step 2: Read number N
Step 3: If N < 2, print "Not Prime" and go to Step 9
Step 4: Set I = 2
Step 5: If I >= N, go to Step 8
Step 6: If N mod I = 0, print "Not Prime" and go to Step 9
Step 7: I = I + 1, go to Step 5
Step 8: Print "Prime"
Step 9: STOP

Algorithm 6: Find the sum of first N natural numbers

Step 1: START
Step 2: Read N
Step 3: Set SUM = 0
Step 4: Set I = 1
Step 5: If I > N, go to Step 8
Step 6: SUM = SUM + I
Step 7: I = I + 1, go to Step 5
Step 8: Print SUM
Step 9: STOP

What is a Flowchart?

A flowchart is a diagrammatic representation of an algorithm. It uses standardized symbols connected by arrows to show the flow of logic.

Flowchart Symbols

Symbol Name Purpose
Oval/Rounded Rectangle Terminal Start and End
Rectangle Process Computation or action
Parallelogram Input/Output Reading input or displaying output
Diamond Decision Yes/No or True/False question
Arrow Flow Line Shows the direction of flow
Circle Connector Connects parts of the flowchart

Advantages of Flowcharts

  1. Visual clarity - Easier to understand than text
  2. Communication - Easy to share and discuss
  3. Debugging - Errors are easier to find
  4. Documentation - Serves as program documentation
  5. Logic planning - Helps plan before coding

Disadvantages of Flowcharts

  1. Complex programs - Flowcharts become very large
  2. Time-consuming - Takes time to draw
  3. Difficult to modify - Changes require redrawing
  4. No standards for detail level - Different people draw differently

Flowchart Guidelines

  1. Use standard symbols only
  2. Flow should generally go from top to bottom, left to right
  3. Use arrows to show direction
  4. Every flowchart must have a START and STOP
  5. Use connectors for complex flowcharts
  6. Write brief text inside symbols

Pseudo Code

Pseudo code is a simplified, informal way of writing an algorithm that resembles a programming language but is not bound by syntax rules.

Pseudo Code Conventions

Keyword Purpose
BEGIN / END Start and end of the program
READ / INPUT Take input from user
PRINT / DISPLAY Show output
IF...THEN...ELSE Decision making
WHILE...DO Loop with condition at start
FOR...TO...DO Counting loop
REPEAT...UNTIL Loop with condition at end
SET / = Assign a value

Pseudo Code Examples

Example 1: Sum of two numbers

BEGIN
    READ A, B
    SET SUM = A + B
    PRINT SUM
END

Example 2: Largest of three numbers

BEGIN
    READ A, B, C
    IF A > B AND A > C THEN
        PRINT "A is largest"
    ELSE IF B > A AND B > C THEN
        PRINT "B is largest"
    ELSE
        PRINT "C is largest"
    END IF
END

Example 3: Factorial of N

BEGIN
    READ N
    SET FACT = 1
    FOR I = 1 TO N DO
        FACT = FACT * I
    END FOR
    PRINT FACT
END

Example 4: Fibonacci series up to N terms

BEGIN
    READ N
    SET A = 0, B = 1
    PRINT A, B
    FOR I = 3 TO N DO
        SET C = A + B
        PRINT C
        SET A = B
        SET B = C
    END FOR
END

Example 5: Linear search in a list

BEGIN
    READ LIST of N elements
    READ ITEM to search
    SET FOUND = FALSE
    FOR I = 1 TO N DO
        IF LIST[I] = ITEM THEN
            PRINT "Found at position", I
            SET FOUND = TRUE
        END IF
    END FOR
    IF FOUND = FALSE THEN
        PRINT "Item not found"
    END IF
END

Decomposition

Decomposition is the process of breaking down a complex problem into smaller, more manageable sub-problems. Each sub-problem can be solved independently.

Example: Building a school website

  • Sub-problem 1: Design the layout (header, footer, navigation), Sub-problem 2: Create the home page content, Sub-problem 3: Build the student registration form, Sub-problem 4: Set up the photo gallery, Sub-problem 5: Add contact information page

Python Implementation of Algorithms

Here are some algorithms implemented in Python:

Sum of two numbers

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
total = a + b
print("Sum =", total)
Enter first number: 15
Enter second number: 25
Sum = 40

Even or Odd

n = int(input("Enter a number: "))
if n % 2 == 0:
    print(n, "is Even")
else:
    print(n, "is Odd")
Enter a number: 7
7 is Odd

Factorial

n = int(input("Enter a number: "))
fact = 1
for i in range(1, n + 1):
    fact = fact * i
print("Factorial of", n, "=", fact)
Enter a number: 5
Factorial of 5 = 120

Check Prime

n = int(input("Enter a number: "))
is_prime = True
if n < 2:
    is_prime = False
else:
    for i in range(2, n):
        if n % i == 0:
            is_prime = False
            break

if is_prime:
    print(n, "is a Prime number")
else:
    print(n, "is not a Prime number")
Enter a number: 17
17 is a Prime number

Fibonacci Series

n = int(input("How many terms? "))
a, b = 0, 1
print("Fibonacci series:")
for i in range(n):
    print(a, end=" ")
    a, b = b, a + b
How many terms? 8
Fibonacci series:
0 1 1 2 3 5 8 13

Important Questions

Q1. What is an algorithm? List its properties.

An algorithm is a finite set of well-defined, step-by-step instructions to solve a specific problem. Its properties are: Finiteness (must end after finite steps), Definiteness (each step must be clear and unambiguous), Input (accepts zero or more inputs), Output (produces at least one output), and Effectiveness (each step must be feasible and basic).

Q2. Write an algorithm and pseudo code to find the largest of three numbers.

See Algorithm 3 and Pseudo Code Example 2 above.

Q3. What are the advantages and disadvantages of flowcharts?

Advantages: Visual clarity makes logic easier to understand, better communication tool, easier debugging, and good documentation. Disadvantages: Complex programs produce very large flowcharts, time-consuming to draw, difficult to modify (requires redrawing), and no standard for the level of detail.

Q4. What is decomposition in problem solving?

Decomposition is the process of breaking down a complex problem into smaller, simpler sub-problems that can be solved independently. Each sub-problem is easier to understand, solve, and test. The solutions to sub-problems are then combined to solve the original problem.

Quick Revision

  • Algorithm = finite, step-by-step instructions to solve a problem, Properties: Finiteness, Definiteness, Input, Output, Effectiveness
  • Flowchart = visual/diagrammatic representation of an algorithm, Flowchart symbols: Oval (start/stop), Rectangle (process), Diamond (decision), Parallelogram (I/O)
  • Pseudo code = informal algorithm in programming-like language
  • Decomposition = breaking complex problems into smaller parts, Always start with START and end with STOP, Practice writing algorithms for: sum, largest, factorial, prime check, Fibonacci

Want to learn more?

Explore free chapter-wise notes with quizzes and code playground

Prefer watching over reading?

Subscribe for free.

Subscribe on YouTube