Content deleted Content added
m Reverted edits by Chite6888888888888888888 (talk) (HG) (3.2.0) |
m grammar and spelling |
||
Line 4:
{{refimprove|date=January 2017}}}}
In [[computer science]], a '''purely functional data structure''' is a [[data structure]] that can be implemented in a [[purely functional language]]. The main difference between an arbitrary data structure and a purely functional one is that a purely functional data structure is (strongly) [[immutable object|immutable]]. This restriction ensures the data structure possesses the advantages of immutable objects: (full) [[persistent data structure|persistency]],<nowiki/> quick copy of objects, and [[thread safety]]. Efficient purely functional data structures may require the use of [[lazy evaluation]] and [[
==Definition==
Line 30:
[[Lazy evaluation]] is particularly interesting in a purely functional language because the order of the evaluation never changes the result of a function. Therefore, lazy evaluation naturally becomes an important part of the construction of purely functional data structures. It allows computation to be done only when its result is actually required. Therefore, the code of a purely functional data structure can, without loss of efficiency, consider similar data which will effectively be used and data which will be ignored. The only computation required is for the first kind of data that will actually be performed.
One of the key tools in building efficient, purely functional data structures is [[memoization]]. When a computation is done, it is saved and does not have to be performed a second time. This is particularly important in lazy implementations; additional evaluations may require the same result, but it is impossible to know which evaluation will require it first. There are actually many books that pertain to purely functional data structures that can give you a more in
===Amortized analysis and scheduling===
Some data structures, even non-purely-functional ones such as [[dynamic array|dynamic arrays]], admit operation which is efficient (constant time for dynamic arrays) most of the time, and inefficient (linear time for dynamic arrays) rarely. ''[[Amortized analysis|Amortization]]'' can then be used to prove that the average running time of the operations
In general, having inefficient operations is not acceptable for persistent data structures, because this inefficient operation can be called many times. It is not acceptable either for real-time or imperative systems, where the user may require the time taken by the operation to be predictable. Furthermore, this unpredictability complicates the use of [[Parallel computing|parallelism]].
Line 40:
====Example: queue====
For example, [[amortized queue]]s are composed of two [[singly linked list]]s: the front and the reversed rear. Elements are added to the rear list and are removed from the
== Bibliography ==
Line 50:
*[http://www.cs.cmu.edu/~sleator/papers/fully-persistent-lists.pdf Fully Persistent Lists with Catenation] by James R. Driscoll, Daniel D. Sleator, Robert E. Tarjan (PDF)
*[http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-854j-advanced-algorithms-fall-2005/lecture-notes/persistent.pdf Persistent Data Structures] from the [[MIT OpenCourseWare]] course [http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-854j-advanced-algorithms-fall-2005 Advanced Algorithms]
*[http://cstheory.stackexchange.com/questions/1539/whats-new-in-purely-functional-data-structures-since-okasaki What's new in purely functional data structures since
[[Category:Functional programming]]
|