logistics
play

Logistics HW 2 due now HW 3 out this afternoon Reading: K&T - PowerPoint PPT Presentation

Logistics HW 2 due now HW 3 out this afternoon Reading: K&T 3.4-3.6 Questions? Logistics Homework: 35% Midterms: 30% Final: 20% Quizzes + participation: 15% Some Comments I look forward to learning more about the p versus np problem


  1. Logistics HW 2 due now HW 3 out this afternoon Reading: K&T 3.4-3.6 Questions?

  2. Logistics Homework: 35% Midterms: 30% Final: 20% Quizzes + participation: 15%

  3. Some Comments I look forward to learning more about the p versus np problem and learning about what problems cannot be efficiently solved. The course text book - Algorithms Design - is really fun to read. It explains concepts in a very clear way. I realized how much I forgot from Data Structure :( The course seems ok so far... I think....

  4. Some Questions Will we usually get graded homework back on the same day that new homework is due? I would appreciate it if you could explain some of the implementations of data structures for Gale Shapley algorithm (how many lists, arrays in the first implementation, etc). sorting with priority queues

  5. Running Time? Initialize each college and student to be free. while (some college is free and hasn't made offers to every student) { Choose such a college c s = 1 st student on c’s list to whom c has not made offer if (s is free) assign c and s to be engaged else if (s prefers c to current college c’) assign c and s to be engaged, and c’ to be free else s rejects c } O(n 2 ) if constant time inside the loop

  6. About Data Structures... For our purposes, most data structures are “black boxes” with certain running-time guarantees Good news: don’ t need to remember details Bad news: they may seem opaque if you don’ t remember details

  7. Lists and Arrays Array List Get i th entry O(1) O(i) O(n) find element e O(n) O(log n) if sorted insert/delete O(n) O(1)

  8. Which Data Structures Should We Use? Need to do following in O(1) time linked list Find free college c freeColleges Find next student s in two arrays preference list of c Pref[c,Next[c]] array Find current college c’ of s Current[s] array Check if s likes c’ better then c Rank[s,c] Example on board

  9. Another Example: Heapsort Input: unsorted array A[] Let Q be a heap-based priority queue for i = 1 to n Insert(Q, A[i]) end for i = 1 to n A[i] = ExtractMin(Q) end (n x Insert) + (n x ExtractMin) → O(n log n) if Insert and ExtractMin are O(log n)

  10. Graphs Chapter 3

  11. Undirected Graph Undirected graph. G = (V , E) V = nodes (vertices) E = edges between pairs of nodes. Captures pairwise relationship between objects. Graph size parameters: n = |V|, m = |E|. V = {1, 2, 3, 4, 5} 1 2 E = {(1,2), (1,4), (1,5), (2,3), (2,4), 3 (3,5)} n=5 5 4 m=6

  12. Graphs are Ubiquitous Google Maps: What is the shortest driving route from Amherst to Florida? Facebook: how many “degrees of separation” between me and Barack Obama? Many more…

  13. Four Degrees of Separation Lars Backstrom ∗ Paolo Boldi † Marco Rosa † Sebastiano Vigna † Johan Ugander ∗ January 6, 2012 Abstract Frigyes Karinthy, in his 1929 short story “Láncszemek” (“Chains”) suggested that any two persons are distanced by arXiv:1111.4570v3 [cs.SI] 5 Jan 2012 at most six friendship links. 1 Stanley Milgram in his famous experiment [20, 23] challenged people to route postcards to a fixed recipient by passing them only through direct acquain- tances. The average number of intermediaries on the path of the postcards lay between 4 . 4 and 5 . 7 , depending on the sample of people chosen. We report the results of the first world-scale social-network graph-distance computations, using the entire Facebook net- work of active users ( ≈ 721 million users, ≈ 69 billion friend- ship links). The average distance we observe is 4 . 74 , cor- responding to 3 . 74 intermediaries or “degrees of separation”, showing that the world is even smaller than we expected, and prompting the title of this paper. More generally, we study the distance distribution of Facebook and of some interest- ing geographic subgraphs, looking also at their evolution over time. The networks we are able to explore are almost two orders

  14. Fish, Rivers and Trees Habitat Accessibility: 0 1.0 (a) budget = 0, z = 5 . 4 × 10 5 (b) budget = 1000, z = 2 . 2 × 10 6 (c) budget = 10000, z = 5 . 8 × 10 6 Figure 4: Visualization of the barrier removal policies

  15. Definitions

  16. Terminology If e = (u, v) is an edge, then: (1) u is a neighbor of v (2) u is adjacent to v (3) e is incident on u and v (4) u and v are the endpoints of e 1 1 2 2 1 is adjacent to 2 3 3 (1,2) is incident on 1 and 2 5 5 4 4

  17. Path A path is a sequence P of nodes v 1 , v 2 , …, v k-1 , v k with the property that each consecutive pair v i , v i+1 is joined by an edge in E. 1 1 2 2 1-4-2 is a path. 3 3 1-3-4 is NOT a path. 5 5 4 4

  18. Distance The distance from u to v is the minimum number of edges in any path from u to v 1 2 3 distance(1,2) = 1 distance(1,3) = 2 5 4

  19. Cycle A cycle is a path v 1 , v 2 , …, v k-1 , v k in which v 1 = v k , k > 2, and the first k-1 nodes are all distinct. 1 2 1-2-4-1 is a cycle. 1-2-4 is NOT a cycle. 3 1-2-4-1-5 is NOT a cycle. 1-2-4-1-5-3-2-1 is NOT a cycle. 5 4

  20. Connectivity An undirected graph is connected if for every pair of nodes u and v, there is a path between u and v. 1 2 is a connected graph. 3 5 4 1 2 is NOT a connected 3 graph. 5 4

  21. Trees A tree is an undirected graph that is connected and does not contain a cycle. 1 2 is a tree 3 5 4 1 2 is NOT a tree 3 5 4

  22. Parents, descendants, ancestors? (Upside-down) Trees 1 2 3 5 4 1 2 5 2 4 1 3 4 3 5 http:/ /www.offbeattravel.com/MoCA.html

  23. Review Definitions What to know: n, m, neighbor, incident, path, distance, cycle, connected, tree Example on board

  24. Graph Traversal Is a graph connected? 1 2 3 5 4 easy hmmm...

  25. Graph Traversal Is a graph connected? Approach: explore outward from arbitrary starting node s to find all nodes reachable from s (connected component)

  26. Is a Graph Connected? Algorithm 1: Breadth-first search (BFS) Explore outward by distance a c Start at a: e b d a c Visit all nodes at e distance 1 from a: b d a c Visit all nodes at e distance 2 from a: b d

  27. Breadth-First Search Layers L 0 = { s }. L 1 = all neighbors of L 0 L 2 = nodes with edge to L 1 that do not belong to L 0 or L 1 ... L i+1 = nodes with edge to L i that do not belong to an earlier layer L i+1 = { v: ∃ (u,v) ∈ E, u ∈ L i , v ∉ L 0 ∪ … ∪ L i } Observation: L i consists of all nodes at distance exactly i from s. There is a path from s to t iff t appears in some layer.

  28. BFS Tree If we keep only the edges traversed while doing a breadth-first search, we will have a tree. Example on board

  29. BFS Tree Property. Let T be a BFS tree of G = (V , E), and let (x, y) be an edge of G. Then the layer of x and y differ by at most 1. Layer 0: {a} a c Layer 1: {b, c, d} e Layer 2: {e} b d Proof on board

  30. A More General Strategy To explore the connected component, add any node v for which: (u, v) is an edge u is explored, but v is not Picture on board

  31. Is a Graph Connected? Algorithm 2: Depth-first search (DFS) - Keep exploring from most recently added node until you have to backtrack a c a c a c e e e b d b d b d a c a c e e b d b d

  32. DFS Algorithm DFS(u) { mark u as “explored” for each edge (u,v) incident to u { if (v is not marked as “explored”) { DFS(v); } } }

  33. Depth First Search Theorem: Let T be a depth-first search tree. Let x and y be 2 nodes in the tree. Let (x, y) be an edge that is in G but not in T. Then either x is an ancestor of y or y is an ancestor of x in T. a c a c e d e b d b Proof?

  34. Summary Definitions: G = (V , E), n = |V|, m = |E|, neighbor, incident, cycle, path, connected, tree BFS and DFS: two ways to traverse a graph; each produces a tree BFS: short, broad tree (“bushy”) DFS: deep, narrow tree (“scraggly”)

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend