0% found this document useful (0 votes)
4 views

Lecture 1 Design and Analysis of Algorithms

The document outlines the basics of algorithms, including their definition, design, and analysis methodologies. It emphasizes the importance of algorithm characteristics such as correctness and resource efficiency, and introduces pseudocode as a tool for algorithm representation. Additionally, it discusses the types of algorithm analysis, including best, worst, and average cases, and provides an overview of upcoming topics related to design strategies.

Uploaded by

n0236685b
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lecture 1 Design and Analysis of Algorithms

The document outlines the basics of algorithms, including their definition, design, and analysis methodologies. It emphasizes the importance of algorithm characteristics such as correctness and resource efficiency, and introduces pseudocode as a tool for algorithm representation. Additionally, it discusses the types of algorithm analysis, including best, worst, and average cases, and provides an overview of upcoming topics related to design strategies.

Uploaded by

n0236685b
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Design and Analysis of

Algorithms
Lecture 1
Lecture Outline
• Basics of Algorithms
• Introduction
• Analysis of Algorithms
• Methodology of Analysis
• Asymptotic Notations & Apriori Analysis
• Space Complexities
What is an algorithm?
• An algorithm is a set of steps of operations to solve a problem performing
calculation, data processing, and automated reasoning tasks.
• An algorithm is an efficient method that can be expressed within finite amount of
time and space.
• A sequence of steps to solve a given problem is called as algorithm. Thus, an
algorithm is a step-by-step procedure developed for solving a given problem. An
algorithm consists of sequences, iterations, selections, etc. The selection of an
algorithm depends upon the nature of the given problem. Thus, the problem is first
analyzed, and then the best algorithm is used to solve it.
• An algorithm follows a systematic and a logical approach, where the procedure is
defined step-wise. In an algorithm, many simple operations are combined to help
form a more complicated operation, which is performed with ease by the computer.
Algorithm Design
• The important aspects of algorithm design include creating an
efficient algorithm to solve a problem in an efficient way using
minimum time and space.
Problem Development Steps
• The following steps are involved in solving computational problems.
• Problem definition
• Development of a model
• Specification of an Algorithm
• Designing an Algorithm
• Checking the correctness of an Algorithm
• Analysis of an Algorithm
• Implementation of an Algorithm
• Program testing
• Documentation
Characteristics of Algorithms
• The main characteristics of algorithms are as follows −
• Algorithms must have a unique name
• Algorithms should have explicitly defined set of inputs and outputs (must take
an input and give out an output)
• Algorithms are well-ordered with unambiguous operations (each instruction
is clear and unambiguous)
• Algorithms halt in a finite amount of time. Algorithms should not run for
infinity, i.e., an algorithm must end at some point
Expectation from an algorithm
• Correctness: Algorithms must produce correct result.
• Less resource usage: Algorithms should use less resources (time and
space)
Pseudocode
• Pseudocode gives a high-level description of an algorithm without the
ambiguity associated with plain text but also without the need to know the
syntax of a particular programming language.
• Pseudocode is an informal method of developing an algorithm. Thus,
computer programmers use simple informal language to write a pseudocode.
It does not have any specific syntax to follow. The pseudocode is a text based
design tool. Basically, pseudocode represents an algorithm to solve a problem
in natural language and mathematical notations.
• Pseudocodes are written in plain English, and they use short phrases to
represent the functionalities that the specific lines of code would do. Since
there is no strict syntax to follow in pseudocode writing, they are relatively
difficult to debug.
Difference between Algorithm and
Pseudocode
• Pseudocode of linear search :
1. Start from the leftmost element of arr[] and one by one compare x
with each element of arr[].
2. If x matches with an element, return the index.
3. If x doesn’t match with any of elements, return -1.
• Here, we can see how the steps of a linear search program are
explained in a simple, English language.
• Algorithm for Linear Search :

FUNCTION linearSearch(list, searchTerm):


FOR index FROM 0 -> length(list):
IF list[index] == searchTerm THEN
RETURN index
ENDIF
ENDLOOP
RETURN -1
END FUNCTION
Analysis of Algorithms
• Algorithm analysis is an important part of computational complexity
theory, which provides theoretical estimation for the required
resources of an algorithm to solve a specific computational problem.
• Analysis of algorithms is the determination of the amount of time and
space resources required to execute it.
Why analyse algorithms
• To predict the behavior of an algorithm without implementing it on a
specific computer.
• It is much more convenient to have simple measures for the efficiency of an
algorithm than to implement the algorithm and test the efficiency every
time a certain parameter in the underlying computer system changes.
• It is impossible to predict the exact behavior of an algorithm. There are too
many influencing factors.
• The analysis is thus only an approximation; it is not perfect.
• More importantly, by analyzing different algorithms, we can compare them
to determine the best one for our purpose.
Types of Algorithm Analysis
• Best case: Define the input for which algorithm takes less time or minimum time.
In the best case calculate the lower bound of an algorithm. Example: In the linear
search when search data is present at the first location of large data then the best
case occurs.
• Worst Case: Define the input for which algorithm takes a long time or maximum
time. In the worst calculate the upper bound of an algorithm. Example: In the
linear search when search data is not present at all then the worst case occurs.
• Average case: In the average case take all random inputs and calculate the
computation time for all inputs.
And then we divide it by the total number of inputs.
• Amortized − A sequence of operations applied to the input of size a averaged over
time.
Read and make notes
• Methodology of analysis
• Space complexity
Watch
• https://youtu.be/FWUV4CGd6DU

• https://youtu.be/-gN6KCS_D4k

• https://youtu.be/VannOh-15WM
Assignment
• Write notes on the Big-O notation
NEXT LECTURE: DESIGN
STRATEGIES
Task 1: Design Strategies Group
Presentations
Divide & Conquer
1. Max-Min Problem
2. Merge Sort
3. Binary Search
4. Strassen’s Matrix Multiplication
5. Greedy Method
6. Knapsack
7. Job Sequencing with Deadline
8. Optimal Merge Pattern
9. Dynamic Programming
10. Longest Common Subsequence

You might also like