Docsity

Theory of Algorithms - Algorithm and Complexity Analysis - Lecture Slides, Slides of Computer Science

Toggle sidebar
bg1
COS 423: Theory of Algorithms
2
Algorithm. (webster.com)
■A procedure for solving a mathematical problem (as of finding the
greatest common divisor) in a finite number of steps that
frequently involves repetition of an operation.
■Broadly: a step-by-step procedure for solving a problem or
accomplishing some end especially by a computer.
"Great algorithms are the poetry of computation."
Etymology.
■"algos" = Greek word for pain.
■"algor" = Latin word for to be cold.
■Abu Ja’far al-Khwarizmi’s = 9th century Arab scholar.
–his book "Al-Jabr wa-al-Muqabilah" evolved into today’s high
school algebra text
Theory of Algorithms
3
Imagine: A World With No Algorithms
Fast arithmetic.
■Cryptography.
Quicksort.
■Databases.
FFT.
■Signal processing.
Huffman codes.
■Data compression.
Network flow .
■Routing Internet packets.
Linear programming.
■Planning, decision-making.
4
What is COS 423?
Introduction to design and analysis of computer algorithms.
■Algorithmic paradigms.
■Analyze running time of programs.
■Data structures.
■Understand fundamental algorithmic problems.
■Intrinsic computational limitations.
■Models of computation.
■Critical thinking.
Prerequisites.
■COS 226 (array, linked list, search tree, graph, heap, quicksort).
■COS 341 (proof, induction, recurrence, probability).
Docsity.com
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Theory of Algorithms - Algorithm and Complexity Analysis - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

COS 423: Theory of Algorithms

Algorithm. (webster.com)^ n^

A procedure for solving a mathematical problem (as of finding thegreatest common divisor) in a finite number of steps thatfrequently involves repetition of an operation. n^

Broadly: a step-by-step procedure for solving a problem oraccomplishing some end especially by a computer. "Great algorithms are the poetry of computation."Etymology.^ n^

"algos" = Greek word for pain. n^

"algor" = Latin word for to be cold. n^

Abu Ja’far al-Khwarizmi’s = 9th century Arab scholar.^ –

his book "Al-Jabr wa-al-Muqabilah" evolved into today’s highschool algebra text

Theory of Algorithms

3

Imagine:

A World With No Algorithms

Fast arithmetic.^ n^

Cryptography. Quicksort.^ n^

Databases. FFT.^ n^

Signal processing. Huffman codes.^ n^

Data compression. Network flow.^ n^

Routing Internet packets. Linear programming.^ n^

Planning, decision-making.

What is COS 423?

Introduction to design and analysis of computer algorithms.^ n^

Algorithmic paradigms. n^

Analyze running time of programs. n^

Data structures. n^

Understand fundamental algorithmic problems. n^

Intrinsic computational limitations. n^

Models of computation. n^

Critical thinking. Prerequisites.^ n^

COS 226 (array, linked list, search tree, graph, heap, quicksort). n^

COS 341 (proof, induction, recurrence, probability).

Docsity.com

5

Administrative Stuff

Lectures: (Kevin Wayne)^ n^

Monday, Wednesday 10:00 - 10:50, COS 104. TA’s: (Edith Elkind, Sumeet Sobti)Textbook: Introduction to Algorithms (CLR).Grading:^ n^

Weekly problem sets. n^

Collaboration, no-collaboration. n^

Class participation, staff discretion. n^

Undergrad / grad. Course web site: courseinfo.princeton.edu/courses/COS423_S2001/^ n^

Fill out questionnaire.

Approximate Lecture Outline

Algorithmic paradigms.^ n^

Divide-and-conquer. n^

Greed. n^

Dynamic programming. n^

Reductions. Analysis of algorithms.^ n^

Amortized analysis. Data structures.^ n^

Union find. n^

Search trees and extensions. Graph algorithms.^ n^

Shortest path, MST. n^

Max flow, matching.

7

Approximate Lecture Outline

NP completeness.^ n^

More reductions. n^

Approximation algorithms. Other models of computation.^ n^

Parallel algorithms. n^

Randomized algorithms. Miscellaneous.^ n^

Numerical algorithms. n^

Linear programming.

College Admissions

Sample problem.Algorithm.Analysis.

