0% found this document useful (0 votes)
3 views1 page

Topic 1

This document introduces the concept of algorithms, defining them as a sequence of instructions for solving problems with specific criteria such as input, output, definiteness, finiteness, and effectiveness. It provides an example of Euclid's algorithm for computing the greatest common divisor (gcd) and outlines the steps and pseudocode for its implementation. Additionally, it discusses the importance of analyzing algorithm efficiency in terms of time, space, simplicity, and generality.

Uploaded by

rsviniba96
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Topic 1

This document introduces the concept of algorithms, defining them as a sequence of instructions for solving problems with specific criteria such as input, output, definiteness, finiteness, and effectiveness. It provides an example of Euclid's algorithm for computing the greatest common divisor (gcd) and outlines the steps and pseudocode for its implementation. Additionally, it discusses the importance of analyzing algorithm efficiency in terms of time, space, simplicity, and generality.

Uploaded by

rsviniba96
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

CS3401 UNIT 1 – INTRODUCTION

ALGORITHM:
An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a
required output for any legitimate input in a finite amount of time. In addition, all algorithms must
satisfy the following criteria:
1. Input
2. Output
3. Definiteness
4. Finiteness
5. Effectiveness.

Notion of an Algorithm:

For example, gcd(60, 24) can be computed as follows:


 gcd(m, n) = gcd(n, m mod n),
 gcd(60, 24) = gcd(24, 12) = gcd(12, 0) = 12.

ALGORITHM:
Euclid’s algorithm for computing gcd(m, n)
Step 1 If n = 0, return the value of m as the answer and stop; otherwise, proceed to Step 2.
Step 2 Divide m by n and assign the value of the remainder to r.
Step 3 Assign the value of n to m and the value of r to n. Go to Step 1.

PSEUDOCODE:
ALGORITHM Euclid(m, n) //Computes gcd(m, n) by Euclid’s algorithm
//Input: Two nonnegative, not-both-zero integers m and n
//Output: Greatest common divisor of m and n
while n _= 0 do
r ←m mod n
m←n
n←r
return m

1.1 Analyzing an Algorithm


For analyzing an algorithm the most important is efficiency. There are two kinds of algorithm efficiency:
The following factors should be considerd while analysing an algorithm
 Time efficiency - Speed (how fast the algorithm runs)
 Space efficieny - memory (howmuch memory the algorithm needs)
 Simplicity - easy to understand
 Generality - which range of input is accepted.

You might also like