SlideShare una empresa de Scribd logo
1 de 33
Descargar para leer sin conexión
PFDS §5.2+6.4.2 Queues
      @shtaag




2012年5月19日土曜日
First...



         http://www.kmonos.net/pub/Presen/PFDS.pdf




2012年5月19日土曜日
FIFO Queue(2リストキュー)


         type foo Queue = foo list x foo list
                fun head (x :: f, r) = x             O(1)
                fun tail (x :: f, r) = (f, r)        O(1)
                fun snoc ((f, r), x) = (f, x :: r)   O(1)

                   リスト終端への挿入にconsを用いるため、
                            リスト後半をreverseして保持
2012年5月19日土曜日
FIFO Queue(2リストキュー)


         invariant to maintain
                fはrが[ ]の時のみ[ ]

                 これがないとf = [ ]時にheadがr終端からの取り出
                 しになりheadがO(n)かかる




2012年5月19日土曜日
FIFO Queue(2リストキュー)

         to maintain invariant...
                fun checkf ([ ], r) = (rev r, [ ])
                  | checkf q = q
                fun snoc ((f, r), x) = checkf (f, x :: r)
                fun tail (x :: f, r) = checkf (f, r)




2012年5月19日土曜日
Banker’s method

         snoc = 1 step + 1 credit
         tail (w/o reverse) = 1 step
         tail (w/ reverse) = (m+1) steps - m credits

         tail . tail . tail . snoc 3 . snoc 2 . snoc 1


2012年5月19日土曜日
real   amortized
         snoc 1 -> [] [1] -> [1] []            2         2
                          checkf w/ 1 step
         snoc 2 -> [1] [2]                     1         2   +1
         snoc 3 -> [1] [3,2]                   1         2   +1
         tail -> [] [3,2] -> [2,3] []          3         1   -2
                           checkf w/ 2 step
         tail -> [3] []                        1         1
         tail -> [] []                         1         1

                                               9         9
2012年5月19日土曜日
real   amortized
         snoc 1 -> [] [1] -> [1] []      2         2
         snoc 2 -> [1] [2]               1         2   +1
         snoc 3 -> [1] [3,2]             1         2   +1
         tail -> [] [3,2] -> [2,3] []    3         1   -2
         tail -> [3] []                  1         1
                 積み立てておいたcreditを消費
         tail -> [] []   1      1

                                         9         9
2012年5月19日土曜日
Physicist’s method

         Φ = length of the rear list
         snoc = 1 step + 1 potential (for 1 elem)
         tail (w/o reverse) = 1 step
         tail (w/ reverse) = (m+1) steps - m potentials




2012年5月19日土曜日
real   amortized
         snoc 1 -> [] [1] -> [1] []      2         2
         snoc 2 -> [1] [2]               1         2   +1
         snoc 3 -> [1] [3,2]             1         2   +1
         tail -> [] [3,2] -> [2,3] []    3         1   -2
         tail -> [3] []                  1         1
         tail -> [] []                   1         1

                                         9         9
2012年5月19日土曜日
§6.4.2 with Lazy Evaluation



                O(1)
                in amortized time



2012年5月19日土曜日
§6.4.2 with Lazy Evaluation

         Queue with O(1) amortized time.
                Persistent
                Lazy Evaluation
                Strict Working Copy




2012年5月19日土曜日
§6.4.2 with Lazy Evaluation
         with the Physicist’s Method.


                                              change in
                                    shared    potential
            strict                   cost
       (non-amortized)
            cost                              amortized
                                   unshared     cost
                                     cost




2012年5月19日土曜日
§6.4.2 with Lazy Evaluation
         with the Physicist’s Method.


                                     change in
                                     potential
            strict                     paid
       (non-amortized)              shared cost
            cost
                                        paid shared cost
                                              = actually executed cost




2012年5月19日土曜日
§6.4.2 with Lazy Evaluation
         with the Physicist’s Method.      max potential
                                                 =
                                        max shared cost ???
                                     change in
                                     potential
            strict                     paid
       (non-amortized)              shared cost
            cost




2012年5月19日土曜日
Implementation of PhysicistsQueue




       type a Queue = a list x int x a list susp x int x a list




2012年5月19日土曜日
type a Queue = a list x int x a list susp x int x a list

                suspended front list + ordinal rear list

                lengths for front and rear lists
                  to calculate the diff of front and rear lengths
                  to guarantee front >= rear


                working copy of front list
                  front is suspended, so necessary to keep the access to the prefix for head
                  queries.




2012年5月19日土曜日
Potential

                length of working copy

                diff of front and rear lengths

                if those values are = 0, then rotation happens

                definition of potential

                  Ψ(q) = min (2|w|, |f| - |r|)




2012年5月19日土曜日
if potential = 0

                [ 5, 8] [ 5, 8] [ 2, 4]

                  snoc

                     unshared = 1




2012年5月19日土曜日
if potential = 0

                [ 5, 8] [ 5, 8] [ 2, 4]

                  snoc

                     shared cost of rotation = 2m + 1

                       force suspended front ++ rear




2012年5月19日土曜日
if potential = 0

                [ 5, 8] [ 5, 8] [ 2, 4]

                  snoc

                     change of potential = + 2m   create debt
                     = accumulated debt




