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

lec1 (4)

Uploaded by

diablovanced
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

lec1 (4)

Uploaded by

diablovanced
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

Algorithm Design and Analysis

(ADA-SEC A)
CSE222

6 1 2025
Administrivia
Lectures : 3:00 – 4:20 pm
Monday and Wednesday

Tuts : Tuesday (Groups will be announced soon)


Instructor Team
Lectures : Syamantak Das

Office Hour: Wednesday 1-2pm


By appointment

Email : syamantak@.....
Instructor Team
TF : Renu (renu@..)

TAs: (Final list yet to be announced)


Query Addressing Flowchart

Your friend  TA  Renu  Me (strictly office hours)

Lecture Doubts : Best to clarify during the lecture /


immediately after
Webpage
Other Platform
Google Classroom: Mostly for evaluation/grading and Announcements


sstpxso
Evaluation
Tutorial Quizzes : (Best 8 x 2.5%) 20%

In-class Quizzes : (Best 3 x 10%) 50%


Mr 30

Mid-sem : 25%

End-sem : 25%
Evaluation
Tutorial Quizzes :
• Tutorial Sheets will be uploaded 5 days in advance

• Quiz will comprise of one non-starred question from the


sheet

• Quiz will typically happen 15-20 mins in to the tutorial hour


Anti-Plagiarism Policy

Applies equally to all Graded Components:

Zero-tolerance policy here. If I think you have adopted unfair means, I will
report without any conversation. Feel free to challenge through DAC !
Decorum
Check webpage for proper email etiquette

No frivolous questions/comments in class/tutorials. I


occasionally prefer light-hearted comments, but please
judge it well before posting

No laptop + Phone.You will be asked to leave the


classroom as soon as you are found using one
What is an Algorithm ?

Input ALGORITHM Output


What is an Algorithm ?

Input ALGORITHM Output

Essentially a ‘recipe’ to solve


computational problem
Examples

Compute Shortest Paths

Predict Stock Market

Schedule Tasks
One Algorithm – Many killer Apps

I still like this icon


more, sorry Elon ;)
One Algorithm – Many killer Apps
Why should YOU care ?

Shows up in some form in ALL branches of computer science


• Networks : Shortest paths, spanning trees etc

• Cryptography : Number theoretic algorithms

• Graphics : Geometric algorithms

• Databases : Fast data-structures for searching

• Machine Learning (just because lecture is complete without mentioning


ML these days ;) : Algorithms for continuous optimization
How would this course Help me ?
Make you a better programmer

Improve Mathematical and Analytical Skills (course is theoretical)

Prepare you to ace interviews

Become familiar with some of the ‘Greatest Hits’ in CS

Motivate you to do research in ‘Theory of Algorithms’

Have fun !
Multiplying Large Integers I

𝑎 𝑎 𝑎 ⋯⋯𝑎
𝑏 𝑏 𝑏 ⋯⋯𝑏
-------------------

Input : Two n-digit numbers A and B


Output : Product A x B
Basic Operations : Multiply / Add two Single-Digit Integers
Multiplying Large Integers
3
5 6 7 8
X1 2 3 4
---------------
3n operations
22712
17034 3n 3m
3m
11 3 56 3r
6m
Mantra of an Algorithmist : Can we do BETTER ?
Mantra of an Algorithmist : Can we do differently ?

a 5 6 7 8b

X1 2 3 4
c d
Mantra of an Algorithmist : Can we do differently ?

Step 1 : Compute a.c = 672


a 5 6 7 8b

X1 2 3 4
c d
Mantra of an Algorithmist : Can we do differently ?

Step 1 : Compute a.c = 672


a 5 6 7 8b
Step II : Compute b.d = 2652
X1 2 3 4
c d
Mantra of an Algorithmist : Can we do differently ?

Step 1 : Compute a.c = 672 a 5 6 7 8b


Step II : Compute b.d = 2652
X1 2 3 4
Step III : Compute (a+b)(c+d)
c d
= 134 x 46 = 6164
Mantra of an Algorithmist : Can we do differently ?

Step 1 : Compute a.c = 672


a 5 6 7 8b
Step II : Compute b.d = 2652
X1 2 3 4
Step III : Compute (a+b)(c+d)
= 134 x 46 = 6164
c d

Step IV : Compute III – II – I = 2840 6720000


284000
Step V :
700
Mantra of an Algorithmist : Can we do differently ?
Step 1 : Compute a.c = 672
a 5 6 7 8b
Step II : Compute b.d = 2652

Step III : Compute (a+b)(c+d) X1 2 3 4


