0% found this document useful (0 votes)
11 views16 pages

3-Overview of Course Introduction To Algorithms-03-01-2024

DAA

Uploaded by

swastik raj
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)
11 views16 pages

3-Overview of Course Introduction To Algorithms-03-01-2024

DAA

Uploaded by

swastik raj
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/ 16

Design and Analysis of Algorithms

• Course Code: BCSE304L


• Course Type: Theory (ETH)
• Slot: A1+TA1 & & A2+TA2
• Class ID: VL2023240500901
VL2023240500902
A1+TA1 A2+TA2
Day Start End Day Start End
Monday 08:00 08:50 Monday 14:00 14:50
Wednesday 09:00 09:50 Wednesday 15:00 15:50
Friday 10:00 10:50 Friday 16:00 16:50

Dr. Venkata Phanikrishna B, SCOPE, VIT-Vellore


Syllabus- Module 1
Module:1 Design Paradigms: Greedy, Divide and Conquer 6 hours
Techniques

Overview and Importance of Algorithms - Stages of algorithm


development: Describing the problem, Identifying a suitable technique,
Design of an algorithm, Derive Time Complexity, Proof of Correctness of
the algorithm, Illustration of Design Stages -
Greedy techniques: Fractional Knapsack Problem, and Huffman coding
Divide and Conquer: Maximum Subarray, Karatsuba faster integer
multiplication algorithm.

Dr. Venkata Phanikrishna B, SCOPE, VIT-Vellore


Introduction to Algorithms

Algorithm is a finite set of instructions that is followed, accomplishes a particular


task.
Algorithms criteria :
• Input: It may be zero or more quantities are externally supplied. But input not
necessary for all Algorithms.
• Output: At least one quantity is produced. It is must for all the algorithms
• Definiteness: Each instruction is clear and unambiguous.
• Finiteness: The instruction (Steps) of an algorithm must be finite. Means
Algorithm terminate after finite number of steps (Instructions).
• 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 is not enough that each
operation be definite, it also must be feasible (possible or realistic).
An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for
obtaining a required output for any valid input in a finite amount of time.
Representation of Algorithms
Algorithm can be described in many ways like

• English for specifying algorithm in step by step


• Flowchart for graphical representation.

But these two ways work well only if algorithm is small or simple. For large or
big algorithm we are going to use pseudo code.

• PSEUDOCODE
• Pseudo code is a kind of structured English for describing algorithms. It
allows the designer to focus on the logic of the algorithm without being
distracted (diverted) by details of language syntax.
• It describes the entire logic of the algorithm so that implementation
becomes a rote mechanical task of translating line by line into source code.
Algorithm Example:
• Euclid Greatest common divisor [gcd(m, n)] : if m and n are two integers
Provides the the largest integer that divides both m and n.

• gcd(60, 24) can be computed as :


gcd(60, 24) = gcd(24, 12) = gcd(12, 0) = 12.

Algorithm:
• 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.
Same algorithm in a 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
Importance of Algorithms
• Problem Solving: Algorithms provide systematic and efficient approaches to problem-solving. They enable the decomposition of complex
problems into manageable steps.
• Efficiency: Algorithms are crucial for optimizing resource usage, such as time and space. Efficient algorithms contribute to faster execution
and reduced computational costs.
• Automation: Algorithms form the foundation of automation in various domains, from simple tasks to complex processes. They enable
machines and systems to perform tasks without human intervention.
• Decision Making: Algorithms are used in decision-making processes, helping systems and machines make choices based on predefined rules
and criteria.
• Data Processing: In data science and computer science, algorithms are essential for processing and analyzing large datasets. Sorting,
searching, and filtering algorithms are commonly used in data manipulation.
• Optimization: Algorithms are employed to find optimal solutions to problems, whether in resource allocation, route planning, or network
optimization.
• Cryptography: Secure communication relies on algorithms for encryption and decryption. Cryptographic algorithms ensure the
confidentiality and integrity of data.
• Artificial Intelligence: Many AI techniques, such as machine learning algorithms, rely on efficient algorithms to process and learn from data,
make predictions, and automate decision-making.
• Computer Programming: Algorithms are the building blocks of computer programs. Programmers use algorithms to design and implement
software solutions for a wide range of applications.
• Scientific Research: Algorithms play a crucial role in various scientific simulations, modeling, and analyses. They help researchers process
and interpret data in fields such as physics, biology, and chemistry.
Dr. Venkata Phanikrishna B, SCOPE, VIT-Vellore
Types of Algorithms
Algorithm is a finite set of instructions that is
followed, accomplishes a particular task.

Algorithm

Recursion Iteration
Recursive algorithms int fact(int i){
if(i<=1){ return 1; }
return i*fact(i-1);
}

• A recursive algorithm is an algorithm which calls itself.


• A recursive algorithm calls itself which usually passes the return value
as a parameter to the algorithm again. This parameter is the input while
the return value is the output.
• Recursive algorithm is a method of simplification that divides the
problem into sub-problems of the same nature.
Advantages of Recursion
• The code/structure is easier to write and understand.
• Stacks evolutions and infix, prefix, postfix evaluations etc.
• Some problems are inherently recursive, such as Graph and Tree Traversal.

Disadvantages of recursion
• Recursive functions are generally slower than non-recursive function.
• It may require a lot of memory space to hold intermediate results on the system
stacks.
• It is not more efficient in terms of space and time complexity.
• The computer may run out of memory if the recursive calls are not properly
checked.
Algorithm

Recursion Iteration

Property Recursion Iteration


A set of instructions repeatedly
Definition Algorithm calls itself.
executed.
Application (implementation) For functions. For loops.
Through base case, where there When the termination condition
Termination will be no function (algorithm) for the iterator ceases to be
call. satisfied.
Used when algorithm size needs Used when time complexity needs
Usage to be small, and time complexity to be balanced against an
is not an issue. expanded code size.
Relatively lower time complexity
Very high(generally exponential)
Time Complexity (generally polynomial-
time complexity.
logarithmic).
Comparing of both procedures (iterative and recursion) for the
Fibonacci series problem

Fibonacci Series: Iterative way


Fibonacci Series: recursive way
Advantages of Recursion
• The code/structure is easier to write and understand.
• Stacks evolutions and infix, prefix, postfix evaluations etc.
• Some problems are inherently recursive, such as Graph and Tree Traversal.

Disadvantages of recursion
• Recursive functions are generally slower than non-recursive function.
• It may require a lot of memory space to hold intermediate results on the system
stacks.
• It is not more efficient in terms of space and time complexity.
• The computer may run out of memory if the recursive calls are not properly
checked.
Dr. Venkata Phanikrishna B, SCOPE, VIT-Vellore

You might also like