Download - Lecture 101 Aug 2014 Upload
-
8/10/2019 Lecture 101 Aug 2014 Upload
1/26
QEEE DSA05
DATA STRUCTURES ANDALGORITHMSG VENKATESH AND MADHAVAN MUKUND
LECTURE 1, 1 AUGUST 2014
-
8/10/2019 Lecture 101 Aug 2014 Upload
2/26
Understanding Algorithms
Correctness
E"ciency
Asymptotic complexity, O( ) notation
Modelling
Graphs, data structures, decomposing the problem
Techniques
Divide and conquer, greedy, dynamic programming
-
8/10/2019 Lecture 101 Aug 2014 Upload
3/26
Expectations
Background in programming
Any language (C, C++, Java, Python)
Basic data structures
Arrays, lists
-
8/10/2019 Lecture 101 Aug 2014 Upload
4/26
Topics to be covered
Asymptotic complexity, basic searching and sorting(2 lectures)
Divide and conquer (3 lectures)
Basics of graphs and graph algorithms (4 lectures)
Greedy algorithms (1 lecture)
Trees (1 lecture)
Dynamic Programming (3 lectures)
-
8/10/2019 Lecture 101 Aug 2014 Upload
5/26
Evaluation
Programming assignments (4-5)
Online judge
http://www.iarcs.org.in/qeee-dsa05/index.php
Log in and create an account for yourself
Enter your name and institution accurately!
Quizzes, paper and pen (2)
Objective (multiple choice, unique answer )
http://www.iarcs.org.in/qeee-dsa05/index.php -
8/10/2019 Lecture 101 Aug 2014 Upload
6/26
Example 1: Air travel
Barbet Airlines serves several cities in India
Some cities are connected by direct flights
Want to compute all pairs of cities A,B such that A
and B are connected by a sequence of flights
-
8/10/2019 Lecture 101 Aug 2014 Upload
7/26
-
8/10/2019 Lecture 101 Aug 2014 Upload
8/26
Throw away the map and record the network
This is a grapha collection of nodes and edges
-
8/10/2019 Lecture 101 Aug 2014 Upload
9/26
Can distort the picture without changing meaning
-
8/10/2019 Lecture 101 Aug 2014 Upload
10/26
Can distort the picture without changing meaning
-
8/10/2019 Lecture 101 Aug 2014 Upload
11/26
Connected destinations
Compute pathsin the graph
How do we represent the graph so that we canmanipulate it using a computer program?
Suitable data structure
How do we design an e"cient algorithm for this
data representation?
-
8/10/2019 Lecture 101 Aug 2014 Upload
12/26
Efficiency?
N cities, F direct flights
Computing paths depends on N and F
What is this dependency?
How large a value of N and F can we handle?
Online booking requires response in seconds
-
8/10/2019 Lecture 101 Aug 2014 Upload
13/26
Variations
Flights have arrival and departure times
Only some connections are feasible
Should not have to wait overnight
or more than 4 hours
How to compute feasible pathswith constraints?
-
8/10/2019 Lecture 101 Aug 2014 Upload
14/26
Example 2: Xerox Shop
Campus Xerox has several photocopiers
Tomorrow is the deadline for BTech projects and
there is a rush of reports to be printed
How to schedule the pending jobs most
e$ectively?
-
8/10/2019 Lecture 101 Aug 2014 Upload
15/26
Xerox Shop
The number of pages for each job is known
Each customer has been promised delivery by a
deadline
Campus Xerox o$ers discount if deadline is not
met
How to sequentially allocate the jobs to
photocopiers to maximize revenue?
-
8/10/2019 Lecture 101 Aug 2014 Upload
16/26
Xerox Shop
Brute force
Try all possible allocations
Choose one that is optimum
Number of possibilities is exponential!
Even with 30 jobs, it would take hours to compute
an optimal schedule
-
8/10/2019 Lecture 101 Aug 2014 Upload
17/26
Xerox Shop
Decompose the problem
Choose a job to schedule first, and the machine
on which it will run, according to some strategy
Now, recursively solve the problem for N-1 jobs
-
8/10/2019 Lecture 101 Aug 2014 Upload
18/26
Xerox Shop
Greedy approach
Fix the choice of next job once and for all
Never go back and try another sequence
How to choose the next job?
Shortest processing time?
Earliest deadline?
How to show that this strategy is optimal?
-
8/10/2019 Lecture 101 Aug 2014 Upload
19/26
Variations
Some photocopiers are old and slow, some are
new and fast
Time for a job depends on choice of machine
Cost of ink and paper varies across machines
Net revenue for a job depends on choice of
machine
-
8/10/2019 Lecture 101 Aug 2014 Upload
20/26
Example 3: Document
similarity
Given two documents, how similar are they?
Plagiarism detection
Checking changes between versions of code
Answering web search queries more e$ectively
-
8/10/2019 Lecture 101 Aug 2014 Upload
21/26
Document similarity
What is a good measure of similarity?
Edit distance
How many changes does one have to make to get
from one document to another?
What types of changes are allowed?
Add or remove a letter
Replace one letter by another
-
8/10/2019 Lecture 101 Aug 2014 Upload
22/26
Document similarity Edit Distance
Minimum number of edit operations to transformone document to another
How do we compute it?
Brute force: try all sequences and choose the bestone
Delete all of first document, add all of seconddocument
Impossibly ine"cient!
-
8/10/2019 Lecture 101 Aug 2014 Upload
23/26
Decomposing the problem
Make the first character in both documents the
same
Explore all possible edit operations that makethis possible
Recursively fix the rest of the documents
Naive recursion is ine"cient
Same subproblem solved recursively many times
-
8/10/2019 Lecture 101 Aug 2014 Upload
24/26
Naive recursion can be
inefficientFibonacci numbers:
F(n) = F(n-1) + F(n-2), F(1) = 1, F(2) = 1
Sequence is 1,1,2,3,5,8,13,21,.
Computing recursively
F(7) = F(6) + F(5) = (F(5) + F(4)) + (F(4)+F(3)) =
(F(4)+F(3)+F(3)+F(2)) + (F(3)+F(2)+F(2)+F(1)) =
-
8/10/2019 Lecture 101 Aug 2014 Upload
25/26
Dynamic Programming
Making recursive computations e"
cient
Ensure that subproblems are computed only once
How do we store and look up answers to already
solved subproblems?
-
8/10/2019 Lecture 101 Aug 2014 Upload
26/26
Variations
Interested only in the meaning of the document
Focus on words
Documents are near if they overlap on many words
Order in which words occur may not matter
Useful for topic based web search
Can have dictionary of similar words