1 Announcement Change of Venue for Tutorial Session #T01 and #TA1 from Week 6 to Week 13 (except in...

download 1 Announcement Change of Venue for Tutorial Session #T01 and #TA1 from Week 6 to Week 13 (except in Week 8): Section Day Time T01 & TA1 Friday 15:00 -

If you can't read please download the document

description

3

Transcript of 1 Announcement Change of Venue for Tutorial Session #T01 and #TA1 from Week 6 to Week 13 (except in...

1 Announcement Change of Venue for Tutorial Session #T01 and #TA1 from Week 6 to Week 13 (except in Week 8): Section Day Time T01 & TA1 Friday 15: :50 New Venue: Week 6: 9 Oct - Room 1406, Academic 2 Week 7: 16 Oct - Room 1406, Academic 2 Week 8: 23 Oct - Room 2308, Academic 2 Week 9: 30 Oct - Room 1406, Academic 2 Week 10: 6 Nov - Room 1406, Academic 2 Week 11: 13 Nov - Room 1406, Academic 2 Week 12: 20 Nov - Room 1406, Academic 2 Week 13: 27 Nov - Room 1406, Academic 2 2 3 4 See the demo slide on the website. 5 Example 1: Whole Process H G F E D C B A Divide H G F E D C B A Merge G H E F C D A B Merge E F G H A B C D Merge A B C D E F G H 6 7 (T(n/2)=2T(n/4)+n/2) 8 Example 2: Whole Process A L G O R I T H M S Divide A L G O R | J T H M S Divide A L | G O R | J T | H M S Divide A | L | G | O R | J | T | H | M S Divide A | L | G | O | R | J | T | H | M | S Merge A | L | G | O R | J | T | H | M S Merge A L | G O R | J T | H M S Merge A G L O R | H J M S T Merge A G H J L M O R S T 9 R1: g, q, p, r, m 1, 2, 3, 4, 5 R2: q, p, r, g, m 2, 3, 4, 1, 5 We can assume that the first rank is 1, 2,,n. example 10 11 12 13 14 15 16 17 Merge and Count Process: Another example. 1, 2, 8, 10, 11, 12; 3, 4, 5, 6, 7, 9; # of inversions 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12. Time for merge : O(n). 18 19 20 21 22 23 24 25 26 27 28 ((0.5 ) 2 +(0.5 ) 2 ) 0.5 =(0.5 2 ) 0.5 < 29 Can be done in O(n) time if we sort all the points first. 30 Sort the points according to the x-coordinates and get a list ListX={p 1, , p n }. Closest-Pair(p 1, , p n ) { Compute separation line L such that half the points List1X={p 1, p 2, , P 0.5n } are on one side and the other half List2X={p 0.5n+1, p n } on the other side. ( 1, List1Y) = Closest-Pair(List1X) ; ( 2, LIst2Y)= Closest-Pair(List2X) ( = min(( 1, 2)) Merge: merge List1Y and list2Y to form ListY. (O(n) time) Delete all points further than from separation line L (O(n) time) Create array new-yg for remaining points sorted by y according to ListY (O(n) time). for (i=0; i, is not updated. Compare the distance dist(p 6,p 7 ) with . Here dist(p 6,p 7 ) = 1 < , is updated. Closest-pair (Region 3 and 4) = dist(p 6,p 7 ) = 1. p2p2 p3p3 p1p1 p4p4 p7p7 p8p8 p6p6 p5p L1L1 L2L2 Reg 1 Reg 2 L3L3 Reg 3Reg 4 1 38 Consider Region 1, 2 and Region 3, 4 as two large regions. 1 =Closest-pair (Region 1 and 2) = dist(p 1,p 2 ) = 2 =Closest- pair (Region 3 and 4) = dist(p 6,p 7 ) = 1 = min( 1, 2 )= 1 p2p2 p3p3 p1p1 p4p4 p7p7 p8p8 p6p6 p5p L1L1 L2L2 Reg 1 Reg 2 L3L3 Reg 3Reg 4 1 39 Delete the points in Region 1, 2, 3 and 4 further than = 1 from L 1 Here only one point p4 is left, is not updated. Closest-pair (Region 1, 2, 3 and 4) = dist(p 6,p 7 ) = 1. p2p2 p3p3 p1p1 p4p4 p7p7 p8p8 p6p6 p5p L1L1 L2L2 Reg 1 Reg 2 L3L3 Reg 3Reg 4 1 40 Closest pair of points Question: How to handle the case, where two points can have the same x-coordinate? For those points with the same x-coordinates, sort them based on y-coordinates.