Design and Analysisof Algorithms
Lecture 1
• Overview of the course
• Motivational Problems
1
CS345
moodle.cse.iitk.ac.in Login as guest
CS345-2025-2026-I
2.
Aim of thecourse
To empower each student with the skills to design algorithms
1. With provable guarantee on correctness.
2. With provable guarantee on efficiency.
2
3.
How CSE ismaking our lives better ?
3
Operating System
Computer Networks
Important role: Little role:
Algorithms
Database
4.
The world ofAlgorithms
Algorithms having
4
Efficiency
non-trivial design
non-trivial analysis
5.
The world ofAlgorithms
Algorithms having
5
Efficiency
non-trivial design
non-trivial analysis Real World
Applications
7
Impact of anAlgorithm
Future of thousands of students in India
on
8.
Technical Institutes inIndia
8
IITs
NITs IIITs GFTIs
BITS PILANI
DCE
ANNA University
JEE Advanced
JEE Main
Entrance Exam
CSAB institutes
9.
A closer lookat the problem
9
Allocation in
IITs
IITK Civil
IITM Metallurgy
NIT Surat Mechanical
NIT Warangal CSE
Ram
Mohan
JEE Advanced JEE
(Mains)
Allocation in
CSAB Institutes
10.
JEE
(Mains)
Allocation in
CSAB Institutes
Acloser look at the problem
10
IITK Civil
IITM Metallurgy
NIT Surat Mechanical
NIT Warangal CSE
Allocation in
IITs
JEE Advanced
Ram
Mohan
11.
JEE
(Mains)
Allocation in
CSAB Institutes
Acloser look at the problem
11
IITK Civil
IITM Metallurgy
NIT Surat Mechanical
NIT Warangal CSE
Shyam
SPOT round
Allocation in
IITs
JEE Advanced
Ram
Mohan
12.
JEE
(Mains)
Allocation in
CSAB Institutes
Acloser look at the problem
12
IITK Civil
IITM Metallurgy
NIT Surat Mechanical
NIT Warangal CSE
Shyam
SPOT round
Allocation in
IITs
JEE Advanced
Ram
Mohan
Homework
1. The seatallocation algorithm for the single merit list?
2. Can you now tackle the problem of multiple merit lists ?
15
16.
Time complexity ofan algorithm
Definition:
the worst case number of instructions executed
as a function of the input size
Examples to illustrate input size :
16
The number of bits/bytes/words
Problem Input size
Computing F()mod for any positive integers
Whether an array storing numbers (each stored in a word) is sorted ?
Whether a matrix of numbers (each stored in a word) contains “14” ?
bits
words
words
(or a parameter defining the input size)
17.
Time complexity ofan algorithm
Definition:
the worst case number of instructions executed
as a function of the input size
Question: What is a polynomial time algorithm ?
Answer: Algorithm whose time complexity is a polynomial of input size.
17
(or a parameter defining the input size)
An algorithm is considered efficient if it is a polynomial time algorithm. But why?
The next slide should convince you .
Primality Testing
Problem definition:Given an integer , determine if it is prime.
Primality_test()
{ ;
Flag True;
While( and Flag) do
{ If ( divides ) Flag False;
;
}
return Flag;
}
Question: What is the time complexity of Primality_test() ?
size of = log
Time complexity of the fastest algorithm at present
19
𝑶(𝒏)
≤ √𝒏
𝑶(√𝒏)
log Time taken
𝟐𝟎𝟎𝟎
𝟔𝟒
years
seconds
𝑶((𝐥𝐨𝐠𝟐
𝒏))
Such large numbers are
Routinely used in Cryptography
20.
In the restof the lecture,
we shall discuss 3 problems which we shall solve in this course.
20
Stable Marriage Problem
•prefers to
• prefers to
Definition:
A marriage is said to be stable if there is no unstable pair in the society.
25
𝑤𝑙
𝑤𝑖
𝑚𝑘
𝑚𝑗
divorce
divorce
(, ) : an unstable pair
Meaning of unstability
26.
Stable Marriage Problem
•: set of men
• : set of women
For each man ,
: a preference list of all women
For each woman ,
: a preference list of all men
Aim: To compute a stable marriage.
26
Unique-path graph
Definition: Adirected graph =(, ) is said to be unique-path graph if
For each pair , , there is at most one path from to .
In other words,
Aim: Design an efficient algorithm to determine if is unique-path graph.
there is only one path from to
An O( time algorithm
u
v
w
t k
q
p
j
r
y
b
h
d
c
#9 Let us take a close look at the problem. Suppose there are two candidates Ram and Mohan. Both study hard for JEE(Mains) and JEE(Advanced). It turns out that Ram outperforms Mohan in JEE Advanced
Ram prefers NIT Warangal Electrical.
Mohan prefers IITK Civil.
Unfortunately both these seats remain vacant and none of them get their desired programs.
#10 Shyam gets NIT Warangal Electrical though his rank is inferior to that of Ram.
The reason: On the date of spot round at NIT Warangal, Ram is unable to come physically to NIT Warangal but Shyam does.
#11 Shyam gets NIT Warangal Electrical though his rank is inferior to that of Ram.
The reason: On the date of spot round at NIT Warangal, Ram is unable to come physically to NIT Warangal but Shyam does.
#12 Shyam gets NIT Warangal Electrical though his rank is inferior to that of Ram.
The reason: On the date of spot round at NIT Warangal, Ram is unable to come physically to NIT Warangal but Shyam does.