lec0418-DS-ann - Announcements: MP 6 regrade window...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 10
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 12
Background image of page 13
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Announcements: MP 6 regrade window extended indefinitely. Late penalty waived. MP7 available. Due soon. Start now. Lab lO.D,._¢ 9 H,H$5‘lp Today: DISJOlnl ets A Disjoint Sets example: Let R be an equivalence relation on the set of students in this room. where (3,!) E R if s and t have the same favorite among {A8, FN. DJ. fl. PvZ}. b‘ "2 .‘nkaus Arch (3 ->1. Find(4)-> o 4 0‘ 5’ , 2. Find(4)==i=ind'(9) m “it? u- mw» 3. If (!(Find(7)==Find(2)) then Union(Find(7).Find(2)) W um” a, i Disjoint Sets ADT We will implement a data structure in support of "Disjoint Sets": o Maintains a collection S = (so. 3,. 3.3 of disjoint sets. - Each set has a representative member. - Supports functions: void MakeSet(const T 8. k); void Union(const T & k1. oonst T 8. k2); T & Find(oonst T 8. k); A A ta structure for Disjoint Sets: fi A Q @ fl-flfl'flufl Find: RAM-7 A mm an Union; om 41. “‘69s A better data structure for Disjoint Sets: UpTrees - if array value is -1. then we've found a root. o/w value is index of parent. 0 x and y are in the same tree iff they are in the same set ~ ‘ z 3‘) um..((:...th§:.-J(\ El ' “all Fin‘(') ‘9 u......tt¢.,.¢.t.,,g,u.\7 (9%) IIIIEEI unna "mum (o‘er-E33 é) @~7®:29e@ mam ——> 1, A Disjoint Sets example: Let R be an equivalence relation on the set of students in this room. where (5.!) ER if s and t have the same favorite among {A8, FN. DJ. ZH. PvZ}. 4 S 5 (a 1. Find(4) 1" 'N 2. Find(4)€=Find(§)/ 3. If (!(Find(7 -=Find(2))then Union(Find(7),Find(2)) A better data structure for Disjoint Sets: Lnt DS::Find(1nt x! [ if (slil < 0) return 1; else return Find(s[i]); Running time depends on MW Worst case? n\ What's an ideal tree? void 3::Union(int rootl, int rootZ) I — — | I: ngtz : ) something to consider... ' ‘M 0 0 ma” 3 ' and: &6 wt °\ 0 “N . kW“ “5 Qk‘i‘hg, “0 o s $174.0. Smart unions: mm Koo/1.5 a’aral/ Apia/1t of free as Sana/l (as possié/c. llflllllll flflfll’lfl Union by size- n yfivfi‘vs‘d’sflm.’ KO] " nnflfllflfl Alla "w «a m4“. 1 o Both of these schemes for Union guarantee the height of the tree is ’0 n Union by height: Smart unions: int DS::Find(int i) I it (slil < 0) return it else return Find(s[i]); void DS::QnionBySize(int rootl. int rootZ) ( int newsize - slrootll+slroot213 it (isBigqer(root1,rooc2)) { slrootzl- rootl: slrootll- newsizo: l else { slrootl] - rootZ: slrootZI- newsize: Path Compression: int DS::Pind(int i) I 1: (3(1] < 0) return 1: 01-. toturn Pind(u[i]): void DS::UnionBysizo(int tootl. int toot2) ( int nousizo - slrootll+slzoot213 it (1.31qqot(toot1,toot2)) { clzootzl- zootl; slrootll- nousizo: l 01-. ( llrootll - rootz: IltootZI- nousizo: Analysis: Trace the code below. Use Path Compression. Union by Height. and a pencil. If (Find(A) != Find(B) Union (Find (A) , Find (B) ) : If (Find(D) !- Find(E) 9 Union(Find(D),Find(E)); If (Find(A) !- Find(C) Union (Find (A) ,Find (C) ) : If (Find(C) != Find(B) Union(Find(C).Find(B)): If (Find(B) !- Find(F)) Union (Find (8) ,Find(F) ) 3 © (é) é If (Find(D) !- Find(F)) Union (Find (D) .Find(F) ) 0. What‘s the tree height of the final tree? Name the last 4 data structures we‘ve discussed: Which of those 4 islare dictionaries? Give 2 applications of a Heap: What's the buildHeap algorithm and how fast is it? ...
View Full Document

Page1 / 13

lec0418-DS-ann - Announcements: MP 6 regrade window...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online