= 134 x 46 = 6164 c d
Step IV : Compute III – II – I = 2840

Step V : 6720000 + 284000 + 2652 = 7006652

Message : The space of algorithm design is richer than you thought


A Recursive Algorithm

An algorithm that invokes itself again on again on smaller


and smaller inputs until it can compute using only basic
operations (base cases)
A Recursive Algorithm

An algorithm that invokes itself again on again on smaller


and smaller inputs until it can compute using only basic
operations (base cases)

Easier way to ‘think’ recursively :


Suppose ‘recursion oracle’ gives me solutions to
problems of smaller sizes ; then can I build a solution to
the main problem ?
A Recursive Algorithm for Multiplication
A 99,92 An
Write 𝐴 = 10 ⋅ 𝑎 + 𝑏 , 𝐵 = 10 ⋅ 𝑐 + 𝑑
𝑎, 𝑏 , 𝑐, 𝑑 are n/2-digit integers B bobiba br
Then, 𝐴 × 𝐵 = 10 𝑎𝑐 + 10 𝑎𝑑 + 𝑏𝑐 + 𝑏𝑑
A Recursive Algorithm for Multiplication

Write 𝐴 = 10 ⋅ 𝑎 + 𝑏 , 𝐵 = 10 ⋅ 𝑐 + 𝑑
𝑎, 𝑏 , 𝑐, 𝑑 are n/2-digit integers

Then, 𝐴 × 𝐵 = 10 𝑎𝑐 + 10 𝑎𝑑 + 𝑏𝑐 + 𝑏𝑑

Step 1 : Recursively compute 𝑎 ⋅ 𝑐


A Recursive Algorithm for Multiplication

Write 𝐴 = 10 ⋅ 𝑎 + 𝑏 , 𝐵 = 10 ⋅ 𝑐 + 𝑑
𝑎, 𝑏 , 𝑐, 𝑑 are n/2-digit integers

Then, 𝐴 × 𝐵 = 10 𝑎𝑐 + 10 𝑎𝑑 + 𝑏𝑐 + 𝑏𝑑

Step 1 : Recursively compute 𝑎 ⋅ 𝑐


Step 1I : Recursively compute 𝑎 ⋅ 𝑑
A Recursive Algorithm for Multiplication

Write 𝐴 = 10 ⋅ 𝑎 + 𝑏 , 𝐵 = 10 ⋅ 𝑐 + 𝑑
𝑎, 𝑏 , 𝑐, 𝑑 are n/2-digit integers

Then, 𝐴 × 𝐵 = 10 𝑎𝑐 + 10 𝑎𝑑 + 𝑏𝑐 + 𝑏𝑑

Step 1 : Recursively compute 𝑎 ⋅ 𝑐


Step 1I : Recursively compute 𝑎 ⋅ 𝑑
Step III : Recursively compute 𝑏 ⋅ 𝑐
A Recursive Algorithm for Multiplication

Write 𝐴 = 10 ⋅ 𝑎 + 𝑏 , 𝐵 = 10 ⋅ 𝑐 + 𝑑
𝑎, 𝑏 , 𝑐, 𝑑 are n/2-digit integers

Then, 𝐴 × 𝐵 = 10 𝑎𝑐 + 10 𝑎𝑑 + 𝑏𝑐 + 𝑏𝑑

Step 1 : Recursively compute 𝑎 ⋅ 𝑐


Step 1I : Recursively compute 𝑎 ⋅ 𝑑
Step III : Recursively compute 𝑏 ⋅ 𝑐
Step 1V : Recursively compute 𝑏 ⋅ 𝑑
A Recursive Algorithm for Multiplication

Write 𝐴 = 10 ⋅ 𝑎 + 𝑏 , 𝐵 = 10 ⋅ 𝑐 + 𝑑
𝑎, 𝑏 , 𝑐, 𝑑 are n/2-digit integers

Then, 𝐴 × 𝐵 = 10 𝑎𝑐 + 10 𝑎𝑑 + 𝑏𝑐 + 𝑏𝑑

Step 1 : Recursively compute 𝑎 ⋅ 𝑐


Step 1I : Recursively compute 𝑎 ⋅ 𝑑
Step III : Recursively compute 𝑏 ⋅ 𝑐
Step 1V : Recursively compute 𝑏 ⋅ 𝑑
Step V : Combine the answers to get 𝐴 × 𝐵
Yet Another Recursive Algorithm