2012年5月19日土曜日
if potential = 0

                [ 5, 8] [ 5, 8] [ 2, 4]

                  snoc

                     complete cost = 2

                       unshared = 1

                       shared = 2m + 1

                       change in potential = 2m



2012年5月19日土曜日
if potential > 0

                [ 5, 8, 2, 4] [ 5, 8, 2, 4] [ 1, 3]

                  potential = 2

                  snoc

                     unshared = 1

                     change in potential = -1




2012年5月19日土曜日
Therefore...

                snoc is O(1) amortized time

                  the cost is 2 or 4




2012年5月19日土曜日
if potential = 0

                [ 5, 8] [ 5, 8] [ 2, 4]

                  tail

                         [ 8] [ 8] [ 2, 4]




2012年5月19日土曜日
if potential = 0

                [ 5, 8] [ 5, 8] [ 2, 4]

                  tail

                         unshared cost = 2

                         shared cost = 2m + 1

                         change in potential = 2m




2012年5月19日土曜日
if potential > 0

                [ 5, 8, 2, 4] [ 5, 8, 2, 4] [ 1, 3]

                  potential = 2

                  tail

                         [ 8, 2, 4] [ 8, 2, 4] [ 1, 3]




2012年5月19日土曜日
if potential > 0

                [ 5, 8, 2, 4] [ 5, 8, 2, 4] [ 1, 3]

                  potential = 2

                  tail

                     unshared = 1 (from working copy)

                     paid shared = 1 (from front)

                     change in potential = -1 for w and -1 for (f-r)



2012年5月19日土曜日
Therefore...

                tail is in O(1) amortized time

                  the cost is 4 or 3




2012年5月19日土曜日
Theorem 6.2

                The amortized costs of snoc and tail are at most 2
                and 4, respectively

                This leads to that every operation is O(1) order.




2012年5月19日土曜日
snoc

                without rotation

                  snoc ((w, lenf, f, lenr, r), x)
                    = check (w, lenf, f , lenr+1, x :: r)

                  cost = 1 & decrease in potential = 1

                    operation for |f| - |r|

                  amortized cost = 1 - (-1)
                                 =2


2012年5月19日土曜日
tail

                without rotation

                  tail (x :: w, lenf, f, lenr, r)
                      = check (w, lenf-1, $tl (force f), lenr, r)

                  cost = 2 & decrease in potential = 2

                    operation for |w| & operation for |f| - |r|

                  amortized cost = 2 - (-2)
                                 =4


2012年5月19日土曜日
With Rotation

                |f| = m and |r| = m + 1

                  shared cost of rotation = 2m + 1

                  potential of resulting queue = 2|w|
                                               = 2m

                amortized cost of snoc

                  1 + (2m + 1) - 2m = 2

                amortized cost of tail

                  2 + (2m + 1) - 2m = 3



2012年5月19日土曜日

Más contenido relacionado

La actualidad más candente

INFLUENCE OF OVERLAYERS ON DEPTH OF IMPLANTED-HETEROJUNCTION RECTIFIERS
INFLUENCE OF OVERLAYERS ON DEPTH OF IMPLANTED-HETEROJUNCTION RECTIFIERSINFLUENCE OF OVERLAYERS ON DEPTH OF IMPLANTED-HETEROJUNCTION RECTIFIERS
INFLUENCE OF OVERLAYERS ON DEPTH OF IMPLANTED-HETEROJUNCTION RECTIFIERSZac Darcy
 
College algebra 7th edition by blitzer solution manual
College algebra 7th edition by blitzer solution manualCollege algebra 7th edition by blitzer solution manual
College algebra 7th edition by blitzer solution manualrochidavander
 
solucionario de purcell 1
solucionario de purcell 1solucionario de purcell 1
solucionario de purcell 1José Encalada
 
Numerical analysis m2 l4slides
Numerical analysis  m2 l4slidesNumerical analysis  m2 l4slides
Numerical analysis m2 l4slidesSHAMJITH KM
 
AN APPROACH TO OPTIMIZE MANUFACTURE OF AN ACTIVE QUADRATURE SIGNAL GENERATOR ...
AN APPROACH TO OPTIMIZE MANUFACTURE OF AN ACTIVE QUADRATURE SIGNAL GENERATOR ...AN APPROACH TO OPTIMIZE MANUFACTURE OF AN ACTIVE QUADRATURE SIGNAL GENERATOR ...
AN APPROACH TO OPTIMIZE MANUFACTURE OF AN ACTIVE QUADRATURE SIGNAL GENERATOR ...antjjournal
 
Mathematical approach for Text Mining 1
Mathematical approach for Text Mining 1Mathematical approach for Text Mining 1
Mathematical approach for Text Mining 1Kyunghoon Kim
 
A Course in Fuzzy Systems and Control Matlab Chapter two
A Course in Fuzzy Systems and Control Matlab Chapter twoA Course in Fuzzy Systems and Control Matlab Chapter two
A Course in Fuzzy Systems and Control Matlab Chapter twoChung Hua Universit
 
31350052 introductory-mathematical-analysis-textbook-solution-manual
31350052 introductory-mathematical-analysis-textbook-solution-manual31350052 introductory-mathematical-analysis-textbook-solution-manual
31350052 introductory-mathematical-analysis-textbook-solution-manualMahrukh Khalid
 