References:

The Stable Marriage Problem by Dan Gusfield and Robert Irving,MIT Press, 1989.Introduction to Algorithms by Jon Kleinberg and

Éva Tardos.

Docsity.com

13

Stable Matching Problem

Problem: Given N men and N women, find a "suitable" matchingbetween men and women.^ n^

PERFECT MATCHING: everyone is matched monogamously.^ –

each man gets exactly one woman – each woman gets exactly one man n^

STABILITY: no incentive for some pair of participants toundermine assignment by joint action.^ –

in matching M, an unmatched pair (m,w) is UNSTABLE if man mand woman w prefer each other to current partners – unstable pair could each improve by dumping spouses andeloping

STABLE MATCHING = perfect matching with no unstable pairs.(Gale and Shapley, 1962)

Lavender assignment is a perfect matching.Are there any unstable pairs?

Men’s Preference List

Women’s Preference List

ManXavierYanceyZeus

st 1 A B A

nd 2 B A B

rd 3 C C C

WomanAmyBerthaClare

st 1 Y X X

nd 2 X Y Y

rd 3 Z Z Z

Yes. Bertha and Xavier form an unstable pair.They would prefer each other to current partners.

B

X

Example

15

Example

Green assignment is a stable matching.

A B A

C^

Y X X

X Y Y

Z Z Z

Men’s Preference List

Women’s Preference List

ManXavierYanceyZeus

st 1

nd 2 B A B

rd 3 C C

WomanAmyBerthaClare

st 1

nd 2

rd 3

Example

Orange assignment is also a stable matching.

A^

X

X Y Y

Z Z

Men’s Preference List

Women’s Preference List

ManXavierYanceyZeus

st 1 A B

nd 2

rd 3 C C

WomanAmyBerthaClare

st 1

nd 2

rd 3

B A B

C

Y X

Z

Docsity.com

17

Preference List^ B

AdamBobChris

C A B

D D

Doofus

A

B^

D C

Stable Roommate ProblemC A

Not obvious that any stable matching exists.Consider related "stable roommate problem."^ n^

2N people. n^

Each person ranks others from 1 to 2N-1. n^

Assign roommate pairs so that no unstable pairs.

C A

B

D

No stable matching.

All 3 perfect matchings haveunstable pair.E.g., A-C forms unstable pairin lavender matching.

C

st 1 A

nd 2

rd 3

Propose-And-Reject Algorithm

Intuitive method that guarantees to find a stable matching.Initialize each person to be free. while

(some man m is free and hasn’t proposed to every woman) w = first woman on m’s list to whom m has not yet proposed if

(w is free)assign m and w to be engaged else if

