CSE NotesCSE Notes
Simplifying Complexity

What is an Algorithm?

An algorithm is a step-by-step procedure or formula for solving a problem or performing a task. It takes an input, processes it through a series of well-defined steps, and produces an output.

Key Components of an Algorithm

  1. Input: The data you start with.
  2. Output: The result after processing the input.
  3. Finite Steps: It must have a finite number of steps.
  4. Well-Defined Instructions: Each step must be clear and unambiguous.
  5. Effectiveness: Each step must be basic enough to be carried out, in principle, by a person using only paper and pencil.

Example: Algorithm for Finding the Maximum of Three Numbers

  1. Input: Three numbers, a,b,.
  2. Output: The maximum of the three numbers.
Steps:
  1. Start.
  2. Read the values of a, b, .
  3. Set max to .
  4. If , then set max to b.
  5. If , then set max to c.
  6. Output max.
  7. End

Pseudocode

pseudocode is a high-level description of an algorithm that uses the structural conventions of programming languages but is intended for human reading rather than machine reading. It allows you to outline the logic of your code without getting bogged down in syntax details.

Key Features of Pseudocode:

  1. Readable: It should be easily understandable by humans.
  2. Language-Agnostic: It doesn’t adhere to any specific programming language syntax.
  3. Structured: It uses common programming structures like loops, conditionals, and functions.

Pseudocode Example

Here’s a pseudocode representation of the algorithm:

BEGIN
INPUT a, b, c
max = a
IF b > max THEN
max = b
ENDIF
IF c > max THEN
max = c
ENDIF
OUTPUT max
END