Improving Union. Implementation. Union-by-size Code. Union-by-Size Find Analysis. Path Compression! Improving Find find(e)

Similar documents
Lecture 20: Minimum Spanning Trees (CLRS 23)

Spanning Trees. BFS, DFS spanning tree Minimum spanning tree. March 28, 2018 Cinda Heeren / Geoffrey Tien 1

(Minimum) Spanning Trees

Minimum Spanning Trees (CLRS 23)

4.1 Interval Scheduling. Chapter 4. Greedy Algorithms. Interval Scheduling: Greedy Algorithms. Interval Scheduling. Interval scheduling.

5/1/2018. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees

CMPS 2200 Fall Graphs. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk

Strongly connected components. Finding strongly-connected components

Weighted Graphs. Weighted graphs may be either directed or undirected.

Minimum Spanning Trees (CLRS 23)

The University of Sydney MATH 2009

Lecture II: Minimium Spanning Tree Algorithms

CSE 373: More on graphs; DFS and BFS. Michael Lee Wednesday, Feb 14, 2018

Depth First Search. Yufei Tao. Department of Computer Science and Engineering Chinese University of Hong Kong

COMP 250. Lecture 29. graph traversal. Nov. 15/16, 2017

Divided. diamonds. Mimic the look of facets in a bracelet that s deceptively deep RIGHT-ANGLE WEAVE. designed by Peggy Brinkman Matteliano

Exam 2 Solutions. Jonathan Turner 4/2/2012. CS 542 Advanced Data Structures and Algorithms

Theorem 1. An undirected graph is a tree if and only if there is a unique simple path between any two of its vertices.

Applications of trees

Graph Search (6A) Young Won Lim 5/18/18

In which direction do compass needles always align? Why?

CMSC 451: Lecture 4 Bridges and 2-Edge Connectivity Thursday, Sep 7, 2017

CSE 332. Graphs 1: What is a Graph? DFS and BFS. Data Abstractions. CSE 332: Data Abstractions. A Graph is a Thingy... 2

Minimum Spanning Trees

2 Trees and Their Applications

learning objectives learn what graphs are in mathematical terms learn how to represent graphs in computers learn about typical graph algorithms

CSE 332. Data Structures and Parallelism

23 Minimum Spanning Trees

CS 103 BFS Alorithm. Mark Redekopp

CSE 373. Graphs 1: Concepts, Depth/Breadth-First Search reading: Weiss Ch. 9. slides created by Marty Stepp

Cycles and Simple Cycles. Paths and Simple Paths. Trees. Problem: There is No Completely Standard Terminology!

Planar convex hulls (I)

Having a glimpse of some of the possibilities for solutions of linear systems, we move to methods of finding these solutions. The basic idea we shall

Closed Monochromatic Bishops Tours

Paths. Connectivity. Euler and Hamilton Paths. Planar graphs.

, each of which is a tree, and whose roots r 1. , respectively, are children of r. Data Structures & File Management

An undirected graph G = (V, E) V a set of vertices E a set of unordered edges (v,w) where v, w in V

Math 166 Week in Review 2 Sections 1.1b, 1.2, 1.3, & 1.4

SAMPLE CSc 340 EXAM QUESTIONS WITH SOLUTIONS: part 2

Platform Controls. 1-1 Joystick Controllers. Boom Up/Down Controller Adjustments

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

Constructive Geometric Constraint Solving

Single Source Shortest Paths (with Positive Weights)

16.unified Introduction to Computers and Programming. SOLUTIONS to Examination 4/30/04 9:05am - 10:00am

23 Minimum Spanning Trees

Grade 7/8 Math Circles March 4/5, Graph Theory I- Solutions

d e c b a d c b a d e c b a a c a d c c e b

1 Introduction to Modulo 7 Arithmetic

12/3/12. Outline. Part 10. Graphs. Circuits. Euler paths/circuits. Euler s bridge problem (Bridges of Konigsberg Problem)

5/9/13. Part 10. Graphs. Outline. Circuits. Introduction Terminology Implementing Graphs

Outline. Computer Science 331. Computation of Min-Cost Spanning Trees. Costs of Spanning Trees in Weighted Graphs

b.) v d =? Example 2 l = 50 m, D = 1.0 mm, E = 6 V, " = 1.72 #10 $8 % & m, and r = 0.5 % a.) R =? c.) V ab =? a.) R eq =?

Math 61 : Discrete Structures Final Exam Instructor: Ciprian Manolescu. You have 180 minutes.

Graphs Depth First Search

Outline. 1 Introduction. 2 Min-Cost Spanning Trees. 4 Example

CSE 373: AVL trees. Warmup: Warmup. Interlude: Exploring the balance invariant. AVL Trees: Invariants. AVL tree invariants review