Green’s Function Solution of Non-homogenous Singular Sturm-Liouville Problem
Green’s Function Solution of Non-homogenous Singular Sturm-Liouville ProblemGreen’s Function Solution of Non-homogenous Singular Sturm-Liouville Problem
Green’s Function Solution of Non-homogenous Singular Sturm-Liouville ProblemIJSRED
 
A Boundary Value Problem and Expansion Formula of I - Function and General Cl...
A Boundary Value Problem and Expansion Formula of I - Function and General Cl...A Boundary Value Problem and Expansion Formula of I - Function and General Cl...
A Boundary Value Problem and Expansion Formula of I - Function and General Cl...IJERA Editor
 
Differentiation mcq
Differentiation mcqDifferentiation mcq
Differentiation mcq123iitjee
 
A common random fixed point theorem for rational ineqality in hilbert space ...
 A common random fixed point theorem for rational ineqality in hilbert space ... A common random fixed point theorem for rational ineqality in hilbert space ...
A common random fixed point theorem for rational ineqality in hilbert space ...Alexander Decker
 

La actualidad más candente (15)

Algebra 6
Algebra 6Algebra 6
Algebra 6
 
INFLUENCE OF OVERLAYERS ON DEPTH OF IMPLANTED-HETEROJUNCTION RECTIFIERS
INFLUENCE OF OVERLAYERS ON DEPTH OF IMPLANTED-HETEROJUNCTION RECTIFIERSINFLUENCE OF OVERLAYERS ON DEPTH OF IMPLANTED-HETEROJUNCTION RECTIFIERS
INFLUENCE OF OVERLAYERS ON DEPTH OF IMPLANTED-HETEROJUNCTION RECTIFIERS
 
College algebra 7th edition by blitzer solution manual
College algebra 7th edition by blitzer solution manualCollege algebra 7th edition by blitzer solution manual
College algebra 7th edition by blitzer solution manual
 
solucionario de purcell 1
solucionario de purcell 1solucionario de purcell 1
solucionario de purcell 1
 
Numerical analysis m2 l4slides
Numerical analysis  m2 l4slidesNumerical analysis  m2 l4slides
Numerical analysis m2 l4slides
 
AN APPROACH TO OPTIMIZE MANUFACTURE OF AN ACTIVE QUADRATURE SIGNAL GENERATOR ...
AN APPROACH TO OPTIMIZE MANUFACTURE OF AN ACTIVE QUADRATURE SIGNAL GENERATOR ...AN APPROACH TO OPTIMIZE MANUFACTURE OF AN ACTIVE QUADRATURE SIGNAL GENERATOR ...
AN APPROACH TO OPTIMIZE MANUFACTURE OF AN ACTIVE QUADRATURE SIGNAL GENERATOR ...
 
Mathematical approach for Text Mining 1
Mathematical approach for Text Mining 1Mathematical approach for Text Mining 1
Mathematical approach for Text Mining 1
 
A Course in Fuzzy Systems and Control Matlab Chapter two
A Course in Fuzzy Systems and Control Matlab Chapter twoA Course in Fuzzy Systems and Control Matlab Chapter two
A Course in Fuzzy Systems and Control Matlab Chapter two
 
31350052 introductory-mathematical-analysis-textbook-solution-manual
31350052 introductory-mathematical-analysis-textbook-solution-manual31350052 introductory-mathematical-analysis-textbook-solution-manual
31350052 introductory-mathematical-analysis-textbook-solution-manual
 
Green’s Function Solution of Non-homogenous Singular Sturm-Liouville Problem
Green’s Function Solution of Non-homogenous Singular Sturm-Liouville ProblemGreen’s Function Solution of Non-homogenous Singular Sturm-Liouville Problem
Green’s Function Solution of Non-homogenous Singular Sturm-Liouville Problem
 
A Boundary Value Problem and Expansion Formula of I - Function and General Cl...
A Boundary Value Problem and Expansion Formula of I - Function and General Cl...A Boundary Value Problem and Expansion Formula of I - Function and General Cl...
A Boundary Value Problem and Expansion Formula of I - Function and General Cl...
 
Differentiation mcq
Differentiation mcqDifferentiation mcq
Differentiation mcq
 
A common random fixed point theorem for rational ineqality in hilbert space ...
 A common random fixed point theorem for rational ineqality in hilbert space ... A common random fixed point theorem for rational ineqality in hilbert space ...
A common random fixed point theorem for rational ineqality in hilbert space ...
 
Homework packet
Homework packetHomework packet
Homework packet
 
Capitulo 4 Soluciones Purcell 9na Edicion
Capitulo 4 Soluciones Purcell 9na EdicionCapitulo 4 Soluciones Purcell 9na Edicion
Capitulo 4 Soluciones Purcell 9na Edicion
 

Destacado

IQPC Def Log UAE 2011 Brochure
IQPC Def Log UAE 2011 BrochureIQPC Def Log UAE 2011 Brochure
IQPC Def Log UAE 2011 Brochurecjeffray
 
Introduction to Social Media for Academics | Ecodemia
Introduction to Social Media for Academics | EcodemiaIntroduction to Social Media for Academics | Ecodemia
Introduction to Social Media for Academics | EcodemiaRichard Roaf
 
IQPC Future Artillery 2011 Brochure
IQPC Future Artillery 2011 BrochureIQPC Future Artillery 2011 Brochure
IQPC Future Artillery 2011 Brochurecjeffray
 
Raymond & Rachel Engagement Dinner
Raymond & Rachel Engagement DinnerRaymond & Rachel Engagement Dinner
Raymond & Rachel Engagement DinnerRiver Rock
 
Windsor Conference Timetable
Windsor Conference Timetable Windsor Conference Timetable
Windsor Conference Timetable Richard Roaf
 
Scala(finagle)@SmartNews_English
Scala(finagle)@SmartNews_EnglishScala(finagle)@SmartNews_English
Scala(finagle)@SmartNews_EnglishShigekazu Takei
 
Future Artillery India
Future Artillery IndiaFuture Artillery India
Future Artillery Indiacjeffray
 
Cyber Defence & Network Security
Cyber Defence & Network SecurityCyber Defence & Network Security
Cyber Defence & Network Securitycjeffray
 
Armoured Vehicles UAE Conference Brochure
Armoured Vehicles UAE Conference BrochureArmoured Vehicles UAE Conference Brochure
Armoured Vehicles UAE Conference Brochurecjeffray
 
Stanford ml neuralnetwork
Stanford ml neuralnetworkStanford ml neuralnetwork
Stanford ml neuralnetworkShigekazu Takei
 
Scala@SmartNews_20150221
Scala@SmartNews_20150221Scala@SmartNews_20150221
Scala@SmartNews_20150221Shigekazu Takei
 

Destacado (14)

IQPC Def Log UAE 2011 Brochure
IQPC Def Log UAE 2011 BrochureIQPC Def Log UAE 2011 Brochure
IQPC Def Log UAE 2011 Brochure
 
Pfds 9 2_2
Pfds 9 2_2Pfds 9 2_2
Pfds 9 2_2
 
Introduction to Social Media for Academics | Ecodemia
Introduction to Social Media for Academics | EcodemiaIntroduction to Social Media for Academics | Ecodemia
Introduction to Social Media for Academics | Ecodemia
 
IQPC Future Artillery 2011 Brochure
IQPC Future Artillery 2011 BrochureIQPC Future Artillery 2011 Brochure
IQPC Future Artillery 2011 Brochure
 
Raymond & Rachel Engagement Dinner
Raymond & Rachel Engagement DinnerRaymond & Rachel Engagement Dinner
Raymond & Rachel Engagement Dinner
 
Windsor Conference Timetable
Windsor Conference Timetable Windsor Conference Timetable
Windsor Conference Timetable
 
Startprintf_2013May18
Startprintf_2013May18Startprintf_2013May18
Startprintf_2013May18
 
Scala(finagle)@SmartNews_English
Scala(finagle)@SmartNews_EnglishScala(finagle)@SmartNews_English
Scala(finagle)@SmartNews_English
 
Future Artillery India
Future Artillery IndiaFuture Artillery India
Future Artillery India
 
Cyber Defence & Network Security
Cyber Defence & Network SecurityCyber Defence & Network Security
Cyber Defence & Network Security
 
Armoured Vehicles UAE Conference Brochure
Armoured Vehicles UAE Conference BrochureArmoured Vehicles UAE Conference Brochure
Armoured Vehicles UAE Conference Brochure
 
Ids ips
Ids ipsIds ips
Ids ips
 
Stanford ml neuralnetwork
Stanford ml neuralnetworkStanford ml neuralnetwork
Stanford ml neuralnetwork
 
Scala@SmartNews_20150221
Scala@SmartNews_20150221Scala@SmartNews_20150221
Scala@SmartNews_20150221
 

Último

👉Chandigarh Call Girls 📞Book Now📞👉 9878799926 👉Zirakpur Call Girl Service No ...
👉Chandigarh Call Girls 📞Book Now📞👉 9878799926 👉Zirakpur Call Girl Service No ...👉Chandigarh Call Girls 📞Book Now📞👉 9878799926 👉Zirakpur Call Girl Service No ...
👉Chandigarh Call Girls 📞Book Now📞👉 9878799926 👉Zirakpur Call Girl Service No ...rajveerescorts2022
 
VIP 💞🌷Call Girls In Karnal 08168329307 Escorts Service Nilokheri Call Girls
VIP 💞🌷Call Girls In Karnal 08168329307 Escorts Service Nilokheri Call GirlsVIP 💞🌷Call Girls In Karnal 08168329307 Escorts Service Nilokheri Call Girls
VIP 💞🌷Call Girls In Karnal 08168329307 Escorts Service Nilokheri Call GirlsApsara Of India
 
Top 10 Moisturising Cream Brands In India - Stelon Biotech
Top 10 Moisturising Cream Brands In India - Stelon BiotechTop 10 Moisturising Cream Brands In India - Stelon Biotech
Top 10 Moisturising Cream Brands In India - Stelon BiotechStelon Biotech
 
👉Chandigarh Call Girls 📞Book Now📞👉 9878799926 👉Zirakpur Call Girl Service No ...
👉Chandigarh Call Girls 📞Book Now📞👉 9878799926 👉Zirakpur Call Girl Service No ...👉Chandigarh Call Girls 📞Book Now📞👉 9878799926 👉Zirakpur Call Girl Service No ...
👉Chandigarh Call Girls 📞Book Now📞👉 9878799926 👉Zirakpur Call Girl Service No ...rajveerescorts2022
 
