1 / 25

Lecture 9

Lecture 9. CSE 331 Sep 16, 2019. HW 1 post-mortem. If you need it, ask for help. Advice from TAs. True/False piazza polls. Mini Project choice due in 2 weeks. Your UBIT ID is. xyz if your email ID is xyz @buffalo.edu. NOT. xyz @buffalo.edu. Your UB person number. Today’s agenda.

Download Presentation

Lecture 9

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 9 CSE 331 Sep 16, 2019

  2. HW 1 post-mortem

  3. If you need it, ask for help

  4. Advice from TAs

  5. True/False piazza polls

  6. Mini Project choice due in 2 weeks

  7. Your UBIT ID is xyz if your email ID is xyz@buffalo.edu NOT xyz@buffalo.edu Your UB person number

  8. Today’s agenda O(n2) implementation of the Gale-Shapley algorithm Some practice with run time analysis

  9. Questions?

  10. g(n) is O(f(n)) c*f(n) for some c>0 g(n) n n0

  11. Properties of O (and Ω) g is O(f) and f is O(h) then g is O(h) Transitive Step 1 // O(n) time Step 2 // O(n) time g is O(h) and f is O(h) then g+f is O(h) Additive Overall: O(n) time g is O(h1) and f is O(h2) then g*f is O(h1*h2) Multiplicative While (loop condition) // O(n2) iterations Stuff happens // O(1) time Overall: O(n2) time

  12. 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) timeimplementation 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

  13. Arrays and Linked Lists n numbers a1,a2,…,an Last Front a1 an 1 a3 a1 a2 a2 2 3 a3 Array Linked List O(1) O(i) Access ith element O(n) (O(log n) if sorted) O(n) Is e present? O(n) Insert an element O(1) given pointer n an Delete an element O(n) O(1) given pointer Static vs Dynamic Static Dynamic

  14. Implementation Steps (0) How to represent the input? (1) How do we find a free woman w? (2) How would w pick her best unproposed man m? (3) How do we know who m is engaged to? (4) How do we decide if m prefers w’ to w?

  15. Overall running time Init(1-4) n2 X ( Query/Update(1-4) )

  16. Questions?

  17. Puzzle Prove that any algorithm for the SMP takes Ω(n2) time

  18. Main Steps in Algorithm Design Problem Statement Problem Definition Algorithm n! “Implementation” Analysis Correctness Analysis

  19. Reading Assignments Sec 1.1 and Chap. 2 in [KT]

  20. Up Next…. Problem Statement A generic tool to abstract out problems Problem Definition Algorithm “Implementation” Analysis

  21. Graphs Representation of relationships between pairs of entities/elements Edge Entities: News hosts Relationship: Mention in other’s program Vertex/Node

  22. Graphs are omnipresent Airline Route maps

  23. What does this graph represent? Internet

  24. And this one? Math articles on Wikipedia

  25. And this one?

More Related