Lecture 1 Design and Analysis of Algorithms
Lecture 1 Design and Analysis of Algorithms
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 :
• 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