CSC Design and Analysis of Algorithms. Example: Change-Making Problem

Integration Continued. Integration by Parts Solving Definite Integrals: Area Under a Curve Improper Integrals

MAT3707. Tutorial letter 201/1/2017 DISCRETE MATHEMATICS: COMBINATORICS. Semester 1. Department of Mathematical Sciences MAT3707/201/1/2017

CSE 332. Graphs 1: What is a Graph? DFS and BFS. Data Abstractions. CSE 332: Data Abstractions. A Graph is a Thingy... 2

Housing Market Monitor

(2) If we multiplied a row of B by λ, then the value is also multiplied by λ(here lambda could be 0). namely

Tangram Fractions Overview: Students will analyze standard and nonstandard

CHELOURANYAN CALENDAR FOR YEAR 3335 YEAR OF SAI RHAVË

( ) ( ) ( ) 0. Conservation of Energy & Poynting Theorem. From Maxwell s equations we have. M t. From above it can be shown (HW)

CS September 2018

Appendix. In the absence of default risk, the benefit of the tax shield due to debt financing by the firm is 1 C E C

Graphs. Graphs. Graphs: Basic Terminology. Directed Graphs. Dr Papalaskari 1

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

Outline. Circuits. Euler paths/circuits 4/25/12. Part 10. Graphs. Euler s bridge problem (Bridges of Konigsberg Problem)

Graph Search Algorithms

L.3922 M.C. L.3922 M.C. L.2996 M.C. L.3909 M.C. L.5632 M.C. L M.C. L.5632 M.C. L M.C. DRIVE STAR NORTH STAR NORTH NORTH DRIVE

Minimum Spanning Trees

Planar Upward Drawings

The R-Tree. Yufei Tao. ITEE University of Queensland. INFS4205/7205, Uni of Queensland

QUESTIONS BEGIN HERE!

OpenMx Matrices and Operators

An action with positive kinetic energy term for general relativity. T. Mei

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

CS 461, Lecture 17. Today s Outline. Example Run

Ash Wednesday. First Introit thing. * Dómi- nos. di- di- nos, tú- ré- spi- Ps. ne. Dó- mi- Sál- vum. intra-vé-runt. Gló- ri-

Introduction to Inertial Dynamics

Graphs. CSC 1300 Discrete Structures Villanova University. Villanova CSC Dr Papalaskari

Decimals DECIMALS.

Why the Junction Tree Algorithm? The Junction Tree Algorithm. Clique Potential Representation. Overview. Chris Williams 1.

CSE303 - Introduction to the Theory of Computing Sample Solutions for Exercises on Finite Automata

Multipoint Alternate Marking method for passive and hybrid performance monitoring

w x a f f s t p q 4 r u v 5 i l h m o k j d g DT Competition, 1.8/1.6 Stainless, Black S, M, L, XL Matte Raw/Yellow

SAMPLE LITANY OF THE SAINTS E/G. Dadd9/F. Aadd9. cy. Christ, have. Lord, have mer cy. Christ, have A/E. Dadd9. Aadd9/C Bm E. 1. Ma ry and. mer cy.

A Simple Code Generator. Code generation Algorithm. Register and Address Descriptors. Example 3/31/2008. Code Generation

12. Traffic engineering

17 Basic Graph Properties

CS61B Lecture #33. Administrivia: Autograder will run this evening. Today s Readings: Graph Structures: DSIJ, Chapter 12

24.1 Sex-Linked Inheritance. Chapter 24 Chromosomal Basis of Inheritance Sex-Linked Inheritance Sex-Linked Inheritance

P a g e 3 6 of R e p o r t P B 4 / 0 9

Designing A Concrete Arch Bridge

On Hamiltonian Tetrahedralizations Of Convex Polyhedra

Jonathan Turner Exam 2-10/28/03

Similarity Search. The Binary Branch Distance. Nikolaus Augsten.

EE1000 Project 4 Digital Volt Meter

Transcription:

POW CSE 36: Dt Struturs Top #10 T Dynm (Equvln) Duo: Unon-y-Sz & Pt Comprsson Wk!! Luk MDowll Summr Qurtr 003 M! ZING Wt s Goo Mz? Mz Construton lortm Gvn: ollton o rooms V Conntons twn t rooms (ntlly ll los) E W wnt to ul ollton o onntons to knok own, E? E, su tt on unqu pt onnts vry two rooms T Prolm, Formlly I n v not yt n onnt r two lmnts n t sm st? Wl s rmn n E { (, ) = RmovRnomWll() ( n v not n onnt ) { (, ) to E Mrk n s onnt Mrk n s onnt Form t unon o two sts Dsjont Sts DT Fn(x) Rturns st ntr Fn(x) = Fn(y) x n y r n t sm st Unon(, ) rumnts r st ntrs How o w unon t sts ontnn x n y? MkNwSt(tm) Crt nw st ontnn only tm Dsjont Sts Forml Proprts Equvln proprty Evry lmnt o DS lons to xtly on st Dynm quvln proprty T st o n lmnt n n tr xuton o unon n(4) unon(3,6) {1,4, {6 {5,9,10 {,3 {7 {,3,6 1

