Design and Analysis of Algorithms
Lecture 1
• Overview of the course
• Motivational Problems
1
CS345
moodle.cse.iitk.ac.in Login as guest
CS345-2025-2026-I
Aim of the course
To empower each student with the skills to design algorithms
1. With provable guarantee on correctness.
2. With provable guarantee on efficiency.
2
How CSE is making our lives better ?
3
 Operating System
 Computer Networks
Important role: Little role:
 Algorithms
 Database
The world of Algorithms
Algorithms having
4
Efficiency
non-trivial design
non-trivial analysis
The world of Algorithms
Algorithms having
5
Efficiency
non-trivial design
non-trivial analysis Real World
Applications
Real world problem 1
6
7
Impact of an Algorithm
Future of thousands of students in India
on
Technical Institutes in India
8
IITs
NITs IIITs GFTIs
BITS PILANI
DCE
ANNA University
JEE Advanced
JEE Main
Entrance Exam
CSAB institutes
A closer look at 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
JEE
(Mains)
Allocation in
CSAB Institutes
A closer look at the problem
10
IITK Civil
IITM Metallurgy
NIT Surat Mechanical
NIT Warangal CSE
Allocation in
IITs
JEE Advanced
Ram
Mohan
JEE
(Mains)
Allocation in
CSAB Institutes
A closer 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
JEE
(Mains)
Allocation in
CSAB Institutes
A closer 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
13
Multiple Merit Lists
19 IITs
31 NITs
18 IIITs
18 OtherGFTIs
33989 seats 1304127 candidates
Fairness
14
Merit list
q
p q p
Ram
Mohan
Choice list of Mohan
of programme q
Ram Mohan
Homework
1. The seat allocation algorithm for the single merit list?
2. Can you now tackle the problem of multiple merit lists ?
15
Time complexity of an 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)
Time complexity of an 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 .
Real world problem 2
18
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
In the rest of the lecture,
we shall discuss 3 problems which we shall solve in this course.
20
Problem 1
The Stable Marriage Problem
21
Stable Marriage Problem
22
Women Men
𝑤1
𝑤2
𝑤3
𝑤𝑛
𝑤𝑖
𝑚1
𝑚2
𝑚3
𝑚𝑗
𝑚𝑛
1
2
3
…
…..
Stable Marriage Problem
23
Women Men
𝑤1
𝑤2
𝑤3
𝑤𝑛
𝑤𝑖
𝑚1
𝑚2
𝑚3
𝑚𝑗
𝑚𝑛
2
3
1
…
…..
…
𝑘
Stable Marriage Problem
24
Women Men
𝑤1
𝑤2
𝑤3
𝑤𝑛
𝑤𝑖
𝑚1
𝑚2
𝑚3
𝑚𝑗
𝑚𝑛
Marriage : ?
…
…
…
…
a bijection between Women and Men
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
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
Problem 2
The Unique-path Problem
27
Unique-path graph
Definition: A directed 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
Problem 3
A Physics Problem
29
…
: Force exerted on
Aim: Compute for all
30
1 1 1
𝑘𝑞1 𝑞 𝑗
( 𝑗 −1)2
…+
𝑘 𝑞𝑗 −1 𝑞 𝑗
(1)2
+𝑘𝑞2 𝑞 𝑗
( 𝑗 −2)2
−
𝑘𝑞 𝑗+1 𝑞 𝑗
(1)2
…−
𝑘𝑞𝑛−1 𝑞𝑗
(𝑛−1 − 𝑗 )2
−
𝑘 𝑞𝑛 𝑞 𝑗
(𝑛 − 𝑗 )2
𝐹 𝑗=¿
time
in time.
Homework
Spend sometime during the weekend pondering over these problems.
I hope these problems will inspire you … 
31

Lecture 1-Overview.pptxLecture 1-Overview.pptxLecture 1-Overview.pptx

  • 1.
    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
  • 6.
  • 7.
    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
  • 13.
    13 Multiple Merit Lists 19IITs 31 NITs 18 IIITs 18 OtherGFTIs 33989 seats 1304127 candidates
  • 14.
    Fairness 14 Merit list q p qp Ram Mohan Choice list of Mohan of programme q Ram Mohan
  • 15.
    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 .
  • 18.
  • 19.
    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
  • 21.
    Problem 1 The StableMarriage Problem 21
  • 22.
    Stable Marriage Problem 22 WomenMen 𝑤1 𝑤2 𝑤3 𝑤𝑛 𝑤𝑖 𝑚1 𝑚2 𝑚3 𝑚𝑗 𝑚𝑛 1 2 3 … …..
  • 23.
    Stable Marriage Problem 23 WomenMen 𝑤1 𝑤2 𝑤3 𝑤𝑛 𝑤𝑖 𝑚1 𝑚2 𝑚3 𝑚𝑗 𝑚𝑛 2 3 1 … ….. … 𝑘
  • 24.
    Stable Marriage Problem 24 WomenMen 𝑤1 𝑤2 𝑤3 𝑤𝑛 𝑤𝑖 𝑚1 𝑚2 𝑚3 𝑚𝑗 𝑚𝑛 Marriage : ? … … … … a bijection between Women and Men
  • 25.
    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
  • 27.
  • 28.
    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
  • 29.
  • 30.
    … : Force exertedon Aim: Compute for all 30 1 1 1 𝑘𝑞1 𝑞 𝑗 ( 𝑗 −1)2 …+ 𝑘 𝑞𝑗 −1 𝑞 𝑗 (1)2 +𝑘𝑞2 𝑞 𝑗 ( 𝑗 −2)2 − 𝑘𝑞 𝑗+1 𝑞 𝑗 (1)2 …− 𝑘𝑞𝑛−1 𝑞𝑗 (𝑛−1 − 𝑗 )2 − 𝑘 𝑞𝑛 𝑞 𝑗 (𝑛 − 𝑗 )2 𝐹 𝑗=¿ time in time.
  • 31.
    Homework Spend sometime duringthe weekend pondering over these problems. I hope these problems will inspire you …  31

Editor's Notes

  • #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.