ALGORITHMS AND FLOWCHARTS


1. ALGORITHMS

Definition:

An algorithm is a step-by-step procedure to solve a problem or perform a task.

Functions of an Algorithm:

1.     Problem-solving – Breaks down complex tasks into simple steps.

2.     Efficiency – Helps optimize time and resources.

3.     Clarity – Makes logic easy to understand before coding.

4.     Reproducibility – Can be reused for similar problems.

5.     Documentation – Serves as a reference for programmers.

Rules for Writing a Good Algorithm:

 Input & Output – Must have defined inputs and produce results.
 Definiteness – Each step must be clear and precise.
 Finiteness – Must terminate after a finite number of steps.
 Effectiveness – Every step should be doable and efficient.
 Language Independent – Can be written in plain English or pseudocode.

Examples of Algorithms (Problem-Solving)

Example 1: Algorithm to Find the Largest of Three Numbers

1.     Start

2.     Read three numbers (A, B, C)

3.     If A > B and A > C, then

o    Display "A is the largest"

4.     Else if B > A and B > C, then

o    Display "B is the largest"

5.     Else

o    Display "C is the largest"

6.     End

Example 2: Algorithm to Check if a Number is Even or Odd

1.     Start

2.     Read a number (N)

3.     If N % 2 == 0, then

o    Display "Even"

4.     Else

o    Display "Odd"

5.     End

Example 3: Algorithm to Calculate the Sum of First N Natural Numbers

1.     Start

2.     Read a number (N)

3.     Initialize Sum = 0 and Counter = 1

4.     Repeat while Counter ≤ N:

o    Sum = Sum + Counter

o    Counter = Counter + 1

5.     Display Sum

6.     End


2. FLOWCHARTS

Definition:

A flowchart is a visual representation of an algorithm using symbols and arrows.

Functions of a Flowchart:

1.     Visual Clarity – Makes logic easier to understand.

2.     Debugging – Helps identify errors before coding.

3.     Documentation – Acts as a blueprint for programmers.

4.     Communication – Simplifies explanations for non-programmers.

Characteristics of a Good Flowchart:

 Standard Symbols – Uses universally recognized shapes.
 Logical Flow – Steps must follow a clear sequence.
 Simplicity – Avoids unnecessary complexity.
 One Start & One End Point – Ensures completeness.

 


Comments

Popular posts from this blog

The Internet JSS2

PROGRAMMING IN BASIC II - Built-in Functions

FILE SHARING -JS2