SlideShare une entreprise Scribd logo
1  sur  7
Télécharger pour lire hors ligne
Leftist Heap




Definition
A Leftist (min)Heap is a binary tree that satisfies the follow-ing conditions.
If X is a node and L and R are its left and right children, then:
    –      X.value ≤ L.value
    –      X.value ≤ R.value
    –      null path length of L ≥ null path length of R

where the null path length of a node is the shortest distance between
from that node to a descendant with 0 or 1 child.
If a node is null, its null path length is −1.
Example: Null Path Length

                                                  •node 4 violates leftist heap property
                                             4     fix by swapping children


                              8    0                           19   1



             12       1                               27   0               20   0


    15   0                25      0          43   0

    node          4       8       19   12   15   25    27      20   43
    npl           1       0        1   1     0    0        0   0      0
Example: Null Path Length


                                        4


                     19   1                                8        0



            27   0             20   0            12    1



      43    0                           15   0             25   0

      node       4   8    19   12   15       25       27   20       43
      npl        1   0     1   1        0    0         0    0           0
FromListの実装
(言語ゲーム 2009-11-23 Leftist Heap (http://d.hatena.ne.jp/propella/20091123/p1) のサンプルプログラムに追加して使って下さい)



   -- Copied from CS231 Algorithm Prof. Lyn Turbak Wellesley College

   -- make a leftist heap with one node.
   singleton x = T 1 x E E

   -- make a leftist heap from list
   fromList :: Ord a => [a] -> Heap a
   fromList [] = E
   fromList xs = mergeLoop (map singleton xs)
     where
      mergeLoop [] = error "shouldnt: mergeLoop []"
      mergeLoop [t] = t
      mergeLoop ts = mergeLoop(mergePairs ts)
      mergePairs [] = []
      mergePairs [t] = [t]
      mergePairs (t1:t2:ts) = (merge t1 t2):(mergePairs ts)

   prop_Heap2 :: [Int] -> Bool
   prop_Heap2 xs = isSorted (heapToList (fromList xs))

   test2 = verboseCheck prop_Heap2
動作




3段階目




2段階目




1段階目
fromListの計算量がO(n)であること

 n   n          n        2          n          n
   + 2 log 2 + 3 log 2 + ⋯ + (log n+1) log 2
 2   2          2               2
                         2              n
   n   n log 2    log 2         log 2
 = + (         +       2   + ⋯+      n    )
   2   2 2           2             2
                      2             n
     1 log 2    log 2         log 2
   ( (        +     2
                         +⋯+      n
                                       ) < 1 よ り)
     2 2          2             2
   n       3n
 < +n=
   2        2
参考文献

・Clemson University CpSc 212, Section 001 (Roy P. Pargas)
http://www.cs.clemson.edu/~pargas/courses/cs212/common/notes/ppt/1
4LeftistSkewHeaps.ppt
 p.3, p.6-7

・Wellesley College CS 231 2001 (Lyn Turbak)
http://cs.wellesley.edu/~cs231/fall01/leftist.pdf
 p.2, p.5

・言語ゲーム 2009-11-23 Leftist Heap
http://d.hatena.ne.jp/propella/20091123/p1

Contenu connexe

Tendances

SPIRE2013-tabei20131009
SPIRE2013-tabei20131009SPIRE2013-tabei20131009
SPIRE2013-tabei20131009
Yasuo Tabei
 
Gaucheで本を作る
Gaucheで本を作るGaucheで本を作る
Gaucheで本を作る
guest7a66b8
 

Tendances (14)

boyd 3.1
boyd 3.1boyd 3.1
boyd 3.1
 
GoでKVSを書けるのか
GoでKVSを書けるのかGoでKVSを書けるのか
GoでKVSを書けるのか
 
MATHS SYMBOLS - #8 - LOGARITHMS, CHANGE of BASE - PROOFS
MATHS SYMBOLS - #8 - LOGARITHMS, CHANGE of BASE - PROOFSMATHS SYMBOLS - #8 - LOGARITHMS, CHANGE of BASE - PROOFS
MATHS SYMBOLS - #8 - LOGARITHMS, CHANGE of BASE - PROOFS
 
Interactive Power Point Presentation
Interactive Power Point PresentationInteractive Power Point Presentation
Interactive Power Point Presentation
 
Rcpp11 useR2014
Rcpp11 useR2014Rcpp11 useR2014
Rcpp11 useR2014
 
Rcpp11 genentech
Rcpp11 genentechRcpp11 genentech
Rcpp11 genentech
 
ALPSチュートリアル
ALPSチュートリアルALPSチュートリアル
ALPSチュートリアル
 
When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)
 
Java program-to-calculate-area-and-circumference-of-circle
Java program-to-calculate-area-and-circumference-of-circleJava program-to-calculate-area-and-circumference-of-circle
Java program-to-calculate-area-and-circumference-of-circle
 
SdE 2: Le langage Python, Allocation de memoire
SdE 2: Le langage Python, Allocation de memoireSdE 2: Le langage Python, Allocation de memoire
SdE 2: Le langage Python, Allocation de memoire
 
SPIRE2013-tabei20131009
SPIRE2013-tabei20131009SPIRE2013-tabei20131009
SPIRE2013-tabei20131009
 
Activity Recognition Through Complex Event Processing: First Findings
Activity Recognition Through Complex Event Processing: First Findings Activity Recognition Through Complex Event Processing: First Findings
Activity Recognition Through Complex Event Processing: First Findings
 
Protecting C++
Protecting C++Protecting C++
Protecting C++
 
Gaucheで本を作る
Gaucheで本を作るGaucheで本を作る
Gaucheで本を作る
 

En vedette (7)

Advance Data Structure
Advance Data StructureAdvance Data Structure
Advance Data Structure
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithm
 
BTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTsBTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTs
 
Leftist heap
Leftist heapLeftist heap
Leftist heap
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci Heaps
 
Fibonacci Heap
Fibonacci HeapFibonacci Heap
Fibonacci Heap
 
Binomial heap presentation
Binomial heap presentationBinomial heap presentation
Binomial heap presentation
 

Similaire à Purely Functional Data Structures ex3.3 leftist heap

Data Structure Lecture 7
Data Structure Lecture 7Data Structure Lecture 7
Data Structure Lecture 7
Teksify
 
SEGMENTATION OF POLARIMETRIC SAR DATA WITH A MULTI-TEXTURE PRODUCT MODEL
SEGMENTATION OF POLARIMETRIC SAR DATA WITH A MULTI-TEXTURE PRODUCT MODELSEGMENTATION OF POLARIMETRIC SAR DATA WITH A MULTI-TEXTURE PRODUCT MODEL
SEGMENTATION OF POLARIMETRIC SAR DATA WITH A MULTI-TEXTURE PRODUCT MODEL
grssieee
 
Graph Algorithms Graph Algorithms Graph Algorithms
Graph Algorithms Graph Algorithms Graph AlgorithmsGraph Algorithms Graph Algorithms Graph Algorithms
Graph Algorithms Graph Algorithms Graph Algorithms
htttuneti
 

Similaire à Purely Functional Data Structures ex3.3 leftist heap (20)

Q
QQ
Q
 
Splay Tree Algorithm
Splay Tree AlgorithmSplay Tree Algorithm
Splay Tree Algorithm
 
Laplace transform
Laplace transformLaplace transform
Laplace transform
 
Interpolating evolutionary tracks of rapidly rotating stars - presentation
Interpolating evolutionary tracks of rapidly rotating stars - presentationInterpolating evolutionary tracks of rapidly rotating stars - presentation
Interpolating evolutionary tracks of rapidly rotating stars - presentation
 
Decyphering Rails 3
Decyphering Rails 3Decyphering Rails 3
Decyphering Rails 3
 
Estimation of the score vector and observed information matrix in intractable...
Estimation of the score vector and observed information matrix in intractable...Estimation of the score vector and observed information matrix in intractable...
Estimation of the score vector and observed information matrix in intractable...
 
Many electrons atoms_2012.12.04 (PDF with links
Many electrons atoms_2012.12.04 (PDF with linksMany electrons atoms_2012.12.04 (PDF with links
Many electrons atoms_2012.12.04 (PDF with links
 
ATPG of reversible circuits
ATPG of reversible circuitsATPG of reversible circuits
ATPG of reversible circuits
 
Data Structure Lecture 7
Data Structure Lecture 7Data Structure Lecture 7
Data Structure Lecture 7
 
Generic parallelization strategies for data assimilation
Generic parallelization strategies for data assimilationGeneric parallelization strategies for data assimilation
Generic parallelization strategies for data assimilation
 
Dancing Links: an educational pearl
Dancing Links: an educational pearlDancing Links: an educational pearl
Dancing Links: an educational pearl
 
Big o
Big oBig o
Big o
 
SEGMENTATION OF POLARIMETRIC SAR DATA WITH A MULTI-TEXTURE PRODUCT MODEL
SEGMENTATION OF POLARIMETRIC SAR DATA WITH A MULTI-TEXTURE PRODUCT MODELSEGMENTATION OF POLARIMETRIC SAR DATA WITH A MULTI-TEXTURE PRODUCT MODEL
SEGMENTATION OF POLARIMETRIC SAR DATA WITH A MULTI-TEXTURE PRODUCT MODEL
 
Graph Algorithms Graph Algorithms Graph Algorithms
Graph Algorithms Graph Algorithms Graph AlgorithmsGraph Algorithms Graph Algorithms Graph Algorithms
Graph Algorithms Graph Algorithms Graph Algorithms
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with Scala
 
Tail Probabilities for Randomized Program Runtimes via Martingales for Higher...
Tail Probabilities for Randomized Program Runtimes via Martingales for Higher...Tail Probabilities for Randomized Program Runtimes via Martingales for Higher...
Tail Probabilities for Randomized Program Runtimes via Martingales for Higher...
 
Week3 ap3421 2019_part1
Week3 ap3421 2019_part1Week3 ap3421 2019_part1
Week3 ap3421 2019_part1
 
7.tree
7.tree7.tree
7.tree
 
Meta-learning and the ELBO
Meta-learning and the ELBOMeta-learning and the ELBO
Meta-learning and the ELBO
 
Data sparse approximation of the Karhunen-Loeve expansion
Data sparse approximation of the Karhunen-Loeve expansionData sparse approximation of the Karhunen-Loeve expansion
Data sparse approximation of the Karhunen-Loeve expansion
 

Plus de Tetsuro Nagae

Plus de Tetsuro Nagae (7)

オブザーバビリティ、OpenTelemetryについて.pptx
オブザーバビリティ、OpenTelemetryについて.pptxオブザーバビリティ、OpenTelemetryについて.pptx
オブザーバビリティ、OpenTelemetryについて.pptx
 
RDBのインデックスについて.pptx
RDBのインデックスについて.pptxRDBのインデックスについて.pptx
RDBのインデックスについて.pptx
 
MySQL SQL tuning
MySQL SQL tuningMySQL SQL tuning
MySQL SQL tuning
 
Hoare論理
Hoare論理Hoare論理
Hoare論理
 
Purely functional data structures 8.2 日本語での説明
Purely functional data structures 8.2 日本語での説明Purely functional data structures 8.2 日本語での説明
Purely functional data structures 8.2 日本語での説明
 
Blueprintsについて
BlueprintsについてBlueprintsについて
Blueprintsについて
 
purely functional data structures 5.3 日本語での説明
purely functional data structures 5.3 日本語での説明purely functional data structures 5.3 日本語での説明
purely functional data structures 5.3 日本語での説明
 

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Dernier (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

Purely Functional Data Structures ex3.3 leftist heap

  • 1. Leftist Heap Definition A Leftist (min)Heap is a binary tree that satisfies the follow-ing conditions. If X is a node and L and R are its left and right children, then: – X.value ≤ L.value – X.value ≤ R.value – null path length of L ≥ null path length of R where the null path length of a node is the shortest distance between from that node to a descendant with 0 or 1 child. If a node is null, its null path length is −1.
  • 2. Example: Null Path Length •node 4 violates leftist heap property 4  fix by swapping children 8 0 19 1 12 1 27 0 20 0 15 0 25 0 43 0 node 4 8 19 12 15 25 27 20 43 npl 1 0 1 1 0 0 0 0 0
  • 3. Example: Null Path Length 4 19 1 8 0 27 0 20 0 12 1 43 0 15 0 25 0 node 4 8 19 12 15 25 27 20 43 npl 1 0 1 1 0 0 0 0 0
  • 4. FromListの実装 (言語ゲーム 2009-11-23 Leftist Heap (http://d.hatena.ne.jp/propella/20091123/p1) のサンプルプログラムに追加して使って下さい) -- Copied from CS231 Algorithm Prof. Lyn Turbak Wellesley College -- make a leftist heap with one node. singleton x = T 1 x E E -- make a leftist heap from list fromList :: Ord a => [a] -> Heap a fromList [] = E fromList xs = mergeLoop (map singleton xs) where mergeLoop [] = error "shouldnt: mergeLoop []" mergeLoop [t] = t mergeLoop ts = mergeLoop(mergePairs ts) mergePairs [] = [] mergePairs [t] = [t] mergePairs (t1:t2:ts) = (merge t1 t2):(mergePairs ts) prop_Heap2 :: [Int] -> Bool prop_Heap2 xs = isSorted (heapToList (fromList xs)) test2 = verboseCheck prop_Heap2
  • 6. fromListの計算量がO(n)であること n n n 2 n n + 2 log 2 + 3 log 2 + ⋯ + (log n+1) log 2 2 2 2 2 2 n n n log 2 log 2 log 2 = + ( + 2 + ⋯+ n ) 2 2 2 2 2 2 n 1 log 2 log 2 log 2 ( ( + 2 +⋯+ n ) < 1 よ り) 2 2 2 2 n 3n < +n= 2 2
  • 7. 参考文献 ・Clemson University CpSc 212, Section 001 (Roy P. Pargas) http://www.cs.clemson.edu/~pargas/courses/cs212/common/notes/ppt/1 4LeftistSkewHeaps.ppt p.3, p.6-7 ・Wellesley College CS 231 2001 (Lyn Turbak) http://cs.wellesley.edu/~cs231/fall01/leftist.pdf p.2, p.5 ・言語ゲーム 2009-11-23 Leftist Heap http://d.hatena.ne.jp/propella/20091123/p1