Functional Data Structures:Difficulties and Further Reading

Difficulties

As this chapter has shown, many data structures work quite nicely in a functional setting. However, some do not. We close with a description of several warning signs to watch for.

Random access: All of the data structures described in this chapter have been pointer-based. Unfortunately, data structures that depend on arrays—such as hash tables—are more difficult to handle. No entirely satisfactory approach is known for making arrays persistent. The best known approach from a theoretical point of view is that of Dietz [6], in which array accesses run in O(log log n) expected amortized time. However, his approach is quite complicated and difficult to implement. Competing approaches, such as [1, 4, 27], degrade to logarithmic (or worse!) time per access in common cases.

Cycles : Not all pointer-based data structures are suitable for implementation in a functional setting. The most common problem is the presence of cycles, such as those found in doubly-linked lists or in binary search trees with parent pointers.

Path copying requires copying all paths from the root to the site of the update.

In the presence of cycles, this frequently means copying the entire data structure.

Multiple entry points: Even without cycles, a pointer-based data structure can run into difficulties if it has multiple entry points. For example, consider a pointer based implementation of the union-find data structure [33]. All the pointers go from children to parents, so there are no cycles (except sometimes trivial ones at the roots). However, it is common for every node of the union-find data structure to be a potential entry point, rather than just the root(s). Path copying requires copying all paths from any entry point to the site of the update. With multiple entry points, this again frequently degrades into copying the entire data structure.

Unpredictable access patterns : Section 40.4 described how to use lazy evaluation to make an amortized data structure persistent. Although this works for many amortized data structures, such as skew heaps [32], it does not work for all amortized data structures. In particular, data structures with highly unpredictable access patterns, such as splay trees [31] (see Chapter 12), are difficult to make persistent in this fashion.

Further Reading

The most complete general reference on functional data structures is Okasaki [24]. For more information on specific data structures, consult the following sources:

• queues and deques [5, 10, 11, 21]

• priority queues and priority search queues [3, 8]

• random-access lists and flexible arrays [9, 12, 13, 16, 20, 23]

• catenable lists and deques [14, 19, 22]

Comments

Popular posts from this blog

Data Structure Visualization:Introduction and Value of Data Structure Rendering

Collision Detection:Penetration Depth Computation

Concurrent Data Structures:Linked Lists