3-Overview of Course Introduction To Algorithms-03-01-2024
3-Overview of Course Introduction To Algorithms-03-01-2024
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.
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
nr
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);
}
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
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