Our Mo Mz Construton lortm Exmpl Wl s rmn n E (, ) = RmovRnomWll () ( Fn()!= Fn() ) E? = E? U (, ) Unon( Fn(), Fn() ) Construt t mz on t rt Intlly (t nm o st s unrln): {{{{{{{{{ 1 6 11 9 1 5 Orr o s n lu Exmpl, ontnu {{{{{{{{{ n()? n()? n()? n() so: 1 to E? unon(, ) Rsult: 11 9 1 5 Orr o s n lu 6 DS DT Tr Rprsntton Mntn orst o up-trs E st s tr Wt s t st ntr? Fn Implmntton Fn(x) Wlk prnts o x to t root Unon Implmntton + Unon(, ) Jon t two trs Sn n r lry t roots o tr, ts s sy! Runtm: Runtm:

Mor o t Exmpl unon(,) 1 6 11 9 1 5 T Fnl Mz Oo sry! Su r mz! Mn-Exrs ssum unon lwys kps rst rumnt s t root 1. Strtn wt stnt sts,,,,,, Unon(,) Unon(,) Unon(,) Fn() Unon(,) Unon(,) Unon(,) Fn(). Must Fn() lwys rturn t sm vlu? 3. Coul Unon v on ttr jo? Nty stor trk orst o up-trs n sly stor n n rry. Us stl to mp no nms to rry ns 0 () 1 () () 3 () 4 () 5 () 6 () 7 () () up-nx: -1 0-1 0 1-1 -1 7 3

nt Fn(Ojt x) { nt xid = Tl[x]; wl(up[xid]!= -1) { xid = up[xid]; Implmntton vo Unon(nt x, nt y) { up[y] = x; Improvn Unon Coul w o ttr jo on ts unon? rturn xid; Unon-y-sz Co nt Unon(nt x, nt y) { // I up[x] n up[y] rn t ot // -1, ts lortm s n troul (sz[x] > sz[y]) { up[y] = x; sz[x] += sz[y]; ls { up[x] = y; sz[y] += sz[x]; nw runtm or Unon(): nw runtm or Fn(): Unon-y-Sz Fn nlyss Fns r O(mx no pt) ll nos strt t pt 0 Dpt nrss Only wn prt o smllr tr n unon Only y on (1) lvl t tm How mny tms n ts ppn??, unon runtm = Improvn Fn n() Pt Comprsson! Wt - wt s tr to mprov? Wl w r nn, oul w o nytn ls? 4

Exrs Us unon-y-sz. Kp t rst rumnt s root tr s t. How mny nos os Fn ss? 1. Strtn wt stnt sts,,,,,, Unon(,) Unon(,) Unon(,) Unon(,) Fn() Unon(,) Unon(,) Unon(,) Unon(,) Fn() Fn() Fn(). Moy t ov to lso us Pt Comprsson. Dos t lp? 3. Usn unon-y-sz, wt s t worst s pt o ny no? Construt squn o unon oprtons tt prous ts or pt o 5. Pt Comprsson Co Intrlu: Rlly Slow Funton nt Fn(Ojt x) { // x ttr n // t st! nt xid = Tl[x]; nt = xid; // Gt t root or // ts st wl(up[xid]!= -1) { xid = up[xid]; // Cn t prnt or // ll nos lon t pt wl(up[]!= -1) { tmp = up[]; up[] = xid; = tmp; rturn xid; (Nw?) runtm or Fn(): krmnn rt rlly unton (x, y) wt t nvrs? (x, y) w s rlly smll How st os? (x, y) row??(x, y) = 4 or x r lrr tn t numr o toms n t unvrs ( 300 )? sows up n: Computton Gomtry (sur omplxty) Comntors o squns Complx Complxty o Unon-y-Sz + Pt Comprsson Trjn prov tt, wt ts optmztons, m unon n n oprtons on st o n lmnts v worst s omplxty o O(m?? (m, n)) For ll prtl purposs ts s mortz onstnt tm: O(m?4) or m oprtons! In som prtl ss, on or ot optmztons s unnssry, us trs o not nturlly t vry p. Dsjont Sts DT Summry lso known s Unon-Fn or Dsjont St Unon/Fn Smpl, nt mplmntton Wt unon-y-sz n pt omprsson Grt symptot ouns Kn o wr t rst ln, ut lots o ppltons 5