Download presentation
Presentation is loading. Please wait.
1
Lecture 11 CSE 331 Sep 20, 2013
2
HW 2 due today I will not accept HWs after 1:15pm
Place Q1, Q2 and Q3 in separate piles I will not accept HWs after 1:15pm
3
Other HW related stuff HW 3 has been posted online: see piazza
Solutions to HW 2 at the END of the lecture Graded HW 1 available from Monday onwards
4
My New Monday OH 3:00-3:50pm in Davis 319
5
Gale-Shapley Algorithm
At most n2 iterations Intially all men and women are free While there exists a free woman who can propose Let w be such a woman and m be the best man she has not proposed to w proposes to m O(1) time implementation If m is free (m,w) get engaged Else (m,w’) are engaged If m prefers w’ to w w remains free Else (m,w) get engaged and w’ is free Output the engaged pairs as the final output
6
Gale-Shapley Algorithm
Linked list of free women Intially all men and women are free Array Next[w] While there exists a free woman who can propose Let w be such a woman and m be the best man she has not proposed to w proposes to m Array Current[m] If m is free (m,w) get engaged Else (m,w’) are engaged Today If m prefers w’ to w w remains free ManPref[m,j] WomanPref[w,j] Else (m,w) get engaged and w’ is free Output the engaged pairs as the final output
7
Yes, Firefly again but with numbers
1 1 2 2 3 3
8
The data structures so far
1 2 3 Man-Pref 1 1 1 2 3 2 2 1 2 3 3 3 1 3 Linked list of free women 2 1 2 3 first 1 Next Current
9
Implementation Steps (1) How to represent the input?
(2) How do we find a free woman w? Init: O(n), Query/Update: O(1) (3) How would w pick her best unproposed man m? Init: O(n), Query/Update: O(1) (4) How do we know who m is engaged to? Init: O(n), Query/Update: O(1) (5) How do we decide if m prefers w’ to w?
10
Overall running time n2 X ( O(1) + O(1) + O(1)+ Query/Update(5) )
O(n) + O(n) + O(n)+ Init(5) n2 X ( O(1) + O(1) + O(1)+ Query/Update(5) )
11
HW 2 due today I will not accept HWs after 1:15pm
Place Q1, Q2 and Q3 in separate piles I will not accept HWs after 1:15pm
12
Questions?
13
Puzzle Prove that any algorithm for the SMP takes Ω(n2) time
14
Main Steps in Algorithm Design
Problem Statement Problem Definition n! Algorithm “Implementation” Analysis Correctness Analysis
15
Reading Assignments Sec 1.1 and Chap. 2 in [KT]
16
A generic tool to abstract out problems
Up Next…. Problem Statement A generic tool to abstract out problems Problem Definition Algorithm “Implementation” Analysis
17
Relationship: Mention in other’s program
Graphs Representation of relationships between pairs of entities/elements Edge Entities: News hosts Relationship: Mention in other’s program Vertex/Node
18
Graphs are omnipresent
Airline Route maps
19
What does this graph represent?
Internet
20
And this one? Math articles on Wikipedia
21
And this one?
22
Rest of today’s agenda Basic Graph definitions
23
Paths , , Sequence of vertices connected by edges Connected
Path length 3 ,
24
Connectivity u and w are connected iff there is a path between them A graph is connected iff all pairs of vertices are connected
25
Connected Graphs Every pair of vertices has a path between them
26
Cycles Sequence of k vertices connected by edges, first k-1 are distinct ,
28
Formally define everything
29
Tree Connected undirected graph with no cycles
30
Rooted Tree
31
How many rooted trees can an n vertex tree have?
A rooted tree How many rooted trees can an n vertex tree have? AC’s child=SG Pick any vertex as root SG’s parent=AC Let the rest of the tree hang under “gravity”
32
Rest of Today’s agenda Prove n vertex tree has n-1 edges
Algorithms for checking connectivity
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.