Advanced Algorithm Analysis CSC683
Advanced Algorithm Analysis CSC683
CSC683
Instructor
Nadir Shah
Associate Professor
COMSATS University Islamabad, Wah Campus
[email protected]
1
Note
Syllabus given to the CR, will be updated
Rules and Regulation
CR is responsible for
• class arrangement
• Class Makeup
• Any other activity
Attendance 80%
Strong programming and mathematics background
is desired
Students have attended a fundamental course
related to Algorithms, Data Structure, and one
major course
2
Course Assessment
Quizzes, Assignments, mid exam and final exam , class project
Class project has 20 marks will be accommodated in the final paper
• Simulation
• Development *
• Mathematical analysis
3
Performance Evaluation
Mathematical analysis (prefered)
• Algorithmic analysis
• Probability and statistics
• Formal Methods
Simulation(Recommended)
• For Networking, (NS-3, Mininet, Opnet++)
Test bed
• For Networking (SDN with ODL available)
Experiments
• In production network(if you can afford)
4
Importance of Algorithm Studies
An example of Algorithm
• List of values are A={20, 30, 31, 33, 45, 100, 500, 5001, 1000, 1001}
• Find the value of 1001? 10th step,
• Binary search
• Length 10, mid 5, A[5]=45
• Length 5, mid 8, A[8]= 5001
• Length 2, mid 8, A [9]= 1000
• A[10]=1001
v 3 w
2 5
u 2 1 z
3
1 2
x 1
y
graph: G = (N,E)
N = set of routers = { u, v, w, x, y, z }
E = set of links ={ (u,v), (u,x), (v,x), (v,w), (x,w), (x,y), (w,y), (w,z), (y,z) }
notes: 5
4
7
Step5, construct forwarding
table 8
Destination| next hope| distance 3 w z
u y
w | w |3 2
x |x |5 3
V | w |6 7 4
Y |w | 10 v
z |w | 12 Network Layer: Control Plane 5-10
Dijsktra’s algorithm
1 Initialization:
2 N' = {u}
3 for all nodes v
4 if v adjacent to u
5 then D(v) = c(u,v)
6 else D(v) = ∞
7
8 Loop
9 find w not in N' such that D(w) is a minimum
10 add w to N'
11 update D(v) for all v adjacent to w and not in N' :
12 D(v) = min( D(v), D(w) + c(w,v) )
13 /* new cost to v is either old cost to v or known
14 shortest path cost to w plus cost from w to v */
15 until all nodes in N'
SECTION 1.1
The STABLE MATCHING Problem
• originated, in part, in 1962, by David Gale and Lloyd Shapley,
• “Could one design a college admissions process, or a job recruiting process, that was self-enforcing?”
• Suppose, Job recruiting process for summer internship
• Companies and applicants
• Its crux is the interplay between two different types of parties: companies (the employers) and students (the
applicants).
• Preference ordering …
• What could be wrong????
• Raj accepted a job from ClueNet
• Then WebExodux offers Raj the job, and Raj prefers WebExodus to ClueNet…
• What will Raj do???
• Raj retracts ClueNet offer and joins WebExodus, so
• ClueNet offers to another applicant, Shah, and Shah retracts Bablesoft’s offer to join ClueNet,
• So on….. And situation gets out of control…..
• Chelsa, Raj’s friend, comes to know about this, and destined to Bablesoft, says that Chelsa will join Bablesoft
• Bablesoft will find some way to hire Chelsa instead of Shah
• generate a lot of chaos, and many people— both applicants and employers—can end up unhappy with the process
as well as the outcome.
• Why??
• Self-interest…
The STABLE MATCHING Problem
• Solution
• Self-enforcing
• Self-interest itself prevents offers from being retracted and redirected
• Another student, Asad, accepted the ClueNet offer, and calls up WebExodus, and reveals its interest and the job.
• What should be the case?
• WebExodus does not accept it
• Asad does not join it
Formal STABLE MATCHING Problem
• Given a set of preferences among employers and applicants, can we assign applicants to employers so
• that for every employer E, and every applicant A who is not scheduled to work for E, at least one of the following two
things is the case? Is stable
• (i) E prefers every one of its accepted applicants to A; or
• (ii) A prefers her current situation over working for employer E.
• Gale and Shapley proceeded to develop a striking algorithmic solution to this problem
• Formulating the Problem
• Designing the Algorithm
• Analyzing the Algorithm
Formulating the Research Problem
• Formulating the Research Problem
• make the problem as clean as possible
• For example,
• A simple, each of n applicants applies to each of n companies, and each company wants to accept a single applicant
• A company hires more than 01 applicant, An applicant gets job in a single company
• No. of applicant >> No. of available jobs
• An applicant does not apply to every company
• a system by which each of n men and n women can end up getting married: our problem naturally has the analogue
• of two “genders”—the applicants and the companies
• set M = {m1, . . . ,mn} of n men, set W = {w1, . . . , wn} of n women.
• M ×W = {(m, w)| m ∈ M and w ∈W}
• A matching S is a set of ordered pairs, each from M ×W, with the property that each member of M and each member of
W appears in at most one pair in S.
• A perfect matching S’ is a matching with the property that each member of M and each member of W appears in exactly
one pair in S’
• add the notion of preferences
• Each man m ∈M ranks all the women; we will say that m prefers w to w’ if m ranks w higher than w’
• What can be wrong, as per the Recruiting process
Formulating the Research Problem
• Some examples
• First, preference list
• m prefers w to w’.
• m’ prefers w to w’. Complete agreement,
• w prefers m to m’. (m, w) and (m’ w’), unique stable
• w’ prefers m to m’. matching
(m’, w) and (m, w’) unstable because
both m and w wants to leave and join
each other
• Proof
• Third, a bound on the maximum
number of iterations needed for
termination.
• (1.3) The G-S algorithm
terminates after at most n2
iterations of the While loop.
• to find a measure of progress in
each iteration of While Loop
• if we let P(t) denote the set of
pairs (m, w) such that m has
proposed to w by the end of
iteration t, we see that for all t, the
size of P(t + 1) is strictly greater
than the size of P(t).
• only n2 possible pairs of men and
women in total, so the value of P(·)
can increase at most n2 times over
the course of the algorithm. It
follows that there can be at most
n2 iterations
Analyzing the Algorithm
• Proof
• Finds perfect matching
• (1.4) If m is free at some point in
the execution of the algorithm,
then there is a woman to whom he
has not yet proposed.
• Proof.
• Suppose there comes a point when
m is free but has already proposed
to every woman.
• Then by (1.1), each of the n
women is engaged at this point in
time. Since the set of engaged
pairs forms a matching, there must
also be n engaged men at this
point in time. But there are only n
men total, and m is not engaged,
so this is a contradiction.
Analyzing the Algorithm
• Proof
• Finds perfect matching
• (1.5) The set S returned at
termination is a perfect matching.
• Proof. The set of engaged pairs
always forms a matching. Let us
suppose that the algorithm
terminates with a free man m. At
termination, it must be the case
that m had already proposed to
every woman for, otherwise the
While loop would not have exited.
But this contradicts (1.4), which
says that there cannot be a free
man who has proposed to every
woman.
Analyzing the Algorithm
• Proof
• Finds stable matching
• (1.6) Consider an execution of the G-S
algorithm that returns a set of pairs S. The
set S is a stable matching
• in (1.5), that S is a perfect matching
• assume that there is an instability with
respect to S with a pair (m, w) and (m’,
w’), with the properties that
• m prefers w’ to w, and
• W’ prefers m to m’.
• m’s last proposal was, by definition,
to w
• m has proposed w’ before w?
• If not, then w is on higher rank in
m’s preference list than w’,
contradicting our assumption m
prefers w’ over w.
• If yes, then w’ rejected m for her
preference m’’,
• (m’’=m’, w’) it is ok
contradiction to w’ prefers
m to m’ or
• W’ prefers her final partner
m’ to m’’; contradicting to
w’ prefers m to m’
• Our assumption is wrong, which means
S is stable matching
Extension
• Thus, we find that our simple example above, in which the men’s preferences clashed with the women’s, hinted at a very
general phenomenon: for any input, the side that does the proposing in the G-S algorithm ends up with the best
possible stable matching (from their perspective), while the side that does not do the proposing correspondingly ends
up with the worst possible stable matching.
Matching med-school students to hospitals
3
2
Stable matching problem: input
A. A–Y.
B. B–X.
C. B–Z.
1 st 2 nd 3 rd 1 st 2 nd 3 rd
1st 2nd 3rd 1st 2nd 3rd
7
Stable matching problem
1 st 2nd 3 rd
no perfect matching is stable
A B C D
A–B, C–D B–C unstable
B C A D
A–C, B–D A–B unstable
C A B D
A–D, B–C A–C unstable
D A B C
SECTION 1.1
Gale–Shapley deferred acceptance algorithm
s rejects h.
12
Proof of correctness:
termination
Observation 1. Hospitals propose to students in decreasing order
of preference.
A V W X Y Z V B C D E A
B W X. Y V Z W C D E
A B
C X Y. V W Z X D E A
D X Y E A B
Z. W Z
Z A B C B C
Y
AA. X
E V Y
C D
n(n-1) + 1 proposals
Z
13
Proof of correctness: perfect matching
h never proposed to s.
独 Case
h prefers its Gale–Shapley partner sʹ to s.
hospitals propose in
decreasing order
1: of preference
h–s is not unstable.
h proposed to s.
独 Case
s rejected h (either right away or later)
2:
s prefers Gale–Shapley partner hʹ to h.
h – sʹ
h–s is not unstable.
students only trade up
hʹ–s
⋮
独 In either case, the pair h–s is not unstable.
▪
Gale–Shapley matching M*
15
Summar
y
Stable matching problem. Given n hospitals and n students, and their
preference lists, find a stable matching if one exists.
16
Stable matching: quiz 2
17
1.
STABLE
‣
Mstable matching
ATCHING
problem
‣ Gale–Shapley
algorithm
‣ hospital optimality
‣ context
SECTION 1.1
Understanding the solution
11 22 33 11 22 33
1st
stst 2nd
ndn 3rd
rdr 1st
stst 2nd
ndn 3rd
rdr
d d d d
A X Y Z X B A C
A X Y Z X B A C
B Y X Z Y A B C
B Y X Z Y A B C
C X Y Z Z A B C
C X Y Z Z
an instance with two stable matchings: S = { A- X, B- Y, C- Z } and S′ = { A- Y, B- X, C-
Z} 19
Understanding the solution
Def. Student s is a valid partner for hospital h if there exists any stable
matching in which h and s are matched.
Ex.
独 Both X and Y are valid partners for
A. 独 Both X and Y are valid partners
for B. 独 Z is the only valid partner for
C.
A X Y Z X B A C
B Y X Z Y A B C
C X Y Z Z A B C
6 stable matchings
A.
{ A–W, B–X, C–Y, D–Z }
B. { A–X, B–W, C–Y, D–Z }
A Y Z X W W D A B C
B Z Y W X X C B A D
C W Y X Z Y C B A D
D X Z W Y Z D A B C
21
Understanding the solution
23
Hospital optimality
独
validWhen s rejects h in Gale–Shapley, s forms (or re-
stable matching M
s prefers
affirms) hʹ to h. to a hospital, say hʹ.
commitment
独 Let sʹ be partner of hʹ in M.
独 hʹ had not been rejected by any valid
because this is the first
(including sʹ) at the point when h is rejected by s.
partner rejection by a valid partner
▪
25
Stable matching: quiz 4
Suppose each agent knows the preference lists of every other agent
before the hospital propose-and-reject algorithm is executed.
Which is true?
C. Both A and B.
D. Neither A nor B.
26
1.
STABLE
‣
Mstable matching
ATCHING
problem
‣ Gale–Shapley
algorithm
‣ hospital optimality
‣ context
SECTION 1.1
Extensions
29
Historical context
独 -Algorithm
med-school student optimal
overhauled in 1998.
- deals with various side constraints
stable matching no longer
(e.g., allow couples to match together) guaranteed to exist
We report on the design of the new clearinghouse adopted by the National Resident
Matching Program, which annually fills approximately 20,000 jobs for new physi-
cians. Because the market has complementarities between applicants and between
positions, the theory of simple matching markets does not apply directly. However,
computational experiments show the theory provides good approximations. Fur-
thermore, the set of stable matchings, and the opportunities for strategic manipu-
lation, are surprisingly small. A new kind of “core convergence” result explains
this; that each applicant interviews only a small fraction of available positions is
important. We also describe engineering aspects of the design process. (JEL C78,
B41, J44)
30
2012 Nobel Prize in Economics
original applications:
college admissions and
opposite-sex marriage
32
Questbridge national college match
33
A modern application
ABSTRACT
Edge Server
This paper “peeks under the covers” at the subsystems that Overlay
provide the basic functionality of a leading content deliv-
ery network. Based on our experiences in building one of Routing Client
the largest distributed systems in the world, we illustrate
how sophisticated algorithmic research has been adapted to
balance the load between and within server clusters, man-
age the caches on servers, select paths through an overlay
routing network, and elect leaders in various contexts. In
each instance, we first explain the theory underlying the Origin
algorithms, then introduce practical considerations not cap-
tured by the theoretical models, and finally describe what is Content
Authoritative Name Server
implemented in practice. Through these examples, we high-
DNS (Global and Local Load
light the role of algorithmic research in the design of com-
Balancing)
plex networked systems. The paper also illustrates the close
synergy that exists between research and industry where
research ideas cross over into products and product require-
ments drive future research.
34
Assignment#1
What is your field of research or favorite subject. Find a relevant research article that has used G-S algorithm. Write its
summary and your critical reviews.