Algorithm
• An algorithm is a step-by-step set of
instructions or a well-defined procedure for
solving a specific problem or accomplishing a
particular task.
Characteristics of Algorithm
.
• Input: An algorithm has zero or more inputs.
• Output: An algorithm produces at least one output.
• Definiteness: All instructions in an algorithm must be
unambiguous, precise.
• Finiteness: An algorithm must terminate after a finite
number of steps in all test cases. In simple words, the
algorithm should stop after completing a certain
number of steps — it should not go on forever.
• Effectiveness: An algorithm must be developed by
using very basic, simple, and feasible operations so
that one can trace it out by using just paper and
pencil.
• Advantages –
• It is easy to understand.
• An algorithm is a step-wise representation of
a solution to a given problem.
• Disadvantages-
• It is time consuming.
• Understanding complex logic through
algorithms can be very difficult.
Flowchart
• A flowchart is a type of diagram that
represents a workflow or process. A flowchart
can also be defined as a diagrammatic
representation of an algorithm, a step-by-step
approach to solving a task.
Pseudocode
• A Pseudocode is defined as a step-by-step
description of an algorithm. Pseudocode does not
use any programming language in its
representation instead it uses the simple English
language text as it is intended for human
understanding rather than machine reading.
Pseudocode is the intermediate state between an
idea and its implementation(code) in a high-level
language.
Common Pseudocode Keywords
• 1. Input/Output:
• INPUT, READ, GET: Used to acquire data from
a user or external source.
• OUTPUT, PRINT, DISPLAY, SHOW, WRITE: Used
to present results or information.
• 2. Control Flow (Decision Making):
• IF, THEN, ELSE, ENDIF: For conditional execution based on a
true/false condition.
• CASE, OF, OTHERWISE: For handling multiple potential
outcomes based on a variable's value.
• 3. Control Flow (Iteration/Loops):
• WHILE, ENDWHILE: For loops where the condition is
checked at the beginning (pre-test).
• REPEAT, UNTIL: For loops where the body executes at least
once before the condition is checked at the end (post-test).
• FOR, TO, STEP, ENDFOR: For loops that iterate a specific
number of times or through a range.
• 4. Actions/Operations:
• SET, INIT, ASSIGN: For initializing or assigning
values to variables.
• COMPUTE, CALCULATE, DETERMINE: For
performing calculations.
• ADD, SUBTRACT, MULTIPLY, DIVIDE: For
arithmetic operations.
• INCREMENT, DECREMENT: For increasing or
decreasing a value by a fixed amount.
• CALL: For invoking functions or procedures.
Write an algorithm and draw the
flowchart
• Question 1. Even or odd.
• Question [Link] of N no.
• Question 3. Print the input number 5 times.
• Question 4. Print numbers from 1 to 10.
• Question 5. Print the first 5 multiples of 3.
• Algorithm:
• 1. Start
• 2. Put input a
• 3. Now check the condition if a % 2 == 0, goto
step 5. Else goto step 4
• 4. Now print(“number is odd”) and goto step 6
• 5. Print(“number is even”)
• 6. Stop