Nalasopara Call Girls Services 9892124323 Home and Hotel Delivery Free
Nalasopara Call Girls Services 9892124323 Home and Hotel Delivery FreeNalasopara Call Girls Services 9892124323 Home and Hotel Delivery Free
Nalasopara Call Girls Services 9892124323 Home and Hotel Delivery FreePooja Nehwal
 
💞Call Girls In Sonipat 08168329307 Sonipat Kundli GTK Bypass EsCoRt Service
💞Call Girls In Sonipat 08168329307 Sonipat Kundli GTK Bypass EsCoRt Service💞Call Girls In Sonipat 08168329307 Sonipat Kundli GTK Bypass EsCoRt Service
💞Call Girls In Sonipat 08168329307 Sonipat Kundli GTK Bypass EsCoRt ServiceApsara Of India
 
UDAIPUR CALL GIRLS 96O287O969 CALL GIRL IN UDAIPUR ESCORT SERVICE
UDAIPUR CALL GIRLS 96O287O969 CALL GIRL IN UDAIPUR ESCORT SERVICEUDAIPUR CALL GIRLS 96O287O969 CALL GIRL IN UDAIPUR ESCORT SERVICE
UDAIPUR CALL GIRLS 96O287O969 CALL GIRL IN UDAIPUR ESCORT SERVICEApsara Of India
 
"Maximizing your savings:The power of financial planning".pptx
"Maximizing your savings:The power of financial planning".pptx"Maximizing your savings:The power of financial planning".pptx
"Maximizing your savings:The power of financial planning".pptxsadiisadiimano
 
Fun Call Girls In Yamunanagar 08168329307 Jagadhri Escort Services
Fun Call Girls In Yamunanagar 08168329307 Jagadhri Escort ServicesFun Call Girls In Yamunanagar 08168329307 Jagadhri Escort Services
Fun Call Girls In Yamunanagar 08168329307 Jagadhri Escort ServicesApsara Of India
 
Chandigarh Escorts Service 📞9915851334📞 Just📲 Call Rajveer Chandigarh Call Gi...
Chandigarh Escorts Service 📞9915851334📞 Just📲 Call Rajveer Chandigarh Call Gi...Chandigarh Escorts Service 📞9915851334📞 Just📲 Call Rajveer Chandigarh Call Gi...
Chandigarh Escorts Service 📞9915851334📞 Just📲 Call Rajveer Chandigarh Call Gi...rajveermohali2022
 
Night 7k to 12k Chennai Call Girls 👉👉 8617697112⭐⭐ 100% Genuine Escort Servic...
Night 7k to 12k Chennai Call Girls 👉👉 8617697112⭐⭐ 100% Genuine Escort Servic...Night 7k to 12k Chennai Call Girls 👉👉 8617697112⭐⭐ 100% Genuine Escort Servic...
Night 7k to 12k Chennai Call Girls 👉👉 8617697112⭐⭐ 100% Genuine Escort Servic...Nitya salvi
 
Call Girls Udaipur Just Call 9602870969 Top Class Call Girl Service Available
Call Girls Udaipur Just Call 9602870969 Top Class Call Girl Service AvailableCall Girls Udaipur Just Call 9602870969 Top Class Call Girl Service Available
Call Girls Udaipur Just Call 9602870969 Top Class Call Girl Service AvailableApsara Of India
 
New Call Girls In Panipat 08168329307 Shamli Israna Escorts Service
New Call Girls In Panipat 08168329307 Shamli Israna Escorts ServiceNew Call Girls In Panipat 08168329307 Shamli Israna Escorts Service
New Call Girls In Panipat 08168329307 Shamli Israna Escorts ServiceApsara Of India
 
💗📲09602870969💕-Royal Escorts in Udaipur Call Girls Service Udaipole-Fateh Sag...
💗📲09602870969💕-Royal Escorts in Udaipur Call Girls Service Udaipole-Fateh Sag...💗📲09602870969💕-Royal Escorts in Udaipur Call Girls Service Udaipole-Fateh Sag...
💗📲09602870969💕-Royal Escorts in Udaipur Call Girls Service Udaipole-Fateh Sag...Apsara Of India
 
Call girls in Vashi Services : 9167673311 Free Delivery 24x7 at Your Doorstep
Call girls in Vashi Services :  9167673311 Free Delivery 24x7 at Your DoorstepCall girls in Vashi Services :  9167673311 Free Delivery 24x7 at Your Doorstep
Call girls in Vashi Services : 9167673311 Free Delivery 24x7 at Your DoorstepPooja Nehwal
 
Call Girls in Bangalore Prachi 💋9136956627 Bangalore Call Girls
Call Girls in  Bangalore Prachi 💋9136956627 Bangalore Call GirlsCall Girls in  Bangalore Prachi 💋9136956627 Bangalore Call Girls
Call Girls in Bangalore Prachi 💋9136956627 Bangalore Call GirlsPinki Misra
 
All Hotel Karnal Call Girls 08168329307 Noor Mahal Karnal Escort Service
All Hotel Karnal Call Girls 08168329307 Noor Mahal Karnal Escort ServiceAll Hotel Karnal Call Girls 08168329307 Noor Mahal Karnal Escort Service
All Hotel Karnal Call Girls 08168329307 Noor Mahal Karnal Escort ServiceApsara Of India
 
