0% found this document useful (0 votes)
8 views25 pages

Algorithm

The document provides a comprehensive overview of algorithms, defining them as finite sets of steps for problem-solving, and detailing their characteristics, properties, advantages, and disadvantages. It also discusses methods for writing algorithms, including pseudocode and flowcharts, and emphasizes the importance of algorithm correctness and efficiency. Additionally, it outlines various important problem types in algorithmic design, such as sorting, searching, and dynamic programming.

Uploaded by

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

Algorithm

The document provides a comprehensive overview of algorithms, defining them as finite sets of steps for problem-solving, and detailing their characteristics, properties, advantages, and disadvantages. It also discusses methods for writing algorithms, including pseudocode and flowcharts, and emphasizes the importance of algorithm correctness and efficiency. Additionally, it outlines various important problem types in algorithmic design, such as sorting, searching, and dynamic programming.

Uploaded by

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

INTRODUCTION

ALGORITHM
What is an algorithm?
An Algorithm is a finite set of steps of which may require one or more operations. Every
operation may be characterized as either a simple or complex.

Notions of an Algorithms:
Need of the Algorithms
1. Efficiency
2. Consistency
3. Scalability
4. Automation
5. Standardization
Characteristics of an Algorithm
1. Every step of an algorithm should perform a single task.
2. Ambiguity (Confusion) should not be included at any stage in an algorithm.
3. An algorithm should involve a finite number of steps to arrive at a solution.
4. Simple statement and structures should be used in the development of the algorithm.
5. Every algorithm should lead to a unique solution of the problem.
6. An algorithm should have the capability to handle some unexpected situations, which may
arise during the solution of a problem.
Properties of an Algorithm
Input: Zero / more quantities are externally supplied.
Output: At least one quantity is produced.
Definiteness: Each instruction is clear and unambiguous.
Finiteness: If the instructions of an algorithm is traced then for all cases the
algorithm must terminates after a finite number of steps.
Efficiency: Every instruction must be very basic and runs in short time.
Advantages
1. Efficiency – Optimizes time and resource usage.
2. Reusability – Can be applied to multiple problems.
3. Scalability – Works well with large data sets.
4. Accuracy – Ensures reliable and consistent results.
5. Automation – Reduces human effort and errors.
Disadvantages
1. Complexity – Some algorithms are hard to design and implement.
2. High Computational Cost – Can require significant time and resources.
3. Hardware Limitations – Performance depends on computing power.
4. Input Sensitivity – Effectiveness varies with different data sets.
5. Difficult to Understand – Advanced algorithms can be challenging to grasp.
Activity: "Algorithm Relay“
05/02/2025
Examples of Real-Life
Algorithms
1.Recipes
2.Sorting Papers
3.Traffic Signals
4.Bus Schedules
5.GPS
6.Facial Recognition
7.Spotify
8.Google Search
9.Facebook
10.Online Shopping
Steps for writing an
algorithm
1. An algorithm is a procedure.
It has two parts; the first part is head and the second part is body.
2. The Head section consists of keyword Algorithm and Name of the algorithm with
parameter list.
E.g. Algorithm name1(p1, p2,…,p3)
The head section also has the following:
//Problem Description:
//Input:
//Output:

3. In the body of an algorithm various programming constructs like if, for, while and some
statements like assignments are used.
4. The compound statements may be enclosed with { and } brackets. if, for, while can be
closed by endif, endfor, endwhile respectively. Proper indention is must for block.
Steps for writing an
algorithm
5. Comments are written using // at the beginning.
6. The identifier should begin by a letter and not by digit. It contains alpha
numeric letters after first letter. No need to mention data types.
7. The left arrow “←” used as assignment operator. E.g. v←10
8. Boolean operators (TRUE, FALSE), Logical operators (AND, OR, NOT) and
Relational operators (<,<=, >, >=,=, ≠, <>) are also used.
9. Input and Output can be done using read and write.
10. Array[], if then else condition, branch and loop can be also used in
algorithm.
Example
The greatest common divisor(GCD) of two nonnegative integers m and n (not-both-zero), denoted
gcd(m, n), is defined as the largest integer that divides both m and n evenly, i.e., with a remainder
of zero.
Euclid’s algorithm is based on applying repeatedly the equality
gcd(m, n) = gcd(n, m mod n),
where m mod n is the remainder of the division of m by n, until m mod n is equal to 0.
Since gcd(m, 0) = m, the last value of m is also the greatest common divisor of the initial m and n.
gcd(60, 24) can be computed as follows :gcd(60, 24) = gcd(24, 12) = gcd(12, 0) = 12.
Euclid’s algorithm
1. Start with two numbers, m and n, where m≥n.
2. Divide m by n and find the remainder r.
m=n×q+r , where q is the quotient and r is the remainder.
3. Replace m with n, and n with r.
4. Repeat the process (step 2) with the new values of m and n, until the
remainder r=0.
5. When r=0, the GCD is the current value of n (which is the last non-zero
remainder).
FUNDAMENTALS
OF ALGORITHMIC
PROBLEM SOLVING
Understanding the Problem
 This is the first step in designing of algorithm.
 Read the problem’s description carefully to understand the
