Recall from Last Time: Disjoint Set ADT



Similar documents
Reading. Minimum Spanning Trees. Outline. A File Sharing Problem. A Kevin Bacon Problem. Spanning Trees. Section 9.6

Uses for Binary Trees -- Binary Search Trees

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

PRESENTED TO. Data Leakage Worldwide: The Effectiveness of Corporate Security Policies

MPLS FOR MISSION-CRITICAL MICROWAVE NETWORKS BUILDING A HIGHLY RESILIENT MICROWAVE NETWORK WITH MULTI-RING TOPOLOGY

Victims Compensation Claim Status of All Pending Claims and Claims Decided Within the Last Three Years

A simple algorithm to generate the minimal separators and the maximal cliques of a chordal graph

Roof Terraces. Structural assemblies

A New Efficient Distributed Load Balancing Algorithm for OTIS-Star Networks

DATA MANAGEMENT POLICY. SUMMARY OF PRINCIPAL CHANGES General changes None for amendments in this revision, refer to Appendix II, UPR IM16.

tis, cis cunc - cunc - tis, cis tis, cis cunc - tis, func - def - def - tis, U func - def - func - tis, pa - tri pa - tri pa - tri tu - per - tu -

Schedule C. Notice in terms of Rule 5(10) of the Capital Gains Rules, 1993

- ASSEMBLY AND INSTALLATION -

Change Your History How Can Soccer Knowledge Improve Your Business Processes?

Distributed Systems Principles and Paradigms. Chapter 11: Distributed File Systems. Distributed File Systems. Example: NFS Architecture

Applications: Lifting eyes are screwed or welded on a load or a machine to be used as lifting points.

Operation Transform Formulae for the Generalized. Half Canonical Sine Transform

Chapter 3 Chemical Equations and Stoichiometry

1.- L a m e j o r o p c ió n e s c l o na r e l d i s co ( s e e x p li c a r á d es p u é s ).

December Homework- Week 1

Othello: A Minute to Learn... A Lifetime to Master. Brian Rose

Binary Search Trees. Definition Of Binary Search Tree. Complexity Of Dictionary Operations get(), put() and remove()

Mathematics. Vectors. hsn.uk.net. Higher. Contents. Vectors 128 HSN23100

CompactPCI Connectors acc. to PIGMG 2.0 Rev. 3.0

WHAT HAPPENS WHEN YOU MIX COMPLEX NUMBERS WITH PRIME NUMBERS?

11 + Non-verbal Reasoning

Two-stage Framework for Visualization of Clustered High Dimensional Data

Paper Technics Orientation Course in Papermaking 2009:

Hermes: Dynamic Partitioning for Distributed Social Network Graph Databases

Polynomial Functions. Polynomial functions in one variable can be written in expanded form as ( )

Oracle PL/SQL Programming Advanced

WAVEGUIDES (& CAVITY RESONATORS)

d e f i n i c j i p o s t a w y, z w i z a n e j e s t t o m. i n. z t y m, i p o jі c i e t o

Constrained Renewable Resource Allocation in Fuzzy Metagraphs via Min- Slack

A122 MARION COUNTY HEALTH BUILDING HVAC, GLAZING AND LIGHTING RENOVATION 75% DOCUMENTS 08/31/2015

Inductive Proximity Sensors For Reliable Precision Feedback


Menu Structure. Section 5. Introduction. General Functions Menu

CC01[PE] 4mm² BLK. 16mm² [CC01] ASSEMBLY PLATE CB10PE. 16mm². 16mm²

Authenticated Encryption. Jeremy, Paul, Ken, and Mike

The Mathematics of Sudoku

MATH 150 HOMEWORK 4 SOLUTIONS

SEE PAGE 2 FOR BRUSH MOTOR WIRING SEE PAGE 3 FOR MANUFACTURER SPECIFIC BLDC MOTOR WIRING EXAMPLES A

TRIUMPH TR2 - TR4A WIRING DIAGRAMS

Form: Parental Consent for Blood Donation


Integration by Substitution

Solutions to old Exam 1 problems

Attorney Directory. Prepared for on 12/8/2008. Helping you balance work and life. To use your plan:

PC Problems HelpDesk Service Agreement

H ig h L e v e l O v e r v iew. S te p h a n M a rt in. S e n io r S y s te m A rc h i te ct

Campus Sustainability Assessment and Related Literature

Opis przedmiotu zamówienia - zakres czynności Usługi sprzątania obiektów Gdyńskiego Centrum Sportu

