Algorithms, Flowcharts & Design Notations
To find the largest of three marks, start with the first as the largest and compare the other two in turn. This also handles equal marks. Testing 80, 80 and 65 exposes algorithms that incorrectly require one value to be strictly larger than both others.
1. What is an Algorithm? (In Simple Words)
An Algorithm is simply a step-by-step list of instructions written in plain English to solve a specific problem.
Before opening any software to code, a programmer writes down the steps on paper. If your logic on paper is clear, writing the C++ code becomes super easy.
Real-Life Example: Think of making a cup of instant noodles:
- Boil 1.5 cups of water in a pan.
- Break noodle cake into pieces and add tastemaker.
- Cook for 2 minutes while stirring occasionally.
- Turn off the flame and serve hot.
This step-by-step recipe is an algorithm!
5 Essential Properties of an Algorithm (Donald Knuth Criteria):
For college exams, remember these 5 points:
- Finiteness: The algorithm must stop after a fixed number of steps. It cannot run into an infinite loop forever.
- Definiteness: Every single step must be crystal clear and unambiguous. Never write confusing statements like “add some suitable number”.
- Input: It must take zero or more well-defined inputs from the user.
- Output: It must produce at least one correct result or output.
- Effectiveness: Every operation must be simple and practical enough to be done by hand on paper in a realistic amount of time.
2. What is a Flowchart?
A Flowchart is a diagram or visual picture of an algorithm.
Instead of reading paragraphs of text, you can glance at standard shapes (like rectangles and diamonds) connected by arrows to see how data moves from start to finish.
Standard ANSI Flowchart Symbols:
The oval marks a start or end and the rectangle marks a processing step. A diamond asks a question, with labelled arrows showing the possible outcomes.
- Oval / Rounded Box (Terminal) — Used for the START or STOP / END of the program.
- Parallelogram (Input / Output) — Used for reading data from the user ( INPUT A ) or printing results ( PRINT Sum ).
- Rectangle (Process) — Used for calculations and assigning values to variables ( Sum = A + B ).
- Diamond (Decision / Condition) — Used for checking conditions ( Is A > B? ). It has two branch paths: YES or NO .
- Arrows (Flowlines) — Shows the direction in which the program moves (usually top-to-bottom or left-to-right).
- Small Circle (Connector) — Connects different parts of a big flowchart on the same page without crossing lines.
View diagram · Standard Flowchart Symbols & Their Purpose
3. Practical Algorithm & Flowchart Examples
Example 1: Finding the Largest of Three Numbers (A, B, C)
Algorithm:
Step 1: START
Step 2: INPUT three numbers A, B, and C
Step 3: IF A > B and A > C THEN
PRINT "A is the Largest"
ELSE IF B > C THEN
PRINT "B is the Largest"
ELSE
PRINT "C is the Largest"
Step 4: STOP
Flowchart Logic Map:
Compare the input values and follow the branch whose condition holds. When values tie for the maximum, the reported maximum should still equal that shared value.
- Start & Input — Accept inputs A, B, and C
- Check A > B — Branch YES (test A vs C) or NO (test B vs C)
- Compare with C — Evaluate surviving candidate against C
- Print Largest & Stop — Output maximum value and terminate
View diagram · Decision Flowchart: Finding the Largest of Three Numbers
Example 2: Finding Factorial of a Number N (N!)
Remember: 5! = 5 * 4 * 3 * 2 * 1 = 120.
Algorithm:
Step 1: START
Step 2: INPUT integer N
Step 3: SET Fact = 1, i = 1
Step 4: REPEAT STEPS 5 to 6 WHILE i <= N
Step 5: Fact = Fact * i
Step 6: i = i + 1
Step 7: PRINT Fact
Step 8: STOP
Example 3: Checking if a Number is Prime
A prime number is a number greater than 1 that cannot be divided evenly by any number except 1 and itself (like 2, 3, 5, 7, 11).
Step 1: START
Step 2: INPUT integer N
Step 3: IF N <= 1 THEN
PRINT "Not Prime" and GOTO Step 8
Step 4: SET i = 2, isPrime = True
Step 5: WHILE i * i <= N DO
IF N % i == 0 THEN
isPrime = False
BREAK
i = i + 1
Step 6: IF isPrime == True THEN
PRINT "Number is Prime"
ELSE
PRINT "Number is Not Prime"
Step 7: STOP
4. Advantages & Limitations of Flowcharts
| Advantages | Limitations |
|---|---|
| Easy to Understand: Non-technical people and beginners can easily understand the program logic visually. | Hard to Modify: If you want to change a small step, you often have to redraw the whole diagram from scratch. |
| Easy Bug Finding: Helps you spot logic errors or missing conditions before typing any code. | Takes Too Much Space: Flowcharts for large software take up several pages and become messy. |
| Language Independent: The same flowchart can be used to write code in C++, Java, or Python. | Can Get Confusing: If there are too many branches and loops, lines cross each other and look like spaghetti. |
DAVV Exam Preparation Tips
Frequently Asked 5-Mark Questions:
- Explain the five essential characteristics of an algorithm defined by Donald Knuth.
Model Answer: List and explain:- Finiteness: Must finish after a fixed number of steps.
- Definiteness: Every step must be clear and clear-cut.
- Input: Accepts zero or more inputs.
- Output: Produces at least one result.
- Effectiveness: Every operation must be simple and doable on paper.
- Draw standard flowchart symbols and state the purpose of each symbol.
Model Answer: Draw neat diagrams with labels:- Oval: Start / Stop
- Parallelogram: Input / Output
- Rectangle: Calculation / Process
- Diamond: Decision / Branching (Yes/No)
- Circle: Connector
Frequently Asked 10-Mark Questions:
- Write an algorithm and draw a complete flowchart to check whether a given number is Prime or Composite.
Model Answer:- Define what a prime number is (divisible only by 1 and itself).
- Write the step-by-step algorithm using loop condition
i * i <= Nori <= N/2. - Draw the complete ANSI flowchart with start terminal, input box, decision diamond, loop line, output box, and stop terminal.
- Trace it with two sample inputs: N = 7 (Prime) and N = 9 (Composite/Not Prime).