13 views

Uploaded by Antony Vimal Raj A

- C Code for n-ary tree
- Data Structures
- Questions
- Analysis Studio C10 User Guide
- Unit 3&5 Trees
- PC Shifting Graphs
- Getting Started With People Soft Query
- 62908264 Data Structure and Algorithm Lab Manual
- 10.1.1.49.3839
- On Evolution of Meaning Formations
- MCQs
- Verizon
- Binary Coded WAP Approach for Sequential Pattern Mining for Web Log
- Data Structures Questions
- Binary Tree
- DSA Laboratory Guide (updated).pdf
- IFIP-WG
- Network Analysis
- Final Itimp03
- ijcttjournal-v1i2p25

You are on page 1of 7

Disjoint Sets (Union-Find Problem) A disjoint set data structure supports the following operations. x and y are elements. Make-Set(x) Creates a new set {x}. x must not be in any other set. Union(x, y) Combine the set that contains x with the set that contains y. Find-Set(x) Find-Set(x) = Find-Set(y) when x and y are in the same set. Example: Connected components of an undirected graph Connected-Components(G) for each vertex v in graph G do Make-Set(v) for each edge (u, v) in graph G do if Find-Set(u) = Find-Set(v) then Union(u, v)

Linked List Representation Assume x has elds head, tail, next, and size.

NIL

Union(x, y) x Find-Set(x) y Find-Set(y) if size[x] < size[y] then exchange x y next[tail[x]] y Find-Set(x) tail[x] tail[y] return head[x] size[x] size[x] + size[y] while y = nil do head[y] x y next[y]

Amortized Analysis of Linked List Rep. Assume m operations including n Make-Sets. Analyze number of assignments to head eld. Using accounting method of amortized analysis: Use amortized cost 1 + lg n units/Make-Set. Consider an arbitrary element x. Use one unit immediately for Make-Set(x). Use one unit each time Union modies head[x]. Union changes head elds of smaller set, so a change to head[x] at least doubles xs set size. The size of a set cannot exceed n = 2lg n, so the cost lg n + 1 covers all changes to head[x]. Over n elements, the total cost is n(lg n + 1). There can be O(m) Find-Set operations, so total time is O(m + n lg n). It is possible that n1 Unions make (n/2) lg n assignments to head elds so O(m + n lg n) is tight.

Disjoint-Set Forests Assume x has elds p and r (parent and rank). Union(x, y) Make-Set(x) x Find-Set(x) p[x] x y Find-Set(y) r[x] 0 if r[x] > r[y] Find-Set(x) then p[y] x if x = p[x] else p[x] y then if r[x] = r[y] p[x] then r[y] r[y] + 1 Find-Set(p[x]) return p[x]

c h b

UNION

c e

FINDSET(b )

h c

g d a

h b

e d

g a

The rank bounds the height of the tree: Basis: Assume: Show: Induction: When r = 0, then h = 0. When r = k, then h k. When r = k + 1, h k + 1. h can increase only when combining two trees with same r. When r = 0, there is 20 = 1 node. When r = k, there are 2k nodes. When r = k+1, there are 2k+1 nodes. r increases only when combining two trees with same r. Their union must have 2(2k ) = 2k+1 nodes.

Without considering compression, this implies that Find-Set will traverse lg n links/call.

Amortized analysis for O(lg lg n) (not in book) Let f be the number of Find-Sets excluding recursion. Let l1, . . . , lf be the number of links compressed by calls to Find-Set. Want to bound i=1 li. Why? If a call to Find-Set compresses l links, then 2l1 nodes are closer to the root. Proof: A subtree of rank l 1 now points to the root. This subtree has 2l1 nodes. Let l be the average of l1, . . . , lf . The number of recursive calls is f l. It can be shown that i=1 2li1 f 2l1. For example, note that 2l1 + 2l+1 > 2l + 2l There is n lg n distance to compress because each node is lg n away from the root. n lg n distance to compress f 2l1 n lg n. Case 1: f n/(lg n) f n/(lg n) and l lg n imply f l n.

f f

Case 2: f n/(lg n) Start with f 2l1 n lg n Taking logarithms (lg f ) + l 1 (lg n) + (lg lg n) l 1 (lg n) + (lg lg n) (lg f ) (lg n) + (lg lg n) lg(n/ lg n) = (lg n) + (lg lg n) (lg n) + (lg lg n) = 2 lg lg n. so l is O(lg lg n), which implies that the total cost of f Find-Sets is O(n + f lg lg n).

- C Code for n-ary treeUploaded byveeru117
- Data StructuresUploaded byayjnihhh
- QuestionsUploaded byBhakti Agarwal
- Analysis Studio C10 User GuideUploaded byJoy Manning
- Unit 3&5 TreesUploaded byrayedkhan
- PC Shifting GraphsUploaded byHector R.
- Getting Started With People Soft QueryUploaded bychakrips
- 62908264 Data Structure and Algorithm Lab ManualUploaded bySrinivasa Helavar
- 10.1.1.49.3839Uploaded byAnonymous RrGVQj
- On Evolution of Meaning FormationsUploaded byDmitry Paranyushkin
- MCQsUploaded bysaimanobhiram
- VerizonUploaded bySindhu Selvaraj
- Binary Coded WAP Approach for Sequential Pattern Mining for Web LogUploaded byIDES
- Data Structures QuestionsUploaded byraman.r.bhardwaj
- Binary TreeUploaded bySiu Chung Mok
- DSA Laboratory Guide (updated).pdfUploaded byLang Christine
- IFIP-WGUploaded byGopal Sonune
- Network AnalysisUploaded byBhavani Murugesan
- Final Itimp03Uploaded byVigneshInfotech
- ijcttjournal-v1i2p25Uploaded bysurendiran123
- Data Structures Interview Questions-Trees - BALUTUTORIALSUploaded bySagar
- DS LAB MEUploaded byGanesh Kumar
- bstpgmUploaded byAnser Pasha
- MIT6_006F11_lec13Uploaded bymorgan
- ManualUploaded byNguyễnĐìnhDần
- 4101-2017-18.pdfUploaded byNoni Khanna
- Adjusting HeapsUploaded byravikumarsid2990
- Data TypesUploaded byraviskumar2005
- Part9 Ch3 Data ReplicUploaded byhimanshu_agra
- Lesson 11 BtreesUploaded byRussel Ponferrada

- blasiusUploaded byNaris Vongtyanuvat
- Activity 2Uploaded byJusztinAquino
- DiscretizationUploaded byBoudissaJoseph
- Module--1Uploaded bytonydisoja
- The Smarandache Perfect NumbersUploaded byDon Hass
- AlgebraUploaded byakansal
- EjemploUploaded byMartin Garcia
- EigenLab-102Uploaded byMradul Yadav
- Math 2 - Advanced Segment 1Uploaded byACuomo-Yokel1
- Jacobian Matrix and DeterminantUploaded byIonut Dumistrascu
- ALGEBRA (1)Uploaded byjarpulaganesh
- 2012-11-26 Solving Basic Trig Equations and Graphing Basic Trig FunctionsUploaded bysamjshah
- BesselUploaded byRafael Mapo
- On solution of sylvester equation.pdfUploaded byAzhar Mahmood
- Chain RuleUploaded bytxungo
- Lesson 1 - Matrices and DeterminantsUploaded bygaryart111
- tech01_zddUploaded byAmartya Zee
- solution5[1]Uploaded byHarjinder Pal Singh
- Naive Set TheoryUploaded byEel Dde
- 5.3 ExerciseUploaded byAvnish Bhasin
- 5 Bounded Variable Problem With GraphUploaded byAravind Sudheesan
- Enumerative Combinatorics - Peter J CameronUploaded byBug Menot
- 12 Chapter 6Uploaded bysujups
- Furman 2008 ExamUploaded byBHAAJI0001
- Optimization MethodsUploaded byNagesh Kintali
- CSC Reviewer Prof and Sub-Prof.docx · Version 1Uploaded byjhecy
- 9th MathsEM Final (3 to 303)Uploaded byArnold Brown
- ALevelCore1 4v8Fbb AbcdUploaded byRudi Berlian
- Cálculo - James StewartUploaded byLeonardo García
- 2009_Paddy Field Algorithm a New Biologically Inspired Optimization AlgorithmUploaded bytricong09t3