Russian CalDeed Circle Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Esco...
Russian CalDeed Circle Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Esco...Russian CalDeed Circle Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Esco...
Russian CalDeed Circle Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Esco...Damini Dixit
 
High Class Call Girls in Bangalore 📱9136956627📱
High Class Call Girls in Bangalore 📱9136956627📱High Class Call Girls in Bangalore 📱9136956627📱
High Class Call Girls in Bangalore 📱9136956627📱Pinki Misra
 
❤️Call Girls In Chandigarh 08168329307 Dera Bassi Zirakpur Panchkula Escort S...
❤️Call Girls In Chandigarh 08168329307 Dera Bassi Zirakpur Panchkula Escort S...❤️Call Girls In Chandigarh 08168329307 Dera Bassi Zirakpur Panchkula Escort S...
❤️Call Girls In Chandigarh 08168329307 Dera Bassi Zirakpur Panchkula Escort S...Apsara Of India
 

Último (20)

👉Chandigarh Call Girls 📞Book Now📞👉 9878799926 👉Zirakpur Call Girl Service No ...
👉Chandigarh Call Girls 📞Book Now📞👉 9878799926 👉Zirakpur Call Girl Service No ...👉Chandigarh Call Girls 📞Book Now📞👉 9878799926 👉Zirakpur Call Girl Service No ...
👉Chandigarh Call Girls 📞Book Now📞👉 9878799926 👉Zirakpur Call Girl Service No ...
 
VIP 💞🌷Call Girls In Karnal 08168329307 Escorts Service Nilokheri Call Girls
VIP 💞🌷Call Girls In Karnal 08168329307 Escorts Service Nilokheri Call GirlsVIP 💞🌷Call Girls In Karnal 08168329307 Escorts Service Nilokheri Call Girls
VIP 💞🌷Call Girls In Karnal 08168329307 Escorts Service Nilokheri Call Girls
 
Top 10 Moisturising Cream Brands In India - Stelon Biotech
Top 10 Moisturising Cream Brands In India - Stelon BiotechTop 10 Moisturising Cream Brands In India - Stelon Biotech
Top 10 Moisturising Cream Brands In India - Stelon Biotech
 
👉Chandigarh Call Girls 📞Book Now📞👉 9878799926 👉Zirakpur Call Girl Service No ...
👉Chandigarh Call Girls 📞Book Now📞👉 9878799926 👉Zirakpur Call Girl Service No ...👉Chandigarh Call Girls 📞Book Now📞👉 9878799926 👉Zirakpur Call Girl Service No ...
👉Chandigarh Call Girls 📞Book Now📞👉 9878799926 👉Zirakpur Call Girl Service No ...
 
Nalasopara Call Girls Services 9892124323 Home and Hotel Delivery Free
Nalasopara Call Girls Services 9892124323 Home and Hotel Delivery FreeNalasopara Call Girls Services 9892124323 Home and Hotel Delivery Free
Nalasopara Call Girls Services 9892124323 Home and Hotel Delivery Free
 
💞Call Girls In Sonipat 08168329307 Sonipat Kundli GTK Bypass EsCoRt Service
💞Call Girls In Sonipat 08168329307 Sonipat Kundli GTK Bypass EsCoRt Service💞Call Girls In Sonipat 08168329307 Sonipat Kundli GTK Bypass EsCoRt Service
💞Call Girls In Sonipat 08168329307 Sonipat Kundli GTK Bypass EsCoRt Service
 
UDAIPUR CALL GIRLS 96O287O969 CALL GIRL IN UDAIPUR ESCORT SERVICE
UDAIPUR CALL GIRLS 96O287O969 CALL GIRL IN UDAIPUR ESCORT SERVICEUDAIPUR CALL GIRLS 96O287O969 CALL GIRL IN UDAIPUR ESCORT SERVICE
UDAIPUR CALL GIRLS 96O287O969 CALL GIRL IN UDAIPUR ESCORT SERVICE
 
"Maximizing your savings:The power of financial planning".pptx
"Maximizing your savings:The power of financial planning".pptx"Maximizing your savings:The power of financial planning".pptx
"Maximizing your savings:The power of financial planning".pptx
 
Fun Call Girls In Yamunanagar 08168329307 Jagadhri Escort Services
Fun Call Girls In Yamunanagar 08168329307 Jagadhri Escort ServicesFun Call Girls In Yamunanagar 08168329307 Jagadhri Escort Services
Fun Call Girls In Yamunanagar 08168329307 Jagadhri Escort Services
 
Chandigarh Escorts Service 📞9915851334📞 Just📲 Call Rajveer Chandigarh Call Gi...
Chandigarh Escorts Service 📞9915851334📞 Just📲 Call Rajveer Chandigarh Call Gi...Chandigarh Escorts Service 📞9915851334📞 Just📲 Call Rajveer Chandigarh Call Gi...
Chandigarh Escorts Service 📞9915851334📞 Just📲 Call Rajveer Chandigarh Call Gi...
 
Night 7k to 12k Chennai Call Girls 👉👉 8617697112⭐⭐ 100% Genuine Escort Servic...
Night 7k to 12k Chennai Call Girls 👉👉 8617697112⭐⭐ 100% Genuine Escort Servic...Night 7k to 12k Chennai Call Girls 👉👉 8617697112⭐⭐ 100% Genuine Escort Servic...
Night 7k to 12k Chennai Call Girls 👉👉 8617697112⭐⭐ 100% Genuine Escort Servic...
 
Call Girls Udaipur Just Call 9602870969 Top Class Call Girl Service Available
Call Girls Udaipur Just Call 9602870969 Top Class Call Girl Service AvailableCall Girls Udaipur Just Call 9602870969 Top Class Call Girl Service Available
Call Girls Udaipur Just Call 9602870969 Top Class Call Girl Service Available
 
New Call Girls In Panipat 08168329307 Shamli Israna Escorts Service
New Call Girls In Panipat 08168329307 Shamli Israna Escorts ServiceNew Call Girls In Panipat 08168329307 Shamli Israna Escorts Service
New Call Girls In Panipat 08168329307 Shamli Israna Escorts Service
 
💗📲09602870969💕-Royal Escorts in Udaipur Call Girls Service Udaipole-Fateh Sag...
💗📲09602870969💕-Royal Escorts in Udaipur Call Girls Service Udaipole-Fateh Sag...💗📲09602870969💕-Royal Escorts in Udaipur Call Girls Service Udaipole-Fateh Sag...
💗📲09602870969💕-Royal Escorts in Udaipur Call Girls Service Udaipole-Fateh Sag...
 
Call girls in Vashi Services : 9167673311 Free Delivery 24x7 at Your Doorstep
Call girls in Vashi Services :  9167673311 Free Delivery 24x7 at Your DoorstepCall girls in Vashi Services :  9167673311 Free Delivery 24x7 at Your Doorstep
Call girls in Vashi Services : 9167673311 Free Delivery 24x7 at Your Doorstep
 
Call Girls in Bangalore Prachi 💋9136956627 Bangalore Call Girls
Call Girls in  Bangalore Prachi 💋9136956627 Bangalore Call GirlsCall Girls in  Bangalore Prachi 💋9136956627 Bangalore Call Girls
Call Girls in Bangalore Prachi 💋9136956627 Bangalore Call Girls
 
All Hotel Karnal Call Girls 08168329307 Noor Mahal Karnal Escort Service
All Hotel Karnal Call Girls 08168329307 Noor Mahal Karnal Escort ServiceAll Hotel Karnal Call Girls 08168329307 Noor Mahal Karnal Escort Service
All Hotel Karnal Call Girls 08168329307 Noor Mahal Karnal Escort Service
 
Russian CalDeed Circle Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Esco...
Russian CalDeed Circle Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Esco...Russian CalDeed Circle Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Esco...
Russian CalDeed Circle Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Esco...
 
High Class Call Girls in Bangalore 📱9136956627📱
High Class Call Girls in Bangalore 📱9136956627📱High Class Call Girls in Bangalore 📱9136956627📱
High Class Call Girls in Bangalore 📱9136956627📱
 
❤️Call Girls In Chandigarh 08168329307 Dera Bassi Zirakpur Panchkula Escort S...
❤️Call Girls In Chandigarh 08168329307 Dera Bassi Zirakpur Panchkula Escort S...❤️Call Girls In Chandigarh 08168329307 Dera Bassi Zirakpur Panchkula Escort S...
❤️Call Girls In Chandigarh 08168329307 Dera Bassi Zirakpur Panchkula Escort S...
 