𝐴 = 10 ⋅ 𝑎 + 𝑏 , 𝐵 = 10 ⋅ 𝑐 + 𝑑
𝐴 × 𝐵 = 10 𝑎𝑐 + 10 𝑎𝑑 + 𝑏𝑐 + 𝑏𝑑
Yet Another Recursive Algorithm

𝐴 = 10 ⋅ 𝑎 + 𝑏 , 𝐵 = 10 ⋅ 𝑐 + 𝑑
𝐴 × 𝐵 = 10 𝑎𝑐 + 10 𝑎𝑑 + 𝑏𝑐 + 𝑏𝑑

Step 1 : Recursively Compute 𝑎 ⋅ 𝑐


Yet Another Recursive Algorithm

𝐴 = 10 ⋅ 𝑎 + 𝑏 , 𝐵 = 10 ⋅ 𝑐 + 𝑑
𝐴 × 𝐵 = 10 𝑎𝑐 + 10 𝑎𝑑 + 𝑏𝑐 + 𝑏𝑑

Step 1 : Recursively Compute 𝑎 ⋅ 𝑐

Step II : Recursively Compute 𝑏 ⋅ 𝑑


Yet Another Recursive Algorithm

𝐴 = 10 ⋅ 𝑎 + 𝑏 , 𝐵 = 10 ⋅ 𝑐 + 𝑑
𝐴 × 𝐵 = 10 𝑎𝑐 + 10 𝑎𝑑 + 𝑏𝑐 + 𝑏𝑑

Step 1 : Recursively Compute 𝑎 ⋅ 𝑐

Step II : Recursively Compute 𝑏 ⋅ 𝑑


mm mⁿM
Step III : Recursively Compute (𝑎 + 𝑏) ⋅ (𝑐 + 𝑑)
Yet Another Recursive Algorithm

𝐴 = 10 ⋅ 𝑎 + 𝑏 , 𝐵 = 10 ⋅ 𝑐 + 𝑑
𝐴 × 𝐵 = 10 𝑎𝑐 + 10 𝑎𝑑 + 𝑏𝑐 + 𝑏𝑑

Step 1 : Recursively Compute 𝑎 ⋅ 𝑐

Step II : Recursively Compute 𝑏 ⋅ 𝑑

Step III : Recursively Compute (𝑎 + 𝑏) ⋅ (𝑐 + 𝑑)

Step IV : Compute III – II – I = (𝑎𝑑 + 𝑏𝑐) (Gauss’ Trick)


of
Yet Another Recursive Algorithm

𝐴 = 10 ⋅ 𝑎 + 𝑏 , 𝐵 = 10 ⋅ 𝑐 + 𝑑
𝐴 × 𝐵 = 10 𝑎𝑐 + 10 𝑎𝑑 + 𝑏𝑐 + 𝑏𝑑

Step 1 : Recursively Compute 𝑎 ⋅ 𝑐

Step II : Recursively Compute 𝑏 ⋅ 𝑑

Step III : Recursively Compute (𝑎 + 𝑏) ⋅ (𝑐 + 𝑑)

Step IV : Compute III – II – I = (𝑎𝑑 + 𝑏𝑐) (Gauss’ Trick)


Yet Another Recursive Algorithm

𝐴 = 10 ⋅ 𝑎 + 𝑏 , 𝐵 = 10 ⋅ 𝑐 + 𝑑
𝐴 × 𝐵 = 10 𝑎𝑐 + 10 𝑎𝑑 + 𝑏𝑐 + 𝑏𝑑

Step 1 : Recursively Compute 𝑎 ⋅ 𝑐


Karatsuba
Step II : Recursively Compute 𝑏 ⋅ 𝑑 Multiplication
Step III : Recursively Compute (𝑎 + 𝑏) ⋅ (𝑐 + 𝑑)

Step IV : Compute III – II – I = (𝑎𝑑 + 𝑏𝑐) (Gauss’ Trick)


Yet Another Recursive Algorithm

𝐴 = 10 ⋅ 𝑎 + 𝑏 , 𝐵 = 10 ⋅ 𝑐 + 𝑑
𝐴 × 𝐵 = 10 𝑎𝑐 + 10 𝑎𝑑 + 𝑏𝑐 + 𝑏𝑑

Step 1 : Recursively Compute 𝑎 ⋅ 𝑐 Are these really better than


the 3rd grader algorithm ?
Step II : Recursively Compute 𝑏 ⋅ 𝑑

Step III : Recursively Compute (𝑎 + 𝑏) ⋅ (𝑐 + 𝑑)

Step IV : Compute III – II – I = (𝑎𝑑 + 𝑏𝑐) (Gauss’ Trick)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy