Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. Step to developing a usable algorithm:
  2. Model the problem
  3. Find a algorithm to solve it.
  4. Fast enough? Fit in memory?
  5. If not, figure out why?
  6. Find a way to address the problem.
  7. Iterate until satisfied.
  8.  
  9. Dynamic connectivity:
  10. Given a set of N objects
  11.  
  12. Union command: connect two object.
  13. find /connected query: is there a path connecting the two objects?
  14.  
  15. When programming, convenient to name objects 0 to N - 1.
  16. Use integers as array index.
  17. Suppress details not relevant to union-find.
  18.  
  19. Modeling the connections
  20. Assume β€œis connected to” is an equivalence relation:
  21. Reflexive: p is connected to p.
  22. symmetric : if p is connected to q, then q is connected to p.
  23. Transitive: if p is connected to q and q is connected to r, then p is connected to r.
  24.  
  25. Connected components. Maximal set of objects that are mutually connect.
  26. { 0 } { 1 4 5 } { 2 3 7 6 }
  27.  
  28. Implementing the operation
  29. Find query. Check if two objects are in the same component.
  30. Union command. Replace components containing two objects with their union.
  31.  
  32. Union-find data type(API)
  33. Goal. Design efficient data structure for union-find.
  34. Number of objects N can be huge.
  35. Number of operation M can be huge.
  36. Find queries and union command may be intermixed.
  37.  
  38. Dynamic-connectivity client
  39. Read in number of objects from standard input.
  40. Repeat:
  41. Read in pair of integers from standard input
  42. If they are not yet connected, connect the and print out pair.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement