SlideShare a Scribd company logo
1 of 44
Download to read offline
PFDS 11.2
Catenable Double-Ended
        Queues
~ using implicit recursive slowdown ~

                              @rf0444
Simple Implementation
data Cat a
 = Shallow (Deq a)
 | Deep (Deq a) (Cat (Deq a)) (Deq a)
Simple Implementation



         ++
Simple Implementation

                cons




  snoc
Simple Implementation
Simple Implementation



(        ++        )
Simple Implementation



(          ++                  )

      再帰        O(min(log n1, log n2))
using compound elements
data Cat a
 = Shallow (Deq a)
 | Deep (Deq a) (Cat (Ele a)) (Deq a) (Cat (Ele a)) (Deq a)
using compound elements
data Ele a
 = Simple (Deq a)
 | Compound (Deq a) (Cat (Ele a)) (Deq a)
using compound elements




          ++
using compound elements
using compound elements
using compound elements




  snoc            cons
using compound elements
using compound elements
using compound elements
tail

1. f が 4 要素以上             f a m b r

2. a の先頭が Simple

3. a の先頭が Compound

4. a が空、b の先頭が Simple

5. a が空、b の先頭が Compound

6. a も b も空
using compound elements
tail (1)
using compound elements
tail (1)
using compound elements
tail (2)
using compound elements
tail (2)
using compound elements
tail (2)
using compound elements
tail (3)
using compound elements
tail (3)
using compound elements
tail (3)
using compound elements
tail (3)
using compound elements
tail (3)




              ++
using compound elements
tail (3)
using compound elements
tail (3)
using compound elements
tail (4)




           空
using compound elements
tail (4)




           空
using compound elements
tail (4)
using compound elements
tail (4)
using compound elements
tail (4)




           空
using compound elements
tail (5)




           空
using compound elements
tail (5)




           空
using compound elements
tail (5)
using compound elements
tail (5)
using compound elements
tail (5)
using compound elements
tail (5)
using compound elements
tail (6)




             空   空
using compound elements
tail (6)




             空   空
using compound elements
tail (6)




            *どちらかのサイズが 3 以下なら、くっつけて Shallow
using compound elements
tail (6)
using compound elements
tail (6)




             空   空

More Related Content

What's hot

[Question Paper] Linux Administration (60:40 Pattern) [October / 2013]
[Question Paper] Linux Administration (60:40 Pattern) [October / 2013][Question Paper] Linux Administration (60:40 Pattern) [October / 2013]
[Question Paper] Linux Administration (60:40 Pattern) [October / 2013]Mumbai B.Sc.IT Study
 
Time complexity of union find
Time complexity of union findTime complexity of union find
Time complexity of union findWei (Terence) Li
 
The Ring programming language version 1.9 book - Part 30 of 210
The Ring programming language version 1.9 book - Part 30 of 210The Ring programming language version 1.9 book - Part 30 of 210
The Ring programming language version 1.9 book - Part 30 of 210Mahmoud Samir Fayed
 
EC202 SIGNALS & SYSTEMS PREVIOUS QUESTION PAPER
EC202 SIGNALS & SYSTEMS PREVIOUS QUESTION PAPEREC202 SIGNALS & SYSTEMS PREVIOUS QUESTION PAPER
EC202 SIGNALS & SYSTEMS PREVIOUS QUESTION PAPERVISHNUPRABHANKAIMAL
 
Python 101 language features and functional programming
Python 101 language features and functional programmingPython 101 language features and functional programming
Python 101 language features and functional programmingLukasz Dynowski
 
A peek on numerical programming in perl and python e christopher dyken 2005
A peek on numerical programming in perl and python  e christopher dyken  2005A peek on numerical programming in perl and python  e christopher dyken  2005
A peek on numerical programming in perl and python e christopher dyken 2005Jules Krdenas
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort AlgorithmLemia Algmri
 
Db31463471
Db31463471Db31463471
Db31463471IJMER
 
Deep dumpster diving 2010
Deep dumpster diving 2010Deep dumpster diving 2010
Deep dumpster diving 2010RonnBlack
 
Applications of datastructures
Applications of datastructuresApplications of datastructures
Applications of datastructuresRatsietsi Mokete
 
19. algorithms and-complexity
19. algorithms and-complexity19. algorithms and-complexity
19. algorithms and-complexityashishtinku
 
Study Kc - Spaces Via ω-Open Sets
Study Kc - Spaces Via ω-Open SetsStudy Kc - Spaces Via ω-Open Sets
Study Kc - Spaces Via ω-Open Setspaperpublications3
 
The Ring programming language version 1.5.2 book - Part 34 of 181
The Ring programming language version 1.5.2 book - Part 34 of 181The Ring programming language version 1.5.2 book - Part 34 of 181
The Ring programming language version 1.5.2 book - Part 34 of 181Mahmoud Samir Fayed
 

What's hot (20)

Alg2 lesson 7-7
Alg2 lesson 7-7Alg2 lesson 7-7
Alg2 lesson 7-7
 
[Question Paper] Linux Administration (60:40 Pattern) [October / 2013]
[Question Paper] Linux Administration (60:40 Pattern) [October / 2013][Question Paper] Linux Administration (60:40 Pattern) [October / 2013]
[Question Paper] Linux Administration (60:40 Pattern) [October / 2013]
 
Conductance
ConductanceConductance
Conductance
 
Lec23
Lec23Lec23
Lec23
 
Lec24
Lec24Lec24
Lec24
 
Time complexity of union find
Time complexity of union findTime complexity of union find
Time complexity of union find
 
The Ring programming language version 1.9 book - Part 30 of 210
The Ring programming language version 1.9 book - Part 30 of 210The Ring programming language version 1.9 book - Part 30 of 210
The Ring programming language version 1.9 book - Part 30 of 210
 
Lec25
Lec25Lec25
Lec25
 
EC202 SIGNALS & SYSTEMS PREVIOUS QUESTION PAPER
EC202 SIGNALS & SYSTEMS PREVIOUS QUESTION PAPEREC202 SIGNALS & SYSTEMS PREVIOUS QUESTION PAPER
EC202 SIGNALS & SYSTEMS PREVIOUS QUESTION PAPER
 
Python 101 language features and functional programming
Python 101 language features and functional programmingPython 101 language features and functional programming
Python 101 language features and functional programming
 
A peek on numerical programming in perl and python e christopher dyken 2005
A peek on numerical programming in perl and python  e christopher dyken  2005A peek on numerical programming in perl and python  e christopher dyken  2005
A peek on numerical programming in perl and python e christopher dyken 2005
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
ThreeTen
ThreeTenThreeTen
ThreeTen
 
Db31463471
Db31463471Db31463471
Db31463471
 
Deep dumpster diving 2010
Deep dumpster diving 2010Deep dumpster diving 2010
Deep dumpster diving 2010
 
竝行
竝行竝行
竝行
 
Applications of datastructures
Applications of datastructuresApplications of datastructures
Applications of datastructures
 
19. algorithms and-complexity
19. algorithms and-complexity19. algorithms and-complexity
19. algorithms and-complexity
 
Study Kc - Spaces Via ω-Open Sets
Study Kc - Spaces Via ω-Open SetsStudy Kc - Spaces Via ω-Open Sets
Study Kc - Spaces Via ω-Open Sets
 
The Ring programming language version 1.5.2 book - Part 34 of 181
The Ring programming language version 1.5.2 book - Part 34 of 181The Ring programming language version 1.5.2 book - Part 34 of 181
The Ring programming language version 1.5.2 book - Part 34 of 181
 

Viewers also liked

Tapl 5
Tapl 5Tapl 5
Tapl 5rf0444
 
PFDS 10.1.2
PFDS 10.1.2PFDS 10.1.2
PFDS 10.1.2rf0444
 
20120829_TaPL8
20120829_TaPL820120829_TaPL8
20120829_TaPL85th_person
 
Haskellday rf
Haskellday rfHaskellday rf
Haskellday rfrf0444
 
TaPL名古屋 Chap2
TaPL名古屋 Chap2TaPL名古屋 Chap2
TaPL名古屋 Chap2Keita Saitou
 
TAPL 勉強会(紹介編)
TAPL 勉強会(紹介編)TAPL 勉強会(紹介編)
TAPL 勉強会(紹介編)none_toka
 
TAPL勉強会 第1章 (2012-07-17)
TAPL勉強会 第1章 (2012-07-17)TAPL勉強会 第1章 (2012-07-17)
TAPL勉強会 第1章 (2012-07-17)none_toka
 
勉強か?趣味か?人生か?―プログラミングコンテストとは
勉強か?趣味か?人生か?―プログラミングコンテストとは勉強か?趣味か?人生か?―プログラミングコンテストとは
勉強か?趣味か?人生か?―プログラミングコンテストとはTakuya Akiba
 

Viewers also liked (9)

Tapl 5
Tapl 5Tapl 5
Tapl 5
 
PFDS 10.1.2
PFDS 10.1.2PFDS 10.1.2
PFDS 10.1.2
 
20120829_TaPL8
20120829_TaPL820120829_TaPL8
20120829_TaPL8
 
Haskellday rf
Haskellday rfHaskellday rf
Haskellday rf
 
SWF
SWFSWF
SWF
 
TaPL名古屋 Chap2
TaPL名古屋 Chap2TaPL名古屋 Chap2
TaPL名古屋 Chap2
 
TAPL 勉強会(紹介編)
TAPL 勉強会(紹介編)TAPL 勉強会(紹介編)
TAPL 勉強会(紹介編)
 
TAPL勉強会 第1章 (2012-07-17)
TAPL勉強会 第1章 (2012-07-17)TAPL勉強会 第1章 (2012-07-17)
TAPL勉強会 第1章 (2012-07-17)
 
勉強か?趣味か?人生か?―プログラミングコンテストとは
勉強か?趣味か?人生か?―プログラミングコンテストとは勉強か?趣味か?人生か?―プログラミングコンテストとは
勉強か?趣味か?人生か?―プログラミングコンテストとは
 

More from rf0444

FRP in Practice
FRP in PracticeFRP in Practice
FRP in Practicerf0444
 
Start FRP
Start FRPStart FRP
Start FRPrf0444
 
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
 
PFDS 7.4
PFDS 7.4PFDS 7.4
PFDS 7.4rf0444
 
PFDS 6.4.3
PFDS 6.4.3PFDS 6.4.3
PFDS 6.4.3rf0444
 

More from rf0444 (7)

FRP in Practice
FRP in PracticeFRP in Practice
FRP in Practice
 
Start FRP
Start FRPStart FRP
Start FRP
 
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
 
PFDS 7.4
PFDS 7.4PFDS 7.4
PFDS 7.4
 
PFDS 6.4.3
PFDS 6.4.3PFDS 6.4.3
PFDS 6.4.3
 

PFDS 11.2.2