(w prefers m to her fiancé m')

assign m and w to be engaged, and m' to be free else

w rejects m

Gale-Shapley Algorithm (men propose)

19

Implementation and Running Time Analysis Engagements.^ n^

Maintain two arrays wife[m], and husband[w]; set equal to 0 ifparticipant is free. n^

Store list of free men on a stack (queue). Preference lists.^ n^

For each man, create a linked list of women, ordered from favoriteto worst.^ –

men propose to women at top of list, if rejected goto next n^

For each woman, create a "ranking array" such that m

th^

entry in

array is woman’s ranking of man m.^ –

allows for queries of the form: does woman w prefer m to m’?

Resource consumption.^ n^

Time

=^

Θ(N

n^

Space =

(N

n^

Optimal.

{^

w

m

w

m

to

proposed

has

Men’s Preference List ManVictorWyatt

st 1 A B

nd 2

rd 3 C D

B C

A

XavierYanceyZeus

C D

A B

D A B

C

th 4

th 5 E E

D A

E E

B C D

E

Women’s Preference List ManAmyBertha

st 1 W X

nd 2

rd 3 Y Z

X Y

V

ClareDianeErika

Y Z

V W

Z V W

X

th 4

th 5 V W

Z V

X Y

W X Y

Z

A Worst Case Instance

Number of proposals

n(n-1) + 1.

n^

Algorithm terminates when last woman gets first proposal. Number of proposals = n(n-1) + 1 for following family of instances.

Docsity.com

25

Understanding the Solution

Fact 4. Gale-Shapley finds WOMAN-PESSIMAL matching.^ n^

Each woman married to worst valid partner.^ –

simultaneously worst for each and every woman. – there is no stable matching in which any single womanindividually does worse

Proof.^ n^

Suppose (Amy, Zeus) matched in S*, but Zeus is not worst validpartner for Amy. n^

There exists stable matching S in which Amy is paired with man,say Yancey, whom she likes less than Zeus. n^

Let Bertha be Zeus’ partner in S. n^

Zeus prefers Amy to Bertha (man optimality). n^

(Amy, Zeus) form unstable pair in S.

Amy-YanceyBertha-Zeus

S

Understanding the Solution

Fact 5. The man-optimal stable matching is weakly Pareto optimal.^ n^

There is no other perfect matching (stable or unstable), whereevery man does strictly better. Proof.^ n^

Let Amy be last woman in some execution of Gale-Shapley (menpropose) algorithm to receive a proposal. n^

No man is rejected by Amy since algorithm terminates when lastwoman receives first proposal. n^

No man matched to Amy will be strictly better off than in man-optimal stable matching.

27

Extensions: Unacceptable Partners

Yeah, but in real-world every woman is not willing to marry every man,and vice versa?^ n^

Some participants declare others as "unacceptable."(prefer to be alone than with given partner) n^

Algorithm extends to handle partial preference lists. Matching S unstable if there exists man m and woman w such that:^ n^

m is either unmatched in S, or strictly prefers w to his partner in S n^

w is either unmatched in S, or strictly prefers m to her partner in S. Fact 6. Men and women are each partitioned into two sets:^ n^

those that have partners in all stable matchings; n^

those that have partners in none.

Extensions: Sets of Unequal Size

Also, there may be an unequal number of men and women.^ n^

E.g., |M| = 100 men, |W| = 90 women. n^

Algorithm extends. n^

WLOG, assume |W| < |M|. Matching S unstable if there exists man m and woman w such that:^ n^

m is either unmatched in S, or strictly prefers w to his partner in S; n^

w is either unmatched in S, or strictly prefers m to her partner in S. Fact 7. All women are matched in every stable matching. Men arepartitioned into two subsets:^ n^

men who are matched in every stable matching; n^

men who are matched in none.

Docsity.com

29

Extensions: Limited Polygamy

What about limited polygamy?^ n^

E.g., Bill wants 3 women. n^

Algorithm extends. Matching S unstable if there exists man m and woman w such that:^ n^

either w is unmatched, or w strictly prefers m to her partner; n^

either m does not have all its "places" filled in the matching, or mstrictly prefers w to at least one of its assigned residents.

Application: Matching Residents to Hospitals Sets of unequal size, unacceptable partners, limited polygamy.Matching S unstable if there exists hospital h and resident r such that:^ n^

h and r are acceptable to each other; n^

either r is unmatched, or r prefers h to her assigned hospital; n^

either h does not have all its places filled in the matching, or hprefers r to at least one of its assigned residents.

31

Application: Matching Residents to Hospitals Matching medical school residents to hospitals. (NRMP)^ n^

Hospitals ~ Men (limited polygamy allowed). n^

Residents ~ Women. n^

Original use just after WWII (predates computer usage). n^

Ides of March, 13,000+ residents. Rural hospital dilemma.^ n^

Certain hospitals (mainly in rural areas) were unpopular anddeclared unacceptable by many residents. n^

Rural hospitals were under-subscribed in NRMP matching. n^

How can we find stable matching that benefits "rural hospitals"? Rural Hospital Theorem:

Rural hospitals get exactly same residents in every stablematching!

Deceit: Machiavelli Meets Gale-Shapley

Is there any incentive for a participant to misrepresent his/herpreferences?^ n^

Assume you know men’s propose-and-reject algorithm will be run. n^

Assume that you know the preference lists of all other participants. Fact 8. No, for any man yes, for some women!

A^

X

X Y Y

Z Z

Men’s Preference List

Women’s True Preference List

ManXavierYanceyZeus

st 1 A B

nd 2

rd 3 C C

WomanAmyBerthaClare

st 1

nd 2

rd 3

B A B

C

Y X

Z

X

Z Y Y

X Z

Amy Lies

WomanAmyBerthaClare

st 1

nd 2

rd 3

Y X

Z

X Y

Z

Y X

Z Docsity.com