SlideShare uma empresa Scribd logo
1 de 31
Baixar para ler offline
PFDS 6.4.3
Bottom-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 8

5 2 7 4 1 8 3    1 2 3 4 5 7 8
with Sharing

7 4 1 8 3
with Sharing

7 4 1 8 3       7   1 3 4 8
with Sharing
add

       7 4 1 8 3         7    1 3 4 8

      2 7 4 1 8 3       2 7   1 3 4 8

5 2 7 4 1 8 3       5   2 7   1 3 4 8
with Sharing
sort

        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 cost



unshared cost = 1

shared cost = addSeg’s cost
add’s cost
addSeg’s cost


6               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 cost


complete cost

= unshared cost + shared cost
                k
= 1 + 2 (2 - 1)
     k+1
=2         -1
add’s cost



amortized 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    +                          =    0
1    2    +    -2                    =    0
2    4    +         -2               =    2
3    6    +    -2   -4               =    0
4    8    +                -2        =    6
5    10   +    -2          -4        =    4
6    12   +         -2     -6        =    4
7    14   +    -2   -4     -8        =    0
8    16   +                     -2   =   14
9    18   +    -2               -4   =    12
10   20   +         -2          -6   =    12
change in potential
n      ψ(n)   ψ(n + 1)   ψ(n + 1) - ψ(n)

0       0        0             0

1       0        2             2

2       2        0             -2

3       0        6             6

4       6        4             -2

5       4        4             0

6       4        0             -4

7       0       14             14

8      14       12             -2

9       12      12             0
change in potential


                      k+1
ψ(n + 1) - ψ(n) = 2         - 2 B’

  B’ = n + 1 をビット表現したときの 1 の数
add’s cost

amortized cost

= complete cost - change in potential
       k+1               k+1
= (2         - 1) - (2         - 2 B’)

= 2 B’ - 1

O(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 cost


amortized cost

= (2n - k - 1)   + ψ(n)

< 4n

O(n)

Mais conteúdo relacionado

Mais procurados

ロマンティックな9つの数 #ロマ数ボーイズ
ロマンティックな9つの数 #ロマ数ボーイズロマンティックな9つの数 #ロマ数ボーイズ
ロマンティックな9つの数 #ロマ数ボーイズJunpei Tsuji
 
経済数学II 「第6章 比較静学と導関数の概念」
経済数学II 「第6章 比較静学と導関数の概念」経済数学II 「第6章 比較静学と導関数の概念」
経済数学II 「第6章 比較静学と導関数の概念」Wataru Shito
 
Practica 1 numeros naturales y enteros
Practica 1 numeros naturales y enterosPractica 1 numeros naturales y enteros
Practica 1 numeros naturales y enterosrjmartinezcalderon
 
経済数学II 「第7章 微分法とその比較静学への応用」
経済数学II 「第7章 微分法とその比較静学への応用」経済数学II 「第7章 微分法とその比較静学への応用」
経済数学II 「第7章 微分法とその比較静学への応用」Wataru Shito
 
Compfuncdiff
CompfuncdiffCompfuncdiff
Compfuncdiffdianenz
 
Darab tahun 2
Darab tahun 2Darab tahun 2
Darab tahun 2Lin Akash
 
Divisors quotients and remainders
Divisors quotients and remaindersDivisors quotients and remainders
Divisors quotients and remaindersShaun Wilson
 
Maths Olympiad - Try this prime-factor question
Maths Olympiad - Try this prime-factor questionMaths Olympiad - Try this prime-factor question
Maths Olympiad - Try this prime-factor questionKathleen Ong
 
Acitivity square of trinomial
Acitivity  square of trinomialAcitivity  square of trinomial
Acitivity square of trinomialMartinGeraldine
 
Formulario de Calculo Diferencial-Integral
Formulario de Calculo Diferencial-IntegralFormulario de Calculo Diferencial-Integral
Formulario de Calculo Diferencial-IntegralErick Chevez
 
Assignment1 solution
Assignment1 solutionAssignment1 solution
Assignment1 solutionLee Taemin
 
formulas calculo integral y diferencial
formulas calculo integral y diferencialformulas calculo integral y diferencial
formulas calculo integral y diferencialUANL-FIME
 
Taller matemáticas empresariales.
Taller matemáticas empresariales.Taller matemáticas empresariales.
Taller matemáticas empresariales.Daniela Vélez
 

Mais procurados (18)

Algebra
AlgebraAlgebra
Algebra
 
Homework packet
Homework packetHomework packet
Homework packet
 
ロマンティックな9つの数 #ロマ数ボーイズ
ロマンティックな9つの数 #ロマ数ボーイズロマンティックな9つの数 #ロマ数ボーイズ
ロマンティックな9つの数 #ロマ数ボーイズ
 
経済数学II 「第6章 比較静学と導関数の概念」
経済数学II 「第6章 比較静学と導関数の概念」経済数学II 「第6章 比較静学と導関数の概念」
経済数学II 「第6章 比較静学と導関数の概念」
 
Practica 1 numeros naturales y enteros
Practica 1 numeros naturales y enterosPractica 1 numeros naturales y enteros
Practica 1 numeros naturales y enteros
 
E1 f7 bộ binh
E1 f7 bộ binhE1 f7 bộ binh
E1 f7 bộ binh
 
経済数学II 「第7章 微分法とその比較静学への応用」
経済数学II 「第7章 微分法とその比較静学への応用」経済数学II 「第7章 微分法とその比較静学への応用」
経済数学II 「第7章 微分法とその比較静学への応用」
 
Compfuncdiff
CompfuncdiffCompfuncdiff
Compfuncdiff
 
Darab tahun 2
Darab tahun 2Darab tahun 2
Darab tahun 2
 
Divisors quotients and remainders
Divisors quotients and remaindersDivisors quotients and remainders
Divisors quotients and remainders
 
Maths Olympiad - Try this prime-factor question
Maths Olympiad - Try this prime-factor questionMaths Olympiad - Try this prime-factor question
Maths Olympiad - Try this prime-factor question
 
Acitivity square of trinomial
Acitivity  square of trinomialAcitivity  square of trinomial
Acitivity square of trinomial
 
Tugas ii (2)
Tugas ii (2)Tugas ii (2)
Tugas ii (2)
 
Formulario de Calculo Diferencial-Integral
Formulario de Calculo Diferencial-IntegralFormulario de Calculo Diferencial-Integral
Formulario de Calculo Diferencial-Integral
 
Assignment1 solution
Assignment1 solutionAssignment1 solution
Assignment1 solution
 
Substitution
SubstitutionSubstitution
Substitution
 
formulas calculo integral y diferencial
formulas calculo integral y diferencialformulas calculo integral y diferencial
formulas calculo integral y diferencial
 
Taller matemáticas empresariales.
Taller matemáticas empresariales.Taller matemáticas empresariales.
Taller matemáticas empresariales.
 

Destaque

FRP in Practice
FRP in PracticeFRP in Practice
FRP in Practicerf0444
 
Diapositivassanmiguel
DiapositivassanmiguelDiapositivassanmiguel
Diapositivassanmiguelguest635b2dcf
 
PFDS 7.4
PFDS 7.4PFDS 7.4
PFDS 7.4rf0444
 
Technical Presentation
Technical PresentationTechnical Presentation
Technical Presentationabanobpepo
 

Destaque (6)

FRP in Practice
FRP in PracticeFRP in Practice
FRP in Practice
 
Class Review
Class ReviewClass Review
Class Review
 
Diapositivassanmiguel
DiapositivassanmiguelDiapositivassanmiguel
Diapositivassanmiguel
 
Luciatåg 2009
Luciatåg 2009Luciatåg 2009
Luciatåg 2009
 
PFDS 7.4
PFDS 7.4PFDS 7.4
PFDS 7.4
 
Technical Presentation
Technical PresentationTechnical Presentation
Technical Presentation
 

Semelhante a PFDS 6.4.3

鳳山高級中學 B1 3 3---ans
鳳山高級中學   B1  3 3---ans鳳山高級中學   B1  3 3---ans
鳳山高級中學 B1 3 3---ans祥益 顏祥益
 
The Properties of Mathematics
The Properties of MathematicsThe Properties of Mathematics
The Properties of Mathematicsarinedge
 
Algebra cheat sheet
Algebra cheat sheetAlgebra cheat sheet
Algebra cheat sheetalex9803
 
Chapter 4 Extra Practice Answers
Chapter 4 Extra Practice AnswersChapter 4 Extra Practice Answers
Chapter 4 Extra Practice Answersleblance
 
Solucion de problemas de ecuaciones difrenciales hasta 19
Solucion de problemas de ecuaciones difrenciales hasta 19Solucion de problemas de ecuaciones difrenciales hasta 19
Solucion de problemas de ecuaciones difrenciales hasta 19JAVIERTELLOCAMPOS
 
Vector multiplication dot product
Vector multiplication   dot productVector multiplication   dot product
Vector multiplication dot productShaun Wilson
 
5 6 slideand_divide_11_19_12
5 6 slideand_divide_11_19_125 6 slideand_divide_11_19_12
5 6 slideand_divide_11_19_12Samantha Key
 
Lesson 18: Geometric Representations of Functions
Lesson 18: Geometric Representations of FunctionsLesson 18: Geometric Representations of Functions
Lesson 18: Geometric Representations of FunctionsMatthew Leingang
 
Algebra 2 Section 3-5
Algebra 2 Section 3-5Algebra 2 Section 3-5
Algebra 2 Section 3-5Jimbo Lamb
 
Pc12 sol c04_4-1
Pc12 sol c04_4-1Pc12 sol c04_4-1
Pc12 sol c04_4-1Garden City
 

Semelhante a PFDS 6.4.3 (20)

Week 10 - Trigonometry
Week 10 - TrigonometryWeek 10 - Trigonometry
Week 10 - Trigonometry
 
Los atomos-t4
Los atomos-t4Los atomos-t4
Los atomos-t4
 
鳳山高級中學 B1 3 3---ans
鳳山高級中學   B1  3 3---ans鳳山高級中學   B1  3 3---ans
鳳山高級中學 B1 3 3---ans
 
P cch9 sg
P cch9 sgP cch9 sg
P cch9 sg
 
The Properties of Mathematics
The Properties of MathematicsThe Properties of Mathematics
The Properties of Mathematics
 
Algebra cheat sheet
Algebra cheat sheetAlgebra cheat sheet
Algebra cheat sheet
 
Math integration-homework help
Math integration-homework helpMath integration-homework help
Math integration-homework help
 
Chapter 4 Extra Practice Answers
Chapter 4 Extra Practice AnswersChapter 4 Extra Practice Answers
Chapter 4 Extra Practice Answers
 
Chap01
Chap01Chap01
Chap01
 
Solucion de problemas de ecuaciones difrenciales hasta 19
Solucion de problemas de ecuaciones difrenciales hasta 19Solucion de problemas de ecuaciones difrenciales hasta 19
Solucion de problemas de ecuaciones difrenciales hasta 19
 
Solo edo hasta 20
Solo edo hasta 20Solo edo hasta 20
Solo edo hasta 20
 
Vector multiplication dot product
Vector multiplication   dot productVector multiplication   dot product
Vector multiplication dot product
 
5 6 slideand_divide_11_19_12
5 6 slideand_divide_11_19_125 6 slideand_divide_11_19_12
5 6 slideand_divide_11_19_12
 
End sem solution
End sem solutionEnd sem solution
End sem solution
 
Quinary base five
Quinary base fiveQuinary base five
Quinary base five
 
algebraic expressions class viii Hindi version sushma
algebraic expressions class viii Hindi version sushmaalgebraic expressions class viii Hindi version sushma
algebraic expressions class viii Hindi version sushma
 
Lesson 18: Geometric Representations of Functions
Lesson 18: Geometric Representations of FunctionsLesson 18: Geometric Representations of Functions
Lesson 18: Geometric Representations of Functions
 
Quadratic Equations
Quadratic EquationsQuadratic Equations
Quadratic Equations
 
Algebra 2 Section 3-5
Algebra 2 Section 3-5Algebra 2 Section 3-5
Algebra 2 Section 3-5
 
Pc12 sol c04_4-1
Pc12 sol c04_4-1Pc12 sol c04_4-1
Pc12 sol c04_4-1
 

Mais de rf0444

Start FRP
Start FRPStart FRP
Start FRPrf0444
 
PFDS 11.2.2
PFDS 11.2.2PFDS 11.2.2
PFDS 11.2.2rf0444
 
PFDS 10.1.2
PFDS 10.1.2PFDS 10.1.2
PFDS 10.1.2rf0444
 
PFDS 9.3.2
PFDS 9.3.2PFDS 9.3.2
PFDS 9.3.2rf0444
 
PFDS 9.3.1
PFDS 9.3.1PFDS 9.3.1
PFDS 9.3.1rf0444
 
PFDS 8.4.1
PFDS 8.4.1PFDS 8.4.1
PFDS 8.4.1rf0444
 
Tapl 5
Tapl 5Tapl 5
Tapl 5rf0444
 
Haskellday rf
Haskellday rfHaskellday rf
Haskellday rfrf0444
 

Mais de rf0444 (9)

SWF
SWFSWF
SWF
 
Start FRP
Start FRPStart FRP
Start FRP
 
PFDS 11.2.2
PFDS 11.2.2PFDS 11.2.2
PFDS 11.2.2
 
PFDS 10.1.2
PFDS 10.1.2PFDS 10.1.2
PFDS 10.1.2
 
PFDS 9.3.2
PFDS 9.3.2PFDS 9.3.2
PFDS 9.3.2
 
PFDS 9.3.1
PFDS 9.3.1PFDS 9.3.1
PFDS 9.3.1
 
PFDS 8.4.1
PFDS 8.4.1PFDS 8.4.1
PFDS 8.4.1
 
Tapl 5
Tapl 5Tapl 5
Tapl 5
 
Haskellday rf
Haskellday rfHaskellday rf
Haskellday rf
 

PFDS 6.4.3