1. Define Algorithm? Explain the notion of an algorithm and list out its important properties.
Definition of an Algorithm
An algorithm is a finite sequence of well-defined instructions designed to perform a specific task or
solve a particular problem. These instructions are executed in a logical order to transform input into a
desired output. Algorithms are fundamental in computer science and mathematics, as they form the
backbone of programming and problem-solving.
Notion of an Algorithm
The notion of an algorithm revolves around step-by-step computation to achieve a goal. It can be
expressed in different forms, such as:
Natural Language (human-readable steps)
Pseudocode (structured description of logic)
Flowcharts (graphical representation)
Programming Code (implementation in languages like Python, C, etc.)
Algorithms must be precise, unambiguous, and effective, ensuring they solve a problem in a finite
amount of time.
Important Properties of an Algorithm
A well-defined algorithm must possess the following key properties:
1. Finiteness
o The algorithm must terminate after a finite number of steps. It should not run
indefinitely.
2. Definiteness (Unambiguity)
o Each step of the algorithm must be clear and precisely defined. There should be no
ambiguity in instructions.
3. Input
o An algorithm must take zero or more inputs from a well-defined domain.
4. Output
o It must produce at least one output, which is the result after execution.
5. Effectiveness
o Every step should be basic and executable within a finite amount of time, without
requiring infinite resources.
6. Correctness
o The algorithm must produce the correct result for all valid inputs.
7. Generality
o It should be applicable to a range of inputs, not just a specific case.
8. Optimization (Efficiency)
o A good algorithm should be optimized in terms of time complexity (speed) and space
complexity (memory usage).
Example of a Simple Algorithm
Algorithm to find the sum of two numbers:
1. Start
2. Take two numbers as input
3. Add the numbers
4. Display the result
5. Stop
2. Discuss various algorithms to calculate GCD of 2 numbers.
Algorithm GCD(a, b)
1. While b ≠ 0 do:
2. a ← a mod b
3. Swap a and b
4. Return a as the GCD