Matching Execution Histories of Program Versions

LTCG. Runways: Runway 11 Takeoff length: 2640, Landing length: 2640 Runway 29 Takeoff length: 2640, Landing length: 2640

Example A rectangular box without lid is to be made from a square cardboard of sides 18 cm by cutting equal squares from each corner and then folding

Reasoning to Solve Equations and Inequalities

EuroFGI Workshop on IP QoS and Traffic Control TITOLO. A Receiver Side Approach for Real-Time Monitoring of IP Performance Metrics

MODULE 3. 0, y = 0 for all y

Ne l'aria in questi di fatt'ho un si forte Castel,

With content marketing, you can move beyond measuring success in terms of impressions, awareness, or perception.

body.allow-sidebar OR.no-sidebar.home-page (if this is the home page).has-custom-banner OR.nocustom-banner .IR OR.no-IR

Back left Back right Front left Front right. Blue Shield of California. Subscriber JOHN DOE. a b c d

ELECTRICAL CAPACITY SYMBOL EQUIPMENT TYPE LOCATION / SERVING MFR MODEL (GALLONS) VOLTS PH AMPS WATTS

Last time Interprocedural analysis Dimensions of precision (flow- and context-sensitivity) Flow-Sensitive Pointer Analysis

B I N G O B I N G O. Hf Cd Na Nb Lr. I Fl Fr Mo Si. Ho Bi Ce Eu Ac. Md Co P Pa Tc. Uut Rh K N. Sb At Md H. Bh Cm H Bi Es. Mo Uus Lu P F.

Endomines - Ilomantsi Gold Project

Binary Search Trees. Definition Of Binary Search Tree. The Operation ascend() Example Binary Search Tree

SAN JOSE UNIFIED RETURNING VOLUNTEER DRIVER PACKET

Paper Cold & Hot Drink Cups & Lids

Upward Planar Drawings of Series-Parallel Digraphs with Maximum Degree Three

UNIVERSITY OF ILUNOхS LIBRARY AT URBANA-CHAMPA1GN AGR1CULT-"'J?'-

55 th EOQ Congress as World Quality Congress

3 Signals and Systems: Part II

Cloud and Big Data Summer School, Stockholm, Aug., 2015 Jeffrey D. Ullman

Vectors Recap of vectors



Econ 4721 Money and Banking Problem Set 2 Answer Key

Masters Mens Physique 45+

Broadband Technology Opportunities Program: Sustainable Broadband Adoption and Public Computer Centers

Process Mining Making Sense of Processes Hidden in Big Event Data

motori asincroni monofase asynchronous single phase motors moteurs asynchrones monophasés einphasige Asynchronmotoren

ESNV. Runways: Runway 10 Takeoff length: 1502, Landing length: 1502 Runway 28 Takeoff length: 1502, Landing length: 1260

SMBJ Transient Voltage Suppressor Diode Series

Licensed to TAP - AIR PORTUGAL,. Printed from JeppView disc

Math 314, Homework Assignment Prove that two nonvertical lines are perpendicular if and only if the product of their slopes is 1.

SE3BB4: Software Design III Concurrent System Design. Sample Solutions to Assignment 1

EQUATIONS OF LINES AND PLANES

R e t r o f i t o f t C i r u n i s g e C o n t r o l

ALL DIMENSIONS IN MILLIMETRES BUT DO NOT SCALE DRAWING

LISTA DOCUMENTI DOCUMENT LIST REVISIONI REVISIONS DESCRIZIONE FOGLI DESCRIPTION SHEET FOGLIO SHEET FOGLIO SHEET SCHEMA FLUIDICO FLUIDIC DIAGRAM

Transcription:

Ltur 21: Unon n Fn twn Up-Trs Toy s An: Plntn n rown orst o Up-Trs Unon-n n Fn-n Extn xmpl Implmntn Unon/Fn Smrt Unon n Fn Unon-y-sz/t n Pt Comprsson Run Tm Anlyss s tou s t ts! Covr n Cptr 8 o t txtook Rll rom Lst Tm: Dsjont St ADT Stors N unqu lmnts. Two oprtons: Fn: Gvn n lmnt, rturn t nm o ts quvln lss (ts st) Unon: Gvn t nms o two quvln lsss, mr tm nto on lss Exmpl: Fn(4) Intl Clsss = {1,4,8, {2,3, 8 {6, {7, {10,9,5 Nm o quv. lss unrln Unon(3,6) {1,4,8 {10,5,9 {6 {7 {2,3,6 {2,3 Som o t mtrl on ts sls r ourtsy o: S. Wolmn, CSE 326, 2000 1 2 Up-Tr Dt Strutur or Dsjont Sts Nt mplmntton trk or Up-Trs E quvln lss (or st) s n up-tr wt ts root s ts rprsnttv mmr (= lss nm) All mmrs o vn st r nos n tt st s uptr Hs tl mps nput t to no.. nput strn! ntr nx NULL NULL NULL {,,,, {, { Up-trs r usully not nry! 3 Forst o up-trs n sly stor n n rry (ll t up ) I no nms r ntrs or rtrs, n us vry smpl, prt s unton: Hs(X) = X up[x]= prnt o X; = 0 root Arry up: 0 1 () 2 () 3 () 4 () 5 () 6 () 7 () 8 () - NULL NULL NULL 0 1 0 1 2 3 1 0 4

Exmpl o Fn Fn: Just trvrs to t root! Exmpl o Unon Unon: Just n on root rom t otr! Runtm =? Fn() = Fn() = Runtm =? Now: Fn() = Fn() = Unon(,) 0 1 () 2 () 3 () 4 () 5 () 6 () 7 () 8 0 1 () 2 () 3 () 4 () 5 () 6 () 7 () 8 Arry up: - 0 1 0 1 2 3 0 Arry up: - 3 1 0 1 2 3 0 5 Cn (rom 0) to pont to (= 3) 6 A mor tl xmpl A mor tl xmpl Intl Sts: Unon(,) Unon(,) 7 8

A mor tl xmpl A mor tl xmpl Unon(,) But (you sy) n r not roots! My llow n som mplmnttons o Fn rst to t roots Sn Fn() = Fn(), unon lry on! Unon(,) But: wl w r nn, oul w o somtn to sp up Fn() nxt tm? (ol tt tout!) 9 10 A mor tl xmpl (ontnu) A mor tl xmpl Unon(,) Unon(,) 11 12

A mor tl xmpl Implmntton o Fn n Unon Unon(,) nt Fn(nt X, DsjSt up) { // Assums X = Hs(X_Elmnt) // X_Elmnt oul str/r t. (up[x] <= 0) // Root rturn X; //Rturn root = st nm ls //Fn prnt rturn Fn(up[X], up); vo Unon(DsjSt up, nt X, nt Y) { //Mk sur X, Y r //roots ssrt(up[x] == 0); ssrt(up[y] == 0); up[y] = X; Runtm o Fn: O(mx t) Runtm o Unon: O(1) Ht pns on prvous Unons!Bst s: 1-2, 1-3, 1-4, O(1)!Worst s: 2-1, 3-2, 4-3, O(N) Cn w o ttr? 13 14 Lt s look k t our xmpl Spn Up Unon/Fn: Unon-y-Sz Unon(,) For M Fns n N-1 Unons, worst s tm s O(MN+N) Cn w sp tns up y n lvr out rown our up-trs? I: In Unon, lwys mk root o lrr tr t nw root Wy? Mnmzs t o t nw up-tr Coulwottrjoon ts Unon? Wt ppn to? Unon(,) Unon-y-Sz! 15 16

Trk or Storn Sz Inormton Inst o storn 0 n root, stor up-tr sz s ntv vlu n root no Wy not postv vlu? Woul not know rry ntry s sz or prnt pontr Arry up: NULL NULL NULL 0 1 () 2 () 3 () 4 () 5 () 6 () 7 () 8 () - -5 1-2 1 2 3 1-1 17 Unon-y-Sz Co vo Unon(DsjSt up, nt X, nt Y) { //X, Y r roots //ontnn (-sz) o up-trs ssrt(up[x] < 0); ssrt(up[y] < 0); (-up[x] > -up[y]) { //upt sz o X n root o Y up[x] += up[y]; up[y] = X; ls { //sz o X < sz o Y up[y] += up[x]; up[x] = Y; Nw run tm o Unon =? Nw run tm o Fn =? 18 Unon-y-Sz: Anlyss Unon-y-Ht Fns r O(mx up-tr t) or orst o up-trs ontnn N nos Numr o nos n n up-tr o t usn unon-y-sz s 2 Bs s: =0,trs2 0 = 1 no Inuton ypotss: Assumtruor< Pk up-tr wt mx t Tn, 2 mx t N mx t lo N Fn tks O(lo N) Inuton Stp: Nw tr o t ws orm v unon o two trs o t -1 E tr tn s 2-1 nos y t nuton ypotss So, totl nos 2-1 +2-1 =2! Tru or ll Txtook srs ltrntv strty o Unon-y-t Kp trk o t o up-tr n t root nos Unon mks root o up-tr wt rtr t t nw root Sm rsults n smlr mplmntton s Unon-y-Sz Fn s O(lo N) n Unon s O(1) 19 20

Spn Up Fn: Pt Comprsson I w o M Fns on sm lmnt! O(M lo N) tm Cn w moy Fn to v s-ts so tt nxt Fn wll str? A P.C. xmpl wt mor mt Fn() Pt Comprsson: Pont vrytn lon pt o Fn to root Rus t o ntr ss pt to 1: Fns t str! Déjà vu? I smlr to t on n your ol rn sply tr Fn() Pt omprsson! 21 22 How to P.C. Pt Comprsson Co How to P.C. Pt Comprsson Co nt Fn(nt X, DsjSt up) { // Assums X = Hs(X_Elmnt) // X_Elmnt oul str/r t. nt Fn(nt X, DsjSt up) { // Assums X = Hs(X_Elmnt) // X_Elmnt oul str/r t. (up[x] <= 0) // Root rturn X; //Rturn root = st nm ls //Fn prnt rturn up[x] = Fn(up[X], up); Mk ll nos lon ss pt pont to root (up[x] <= 0) // Root rturn X; //Rturn root = st nm ls //Fn prnt rturn up[x] = Fn(up[X], up); Collpsnttry pontn to root Trvl moton o ornl Fn Nw runnn tm o Fn =? Fn stll tks O(mx up-tr t) worst s But wt ppns to t tr ts ovr tm? Wt s t mortz runtmofnwomfns? 23 24

Anlyss o P.C. wt Unon-y-Sz R. E. Trjn (o t up-trs m) sow tt: Wn ot P.C. n Unon-y-Sz r us, t worst s run tm or squn o M oprtons (Unons or Fns) s Θ(M α(m,n)) Wt s α(m,n)? α(m,n) s t nvrs o Akrmnn s unton Wt s Akrmnn s unton? Drsson: Tm slow-rown untons How st os lo N row? lo N = 4 or N = 16 = 2 4 Grows qut slowly Lt lo (k) N = lo (lo (lo (lo N))) (k los) Lt lo* N = mnmum k su tt lo (k) N 1 How st os lo * Nrow? lo * N = 4 or N = 65536 = 2 2 2 2 Grows vry slowly Akrmnn rt rlly xplosv unton A(, j) wos nvrs α(m, N) rows vry, vry slowly (slowr tn lo * N) Howslowosα(M, N) row? α(m, N) = 4 or M ( N) r lrr tn t numr o toms n t unvrs (2 300 )!! 25 26 Anlyss o P.C. wt Unon-y-Sz Summry o Dsjont St n Unon/Fn R. E. Trjn (o t up-trs m) sow tt: Wn ot P.C. n Unon-y-Sz r us, t worst s run tm or squn o M oprtons (Unons or Fns) s Θ(M α(m,n)) α(m, N) 4 or ll prtl os o M n N Txtook provs wkr rsult o O(M lo* N) tm 7 ps n 8 Lmms! (Ck t out ut no n to know t proo) Amortz run tm pr oprton = totl tm/(# oprtons) = Θ(M α(m,n))/m = Θ(α(M,N)) Θ(1) or ll prtl purposs (onstnt tm!) 27 Dsjont St t strutur rss n mny ppltons wr ojts o ntrst ll nto rnt quvln lsss or sts Cts on mp, ltrl omponnts on p, omputrs n ntwork, popl rlt to otr y loo, t. Two mn oprtons: Unon o two lsss n Fn lss nm or vn lmnt Up-Tr t strutur llows nt rry mplmntton Unons tk O(1) worst s tm, Fns n tk O(N) Unon-y-Sz rus worst s tm or Fn to O(lo N) Unon-y-Sz plus Pt Comprsson llows urtr spup Any squn o M Unon/Fn oprtons rsults n O(1) mortz tm pr oprton (or ll prtl purposs) 28

Nxt Clss: CSE 373 ts rp (Alo-rytms on Grps) To Do: Fns Homwork #4 (u nxt lss) Fns rn ptr 8 Strt rn ptr 9 29