PFDS 6.4.3
Upcoming SlideShare
Loading in...5
×
 

PFDS 6.4.3

on

  • 384 views

 

Statistics

Views

Total Views
384
Views on SlideShare
383
Embed Views
1

Actions

Likes
1
Downloads
1
Comments
0

1 Embed 1

https://twitter.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    PFDS 6.4.3 PFDS 6.4.3 Presentation Transcript

    • PFDS 6.4.3Bottom-Up Mergesort with Sharing @rf0444
    • Bottom-UP Mergesort 5 2 7 4 1 8 3
    • Bottom-UP Mergesort 5 2 7 4 1 8 3
    • Bottom-UP Mergesort 5 2 7 4 1 8 3 5 2 7 1 4 3 8
    • Bottom-UP Mergesort 5 2 7 4 1 8 3 5 2 7 1 4 3 8 5 2 7 1 3 4 8
    • Bottom-UP Mergesort 5 2 7 1 3 4 8
    • Bottom-UP Mergesort 5 2 7 1 3 4 8 2 5 7 1 3 4 8
    • Bottom-UP Mergesort 5 2 7 1 3 4 8 2 5 7 1 3 4 8 1 2 3 4 5 7 8
    • with Sharing 7 4 1 8 3 1 3 4 7 8 2 7 4 1 8 3 1 2 3 4 7 85 2 7 4 1 8 3 1 2 3 4 5 7 8
    • with Sharing7 4 1 8 3
    • with Sharing7 4 1 8 3 7 1 3 4 8
    • with Sharingadd 7 4 1 8 3 7 1 3 4 8 2 7 4 1 8 3 2 7 1 3 4 85 2 7 4 1 8 3 5 2 7 1 3 4 8
    • with Sharingsort 7 1 3 4 8 1 3 4 7 8 2 7 1 3 4 8 1 2 3 4 7 8 5 2 7 1 3 4 8 1 2 3 4 5 7 8
    • add’s costunshared cost = 1shared cost = addSeg’s cost
    • add’s costaddSeg’s cost6 5 2 7 1 3 4 8
    • add’s cost addSeg’s cost 6 5 2 7 1 3 4 8(1 + 1) 5 6 2 7 1 3 4 8
    • add’s cost addSeg’s cost 6 5 2 7 1 3 4 8(1 + 1) 5 6 2 7 1 3 4 8(1 + 1) + (2 + 2) 2 5 6 7 1 3 4 8
    • add’s cost addSeg’s cost 6 5 2 7 1 3 4 8(1 + 1) 5 6 2 7 1 3 4 8(1 + 1) + (2 + 2) 2 5 6 7 1 3 4 8(1 + 1) + (2 + 2) + (4 + 4) 1 2 3 4 5 6 7 8
    • add’s cost addSeg’s cost ・・・add時に、左 k ブロックが埋まっているとすると、 k-1 k-1 k(1 + 1) + (2 + 2) + ... + (2 +2 ) = 2 (2 - 1)
    • add’s costcomplete cost= unshared cost + shared cost k= 1 + 2 (2 - 1) k+1=2 -1
    • add’s costamortized cost= complete cost - change in potential
    • potential iψ(n) = 2n - 2 i Σ0 b i (n mod 2 - 1) =0 ≦ ψ(n) ≦ 2n
    • potential b の項n 2n 0 1 2 3 ψ(n)0 0 + = 01 2 + -2 = 02 4 + -2 = 23 6 + -2 -4 = 04 8 + -2 = 65 10 + -2 -4 = 46 12 + -2 -6 = 47 14 + -2 -4 -8 = 08 16 + -2 = 149 18 + -2 -4 = 1210 20 + -2 -6 = 12
    • change in potentialn ψ(n) ψ(n + 1) ψ(n + 1) - ψ(n)0 0 0 01 0 2 22 2 0 -23 0 6 64 6 4 -25 4 4 06 4 0 -47 0 14 148 14 12 -29 12 12 0
    • change in potential k+1ψ(n + 1) - ψ(n) = 2 - 2 B’ B’ = n + 1 をビット表現したときの 1 の数
    • add’s costamortized cost= complete cost - change in potential k+1 k+1= (2 - 1) - (2 - 2 B’)= 2 B’ - 1O(log n)
    • sort’s cost 5 2 7 1 3 4 8
    • sort’s cost 5 2 7 1 3 4 8(1 + 2) 2 5 7 1 3 4 8
    • sort’s cost 5 2 7 1 3 4 8(1 + 2) 2 5 7 1 3 4 8(1 + 2) + (1 + 2 + 4) 1 2 3 4 5 7 8
    • sort’s cost ・・・ k-1(1 + 2) + (1 + 2 + 4) + ... + (1 + 2 + ... + 2 ) k+1= (2 - 4) - (k - 1)= 2n - k - 1
    • sort’s costamortized cost= (2n - k - 1) + ψ(n)< 4nO(n)