You are on page 1of 17

06/08/2023 Prepared by Sadaf Riaz 1

Design and Analysis of Algorithms

Lecture 1
Instructor : Sadaf Riaz

Class: CS 6th A & B

Credit Hours: (3+0)


06/08/2023 Prepared by Sadaf Riaz 2
Instructor Name: Sadaf Riaz
 
Semester: Sixth
 
Course Title: Design & Analysis of Algorithm
 
Course Code: CS-424
 
Credit Hours: 3+0
 

Pre - Requisite Data Structure and Algorithms

Instructor Office: 17
 
Email ID: bscs6thb@gmail.com
 

06/08/2023 Prepared by Sadaf Riaz 3


Recommended Book:

Introduction to Algorithms, Cormen,


Leiserson, Rivest, and Stein, 2nd/3rd
Edition

06/08/2023 Prepared by Sadaf Riaz 4


Course Objectives

Upon completion of this course, students will be able


to do the following:
 Analyze the asymptotic performance of algorithms.
 Write rigorous correctness proofs for algorithms.
 Demonstrate a familiarity with major algorithms
and data structures.
 Apply important algorithmic design paradigms and
methods of analysis.

06/08/2023 Prepared by Sadaf Riaz 5


Learning Outcomes:

 Understand numerous examples of relationships between


data
 Understand the purpose and mathematical background of
algorithm analysis and be able to apply this to determine
the run time and memory usage of algorithms
 Understand the design approaches of algorithms including
greedy, divide-and-conquer, dynamic programming, linear
programing etc.
 Understand various sorting algorithms and the run-time
analysis required to determine their efficiencies
 Understand various graph algorithms and their
applications.
 Understand the concept of NP Hard and NP Complete
Problems
06/08/2023 Prepared by Sadaf Riaz 6
What is Algorithm?
 A finite set of instruction that specifies a sequence of
operation is to be carried out in order to solve a specific
problem or class of problems is called 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.
 Solution of a particular problem in a very simple and
efficient way
06/08/2023 Prepared by Sadaf Riaz 7
Algorithm Design

 Creating an efficient algorithm to solve a problem


in an efficient way using minimum time and
space.
 Different approaches can be used based on the
efficient time or memory consumption
 Both time consumption and memory usage cannot
be optimized simultaneously.
lesser time, we have to invest in more memory
lesser memory, we need to have more time.
06/08/2023 Prepared by Sadaf Riaz 8
Problem Development Steps

 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
06/08/2023 Prepared by Sadaf Riaz 9
C ha rac ter is ti cs o f A lgo rit hm s

 Correctness: It should produce the output according to the requirement of


the algorithm
 Finiteness: Algorithm must complete after a finite number of instructions
have been executed.
 An Absence of Ambiguity: Each step must be defined, having only one
interpretation.
 Definition of Sequence: Each step must have a unique defined preceding
and succeeding step. The first step and the last step must be noted.
 Input/output: Number and classification of needed inputs and results must
be stated.
 Feasibility: It must be feasible to execute each instruction.
 Flexibility: It should also be possible to make changes in the algorithm
without putting so much effort on it.
 Efficient : Measurement in terms of time and space requires to implement
the algorithm.(less time &space)
06/08/2023 Prepared by Sadaf Riaz 10
Difference between Algorithm and Pseudocode

An algorithm is a formal Pseudocode is an informal


definition with some specific and human readable
characteristics that describes a description of an algorithm
process, which could be leaving many granular details
executed by a Turing- of it. Writing a pseudocode
complete computer machine has no restriction of styles and
to perform a specific task. its only objective is to
Generally, the word describe the high level steps of
"algorithm" can be used to algorithm in a much realistic
describe any high level task manner in natural language.
in computer science.
06/08/2023 Prepared by Sadaf Riaz 11
Difference between Algorithm and Pseudocode

Algorithm: Insertion-Sort Pseudocode: Insertion-Sort


Input: A list L of integers of
length n
Output: A sorted list L1 for i <- 1 to length(A)
containing those integers x <- A[i]
present in L j <- i
Step 1: Keep a sorted list L1
while j > 0 and A[j-1] > x
which starts off empty
Step 2: Perform Step 3 for each A[j] <- A[j-1]
element in the original list L j <- j - 1
Step 3: Insert it into the correct A[j] <- x
position in the sorted list L1.
Step 4: Return the sorted list
Step 5: Stop
06/08/2023 Prepared by Sadaf Riaz 12
Algorithm vs Program:

 Design Phase produces an algorithm, and the


implementation phase then generates a program that
expresses the designed algorithm.
 So, the existing expression of an algorithm in a particular
programming language is called a program.

06/08/2023 Prepared by Sadaf Riaz 13


Complexity Analysis of Algorithm

1) Time Complexity: Running time/efficiency of an


algorithm is stated as a function relating the input
length to the number of steps.
2) Space Complexity: Some forms of analysis could be
done based on how much space an algorithm needs
to complete its task. This space complexity analysis
was critical in the early days of computing when
storage space on the computer was limited. But, now
a day's problem of space rarely occurs because space
on the computer (internal or external) is enough
06/08/2023 Prepared by Sadaf Riaz 14
The Need for Analysis

 One computational problem can be solved by different


algorithms.( bubble sort, insertion sort, merge sort….)
 Algorithms are often quite different from one another,
though the objective of these algorithms are the same
 Number of comparisons performed by one algorithm
may vary with others for the same input.
 Time complexity/performance of those algorithms
may differ.
 Bubble sort does not require additional memory, but
merge sort requires additional space. But the time
complexity of bubble sort is higher compared to merge
06/08/2023
sort Prepared by Sadaf Riaz 15
Types of Analysis

 Worst-case: The maximum number of steps


taken on any instance of size n.
 Best-case: The minimum number of steps
taken on any instance of size n.
 Average case: An average number of steps
taken on any instance of size n.
 Amortized: A sequence of operations applied
to the input of size n averaged over time.

06/08/2023 Prepared by Sadaf Riaz 16


06/08/2023 Prepared by Sadaf Riaz 17

You might also like