Introduction to Algorithm
Tanaji Patil
Department of Computer Science and Engineering
Tanaji Patil Introduction to Algorithm patiltanaji@gmail.com 1 / 13
Contents
1 Introduction
2 Algorithm Specifications
English-Like Language
Pseudocode
Flowchart
Tanaji Patil Introduction to Algorithm patiltanaji@gmail.com 2 / 13
Introduction
W HAT IS AN A LGORITHM ?
Definition: An algorithm is a finite set of instructions that, if followed, accomplishes a particular task.
All algorithms must satisfy the following criteria:
1 Input: Zero or more quantities are externally supplied.
2 Output: At least one quantity is produced.
3 Definiteness: Each instruction is clear and unambiguous.
4 Finiteness: If we trace out the instructions of an algorithm, then for all cases, the algorithm terminates
after a finite number of steps.
5 Effectiveness: Every instruction must be very basic so that it can be carried out, in principle, by a person
using only pencil and paper. It must be feasible.
Tanaji Patil Introduction to Algorithm patiltanaji@gmail.com 3 / 13
Algorithm Specifications
Introduction to Algorithm Specifications
Algorithm specification involves describing the steps of an algorithm clearly and unambiguously.
A well-specified algorithm:
Defines the input and output clearly.
Provides a step-by-step process.
Ensures correctness and efficiency.
Three ways
English like language
Pseudocode
Flowchart
Tanaji Patil Introduction to Algorithm patiltanaji@gmail.com 4 / 13
Algorithm Specifications English-Like Language
English-Like Language
Example:
1 Step 1: Start.
2 Step 2: Read the input values.
3 Step 3: If the input is invalid, show an error message.
4 Step 4: Compute the required result using the formula.
5 Step 5: Print the result.
6 Step 6: End.
Advantages:
Easy for non-technical audiences to understand.
Requires no prior knowledge of formal notations.
Useful for high-level discussions and algorithm overviews.
Disadvantages:
Can be verbose and ambiguous.
Not standardized, making it harder to translate directly into code.
May omit implementation details.
Tanaji Patil Introduction to Algorithm patiltanaji@gmail.com 5 / 13
Algorithm Specifications Pseudocode
What is Pseudocode?
Pseudocode is a high-level description of an algorithm.
It uses structured, plain language to describe steps.
Benefits of pseudocode:
Easy to write and understand.
Independent of programming language.
Serves as a bridge between an idea and implementation.
Disadvantages of pseudocode:
Requires some familiarity with programming concepts.
May not be as intuitive as flowcharts for non-technical audiences.
Tanaji Patil Introduction to Algorithm patiltanaji@gmail.com 6 / 13
Algorithm Specifications Pseudocode
Pseudocode Conventions
Comments begin with // and continue until the end of line.
Blocks are indicated with matching braces: { and }. A compound statement and body of a procedure
forms a block. Statements are delimited by ;
An identifier begins with a letter. The data types of variables are not explicitly declared.
Compound data types can be formed with records.
Tanaji Patil Introduction to Algorithm patiltanaji@gmail.com 7 / 13
Algorithm Specifications Pseudocode
Pseudocode Conventions . . .
Assignment of values to variables is done using the assignment statement
(variable) := (expression);
There are two boolean values true and f alse. In order to produce these values, the logical operators and,
or, and not and the relational operators <, ≤, =, ̸=, ≥, and > are provided.
Elements of multidimensional arrays are accessed using [ and ]. For example, if A is a two dimensional
array, the (i, j)th element of the array is denoted as A[i, j]. Array indices start at zero.
while loop:
Tanaji Patil Introduction to Algorithm patiltanaji@gmail.com 8 / 13
Algorithm Specifications Pseudocode
Pseudocode Conventions . . .
for loop:
repeat-until loop:
Tanaji Patil Introduction to Algorithm patiltanaji@gmail.com 9 / 13
Algorithm Specifications Pseudocode
Pseudocode Conventions . . .
if statement:
case statement:
Tanaji Patil Introduction to Algorithm patiltanaji@gmail.com 10 / 13
Algorithm Specifications Pseudocode
Pseudocode Conventions . . .
Input and output are done using the instructions read and write. No format is used to specify the size of
input or output quantities.
There is only one type of procedure: Algorithm. An algorithm consists of a heading and a body. The
heading takes the form.
Algorithm Name (< parameter list >)
Tanaji Patil Introduction to Algorithm patiltanaji@gmail.com 11 / 13
Algorithm Specifications Pseudocode
Example: Pseudocode Conventions
In this algorithm (named Max), A and n are procedure parameters. Result and i are local variables.
Tanaji Patil Introduction to Algorithm patiltanaji@gmail.com 12 / 13
Algorithm Specifications Flowchart
Flowchart Symbols
Tanaji Patil Introduction to Algorithm patiltanaji@gmail.com 13 / 13