problem statement completely.
 Ask questions for clarifying the doubts about the problem.
 Identify the problem types and use existing algorithm to find
solution.
 Input (instance) to the problem and range of the input get fixed.
Decision making
 Ascertaining the Capabilities of the Computational Device
 Choosing between Exact and Approximate Problem Solving
 Algorithm Design Techniques
Methods of Specifying an
Algorithm
There are three ways to specify an algorithm. They are:
1. Natural language
2. Pseudocode
3. Flowchart
Natural Language
It is very simple and easy to specify an algorithm using natural language. But many
times
Specification of algorithm by using natural language is not clear and thereby we get
brief
Specification.
• Example: An algorithm to perform addition of two numbers.
• Step 1: Read the first number, say a.
• Step 2: Read the first number, say b.
• Step 3: Add the above two numbers and store the result in c.
• Step 4: Display the result from c.

Such a specification creates difficulty while actually implementing it. Hence many
programmers prefer to have specification of algorithm by means of Pseudocode.
Pseudocode
Pseudocode is a mixture of a natural language and programming language constructs.
Pseudocode is usually more precise than natural language.
For Assignment operation left arrow “←”, for comments two slashes “//”,if
condition, for,
while loops are used.
• ALGORITHM Sum(a,b)
• //Problem Description: This algorithm performs addition of two numbers
• //Input: Two integers a and b
• //Output: Addition of two integers
• c←a+b
• return c
This specification is more useful for implementation of any language.
Flowchart
Flowchart is a graphical
representation of an algorithm. It
is a method of expressing an
algorithm by a collection of
connected geometric shapes
containing descriptions of the
algorithm’s steps.
Proving an Algorithm’s Correctness
 Once an algorithm has been specified then its correctness must be proved.
 An algorithm must yields a required result for every legitimate input in a finite
amount of time.
 For example, the correctness of Euclid’s algorithm for computing the greatest
common divisor stems from the correctness of the equality gcd(m, n) = gcd(n, m
mod n).
 A common technique for proving correctness is to use mathematical induction
because an algorithm’s iterations provide a natural sequence of steps needed for
such proofs.
 The notion of correctness for approximation algorithms is less straightforward
than it is for exact algorithms. The error produced by the algorithm should not
exceed a predefined limit.
Analyzing an Algorithm
 For an algorithm the most important is efficiency. In fact, there are two kinds
of algorithm efficiency. They are:
• Time efficiency, indicating how fast the algorithm runs, and
• Space efficiency, indicating how much extra memory it uses.
 The efficiency of an algorithm is determined by measuring both time
efficiency and space efficiency.
 So factors to analyse an algorithm are:
• Time efficiency of an algorithm
• Space efficiency of an algorithm
• Simplicity of an algorithm
• Generality of an algorithm
Coding an Algorithm
 The coding / implementation of an algorithm is done by a suitable
programming language like C, C++, JAVA.
 The transition from an algorithm to a program can be done either
incorrectly or very inefficiently. Implementing an algorithm
correctly is necessary.
 The Algorithm power should not reduced by inefficient
implementation.
 It is very essential to write an optimized code (efficient code) to
reduce the burden of compiler.
IMPORTANT PROBLEM TYPES
1. Sorting and Searching – Numerical and Binary search.
2. Graph Algorithms – Dijkstra’s algorithm, Prim’s algorithm, DFS and BFS.
3. Dynamic Programming – Knapsack problem.
4. Greedy Algorithms – Huffman coding.
5. Divide and Conquer – Merge sort.
6. String Algorithms – KMP algorithm.
7. Computational Geometry – line intersection.
8. Network Flow and Linear Programming – linear programming models.
9. Randomized Algorithm – randomized quicksort.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy