Parent function

From formulasearchengine
Revision as of 16:46, 31 January 2014 by en>Gilliam (Reverted edits by 63.133.246.253 (talk) to last version by Allthingstoallpeople)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Iacono's working set data structure
Invented 2001
Invented by John Iacono
Asymptotic complexity
in big O notation
Space O(n)
Search O(log w(x))
Insert O(log n)
Delete O(log n)

In computer science, Iacono's working set structure[1] is a comparison based dictionary. It supports insertion, deletion and access operation to maintain a dynamic set of n elements. The working set of an item x is the set of elements that have been accessed in the structure since the last time that x was accessed (or inserted if it was never accessed). Inserting and deleting in the working set structure takes O(logn) time while accessing an element x takes O(logw(x)). Here, w(x) represents the size of the working set of x.

Structure

An example of a search for x in the working set structure. After finding x, it is removed from T4 and inserted into T1. Finally, a shift from 1 to 4 is performed in which an element is removed from Ti and inserted into Ti+1 for 1i<4.

To store a dynamic set of n elements, this structure consists of a series of Red–black trees, or other Self-balancing binary search trees T1,T2,,Tk, and a series of deques (Double-ended queues) Q1,Q2,Qk, where k=loglogn. For every 1ik, tree Ti and deque Qi share the same contents and pointers are maintained between their corresponding elements. For every i<k, the size of Ti and Qi is 22i. Tree Tk and deque Qk consist of the remaining elements, i.e., their size is ni=1k122i. Therefore, the number of items in all trees and the number of elements in all deques both add up to n. Every element that has been inserted in the data structure is stored in exactly one of the trees and its corresponding deque.

Working set Invariant

In the deques of this structure, elements are kept in sorted order according to their working set size. Formally, element x lies after y in deque Qi if and only if w(x)<w(y). Moreover, for every 1i<k, the elements in deque Qi have a smaller working sets than the elements in deque Qi+1. This property is referred to as the Working set invariant. Every operation in the data structure maintains the Working set invariant.

Operations

The basic operation in this structure is called shift from h to j, where h and j are indices of some trees in the structure. Two cases are considered in a shift from h to j: If h<j, then for every hi<j, taken in increasing order, an item is dequeued from Qi and enqueued into Qi+1. The corresponding item is deleted from Ti and inserted into Ti+1. The running time of this operation is O(i=hjlog|Ti|)=O(i=hjlog22i)=O(2j). Analogously, if j<h, then for every j<ih, taken in decreasing order, an item is dequeued from Qi and enqueued into Qi1. The corresponding item is deleted from Ti and inserted into Ti1. The running time of this operation is O(i=jhlog|Ti|)=O(i=jhlog22i)=O(2h). Regardless of the case, after a shift operation, the size of Th decreases by one whereas the size of Tj increases by one. Since that elements in the deques are sorted with respect to their working sets sizes, a shift operation maintains the Working set invariant.

Search

To search for an element x, search for x in T1,T2,Tk, in increasing order, until finding a tree Tj containing x. If no tree is found, the search is unsuccessful. If x is found, it is deleted from Tj and then inserted into T1, i.e., it is moved to the front of the structure. The search finishes by performing a shift from 1 to j which restores the size of every tree and every deque to their size prior to the search operation. The running time of this search is O(i=1jlog22i)=O(2j) if the search was successful, or O(i=jklog22i)=O(2k)=O(logn) otherwise. By the Working set property, every element in trees T1,T2,,Tj1 belongs to the working set of x. In particular, every element in Tj1 belongs to the working set of x and hence, w(x)>|Tj1|=22j1. Thus, the running time of a successful search is O(2j)=O(log22j1)=O(logw(x)).

Insert

Inserting an element x into the structure is performed by inserting x into T1 and enqueuing it into Q1. Insertion is completed by performing a shift from 1 to k. To avoid overflow, if |Tk|=22k before the shift, i.e., if the last tree is full, then k is incremented and a new empty Tk and Qk is created. The running time of this operation is dominated by the shift from 1 to k whose running time is O(2k)=O(2loglogn)=O(logn). Since element x, whose working set is the smallest, is enqueued in Q1, the Working set invariant is preserved after the shift.

Delete

Deleting an element x is done by searching for x on each tree in the structure, in increasing order, until finding a tree Tj that contains it (if non is found the deletion is unsuccessful). Item x is deleted from Tj and Qj. Finally, a shift from k to j maintains the size of Tj equal to 22j. The running time of this operation is O(2k)=O(logn). The working set invariant is preserved as deleting an element does not change the order of the working set of the elements.

Discussion

Splay trees are self adjusting search trees introduced by Sleator and Tarjan[2] in 1985. Using restructuring heuristic, splay trees are able to achieve insert and delete operations in O(logn) amortized time, without storing any balance information at the nodes. Moreover, the Working Set Theorem for splay trees states that the cost to access an element in a splay tree is O(logw(x)) amortized. Iacono's workings set structure obtains the same running time for search, insert and delete in the worst-case. Therefore, offering an alternative to splay trees.

References

43 year old Petroleum Engineer Harry from Deep River, usually spends time with hobbies and interests like renting movies, property developers in singapore new condominium and vehicle racing. Constantly enjoys going to destinations like Camino Real de Tierra Adentro.

  1. Cite error: Invalid <ref> tag; no text was provided for refs named WorkingSetStructure
  2. Cite error: Invalid <ref> tag; no text was provided for refs named SleatorTarjan