Pfds 5 2+6_4_2

  • 1. PFDS §5.2+6.4.2 Queues @shtaag 2012年5月19日土曜日
  • 2. First... http://www.kmonos.net/pub/Presen/PFDS.pdf 2012年5月19日土曜日
  • 3. FIFO Queue(2リストキュー) type foo Queue = foo list x foo list fun head (x :: f, r) = x O(1) fun tail (x :: f, r) = (f, r) O(1) fun snoc ((f, r), x) = (f, x :: r) O(1) リスト終端への挿入にconsを用いるため、 リスト後半をreverseして保持 2012年5月19日土曜日
  • 4. FIFO Queue(2リストキュー) invariant to maintain fはrが[ ]の時のみ[ ] これがないとf = [ ]時にheadがr終端からの取り出 しになりheadがO(n)かかる 2012年5月19日土曜日
  • 5. FIFO Queue(2リストキュー) to maintain invariant... fun checkf ([ ], r) = (rev r, [ ]) | checkf q = q fun snoc ((f, r), x) = checkf (f, x :: r) fun tail (x :: f, r) = checkf (f, r) 2012年5月19日土曜日
  • 6. Banker’s method snoc = 1 step + 1 credit tail (w/o reverse) = 1 step tail (w/ reverse) = (m+1) steps - m credits tail . tail . tail . snoc 3 . snoc 2 . snoc 1 2012年5月19日土曜日
  • 7. real amortized snoc 1 -> [] [1] -> [1] [] 2 2 checkf w/ 1 step snoc 2 -> [1] [2] 1 2 +1 snoc 3 -> [1] [3,2] 1 2 +1 tail -> [] [3,2] -> [2,3] [] 3 1 -2 checkf w/ 2 step tail -> [3] [] 1 1 tail -> [] [] 1 1 9 9 2012年5月19日土曜日
  • 8. real amortized snoc 1 -> [] [1] -> [1] [] 2 2 snoc 2 -> [1] [2] 1 2 +1 snoc 3 -> [1] [3,2] 1 2 +1 tail -> [] [3,2] -> [2,3] [] 3 1 -2 tail -> [3] [] 1 1 積み立てておいたcreditを消費 tail -> [] [] 1 1 9 9 2012年5月19日土曜日
  • 9. Physicist’s method Φ = length of the rear list snoc = 1 step + 1 potential (for 1 elem) tail (w/o reverse) = 1 step tail (w/ reverse) = (m+1) steps - m potentials 2012年5月19日土曜日
  • 10. real amortized snoc 1 -> [] [1] -> [1] [] 2 2 snoc 2 -> [1] [2] 1 2 +1 snoc 3 -> [1] [3,2] 1 2 +1 tail -> [] [3,2] -> [2,3] [] 3 1 -2 tail -> [3] [] 1 1 tail -> [] [] 1 1 9 9 2012年5月19日土曜日
  • 11. §6.4.2 with Lazy Evaluation O(1) in amortized time 2012年5月19日土曜日
  • 12. §6.4.2 with Lazy Evaluation Queue with O(1) amortized time. Persistent Lazy Evaluation Strict Working Copy 2012年5月19日土曜日
  • 13. §6.4.2 with Lazy Evaluation with the Physicist’s Method. change in shared potential strict cost (non-amortized) cost amortized unshared cost cost 2012年5月19日土曜日
  • 14. §6.4.2 with Lazy Evaluation with the Physicist’s Method. change in potential strict paid (non-amortized) shared cost cost paid shared cost = actually executed cost 2012年5月19日土曜日
  • 15. §6.4.2 with Lazy Evaluation with the Physicist’s Method. max potential = max shared cost ??? change in potential strict paid (non-amortized) shared cost cost 2012年5月19日土曜日
  • 16. Implementation of PhysicistsQueue type a Queue = a list x int x a list susp x int x a list 2012年5月19日土曜日
  • 17. type a Queue = a list x int x a list susp x int x a list suspended front list + ordinal rear list lengths for front and rear lists to calculate the diff of front and rear lengths to guarantee front >= rear working copy of front list front is suspended, so necessary to keep the access to the prefix for head queries. 2012年5月19日土曜日
  • 18. Potential length of working copy diff of front and rear lengths if those values are = 0, then rotation happens definition of potential Ψ(q) = min (2|w|, |f| - |r|) 2012年5月19日土曜日
  • 19. if potential = 0 [ 5, 8] [ 5, 8] [ 2, 4] snoc unshared = 1 2012年5月19日土曜日
  • 20. if potential = 0 [ 5, 8] [ 5, 8] [ 2, 4] snoc shared cost of rotation = 2m + 1 force suspended front ++ rear 2012年5月19日土曜日
  • 21. if potential = 0 [ 5, 8] [ 5, 8] [ 2, 4] snoc change of potential = + 2m create debt = accumulated debt 2012年5月19日土曜日
  • 22. if potential = 0 [ 5, 8] [ 5, 8] [ 2, 4] snoc complete cost = 2 unshared = 1 shared = 2m + 1 change in potential = 2m 2012年5月19日土曜日
  • 23. if potential > 0 [ 5, 8, 2, 4] [ 5, 8, 2, 4] [ 1, 3] potential = 2 snoc unshared = 1 change in potential = -1 2012年5月19日土曜日
  • 24. Therefore... snoc is O(1) amortized time the cost is 2 or 4 2012年5月19日土曜日
  • 25. if potential = 0 [ 5, 8] [ 5, 8] [ 2, 4] tail [ 8] [ 8] [ 2, 4] 2012年5月19日土曜日
  • 26. if potential = 0 [ 5, 8] [ 5, 8] [ 2, 4] tail unshared cost = 2 shared cost = 2m + 1 change in potential = 2m 2012年5月19日土曜日
  • 27. if potential > 0 [ 5, 8, 2, 4] [ 5, 8, 2, 4] [ 1, 3] potential = 2 tail [ 8, 2, 4] [ 8, 2, 4] [ 1, 3] 2012年5月19日土曜日
  • 28. if potential > 0 [ 5, 8, 2, 4] [ 5, 8, 2, 4] [ 1, 3] potential = 2 tail unshared = 1 (from working copy) paid shared = 1 (from front) change in potential = -1 for w and -1 for (f-r) 2012年5月19日土曜日
  • 29. Therefore... tail is in O(1) amortized time the cost is 4 or 3 2012年5月19日土曜日
  • 30. Theorem 6.2 The amortized costs of snoc and tail are at most 2 and 4, respectively This leads to that every operation is O(1) order. 2012年5月19日土曜日
  • 31. snoc without rotation snoc ((w, lenf, f, lenr, r), x) = check (w, lenf, f , lenr+1, x :: r) cost = 1 & decrease in potential = 1 operation for |f| - |r| amortized cost = 1 - (-1) =2 2012年5月19日土曜日
  • 32. tail without rotation tail (x :: w, lenf, f, lenr, r) = check (w, lenf-1, $tl (force f), lenr, r) cost = 2 & decrease in potential = 2 operation for |w| & operation for |f| - |r| amortized cost = 2 - (-2) =4 2012年5月19日土曜日
  • 33. With Rotation |f| = m and |r| = m + 1 shared cost of rotation = 2m + 1 potential of resulting queue = 2|w| = 2m amortized cost of snoc 1 + (2m + 1) - 2m = 2 amortized cost of tail 2 + (2m + 1) - 2m = 3 2012年5月19日土曜日