haccepted-0.1.0.0: Data structures and algorithms
Safe HaskellSafe-Inferred
LanguageHaskell2010

PQTree

Description

PQ-tree

PQ-tree is a data structure for representing permutations. It's useful for solving the consecutive ones problem.

This is an implementation of PQ-tree as described by Booth and Lueker. The tree consists of three types of nodes, P, Q and leaf. Leaves are single elements. The frontier of the tree is the left to right order of leaves in the tree. A P-node is equivalent to another with its children permuted in any order. A Q-node is equivalent to one with its children reversed. The permutations represented by a tree are the frontiers of all equivalent trees.

The various reduction templates described in Booth and Lueker's paper are used, but the construction algorithm is not. This implementation is purely functional, hence it uses a simpler top-down approach instead that runs in O(n) time (plus set member check overheads) rather than in O(update size). This implementation is specialized to Ints, but can be modified to work with other types.

Sources:

Synopsis

Documentation

data PQNode Source #

Instances

Instances details
Show PQNode Source # 
Instance details

Defined in PQTree

NFData PQNode Source # 
Instance details

Defined in PQTree

Methods

rnf :: PQNode -> () #

buildPQ :: [Int] -> PQNode Source #

Builds a PQ-tree from a set of Ints. O(n).

reducePQ :: [Int] -> PQNode -> Maybe PQNode Source #

Reduces a PQ-tree with a set of Ints. This should be a subset of what it was constructed with. O(n).

reduceAllPQ :: [[Int]] -> PQNode -> Maybe PQNode Source #

Reduces a PQ-tree with many sets. O(mn) for m sets.

frontierPQ :: PQNode -> [Int] Source #

The frontier of the PQ-tree. O(n).

permsPQ :: PQNode -> [[Int]] Source #

The permutations represented by the PQ-tree. O(do not use).