Presentation is loading. Please wait.

Presentation is loading. Please wait.

Persistent Data Structures Computational Geometry, WS 2007/08 Lecture 12 Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.

Similar presentations


Presentation on theme: "Persistent Data Structures Computational Geometry, WS 2007/08 Lecture 12 Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut."— Presentation transcript:

1 Persistent Data Structures Computational Geometry, WS 2007/08 Lecture 12 Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut für Informatik Fakultät für Angewandte Wissenschaften Albert-Ludwigs-Universität Freiburg

2 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann2 Overview Versions and persistence in data structures Making structures persistent Partial persistence –Fat node method –Path-copying method –Node-copying (DSST) method Revisit: Planar point-location –Sarnak-Tarjan solution –Dobkin-Lipton observation

3 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann3 Data Structures in the Temporal Sense A data structure is called Ephemeral – no mechanisms to revert to previous states. –Usually, a single transitory structure where a change to the structure destroys the old version. Persistent – supports access to multiple versions. Furthermore, a structure is – partially persistent if all versions can be accessed but only the newest version can be modified, and – fully persistent if every version can be both accessed and modified.

4 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann4 A Linked Data Structure Pre-definitions: A linked data structure has a finite collection of nodes. Each node contains a fixed number of named fields. All nodes in the structure are of exactly the same type Access to the linked structure is by pointers indicating nodes of the structure. In our deliberations: We shall use the binary search tree as our linked data structure for all running examples throughout the lecture.

5 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann5 Persisted Versions Versions are directly related to the operations incurred on the data structure, mainly: Update operations Access operations After an update operation, the current and all previous states of the data structure are archived in a manner that makes them accessible (via access operations) from their version identities.

6 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann6 Terminologies Current version – Version v i of the data structure where a current operation is about to be performed Current operation – An update operation performed on the current version v i of the data structure, which will result in the newest version v i+1, spawned after a successful completion of the operation.

7 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann7 Making Structures Persistent: Naïve I Naïve Structure-Copy Method Make a copy of the data structure each time it is changed At current operation: –A new version v i+1 is spawned by completely copying the current version –The update operation is performed on the newest version Costs (for structure of size n): –Per update: TimeSpace –For m updates: TimeSpace

8 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann8 Making Structures Persistent: Naïve II Naïve Log-File Method Store a log-file of all updates At current operation: –Update log-file To access version i: –Sequentially carry out i updates, starting from the initial structure, to generate version i. Costs (for structure of size n): –Per update: TimeSpace –For m updates: TimeSpace –Per access:Time

9 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann9 Hybrid Method Structure-Copying with Log-file Store the complete sequence of updates in a log-file Store every k th version of the data structure, for a suitably chosen k To access version i: –Retrieve structure from version k  i/k  –Sequentially update structure to get version i Tradeoffs from Log-file method: –Time and space requirement increase at least with a factor of

10 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann10 Ideals We seek more efficient techniques: Ideally, we want (on average) to have Storage space used by the persistent structure to be O(1) per update step, and Time per operation to increase by only a constant factor over the time in the ephemeral structure

11 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann11 Fat Node Method – Partial Persistence Record all changes made to the node field in the nodes themselves Nodes are allowed to become arbitrarily “fat” to include version history; i.e. a list of version stamps A version stamp indicates the version in which the named field was changed to the specified value Each fat node has its own version stamp to indicate the version in which it was created However, a version stamp is not unique; i.e. several Fat nodes can have the same version stamp

12 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann12 Update Operation – Fat Node Method Consider update operation i. Persistent (Fat Node Method) Creates new Fat node with version stamp i, and all original field values Store field value plus version stamp Ephemeral Creates new node Changes a field

13 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann13 Update Operation – Example (Versions 1 to 9) Insert: 5, 20, 8, 15, 6, 2, 1, 28, 12 5 20 8 156 2 28 12 1 (Versions 10 to 12) Delete: 20, 5, 1

14 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann14 Access Operation – Fat Node Method Accessing any version i  m in the persistent structure: Find the root node at version i. Then traverse nodes in the structure, choosing only version values with the maximum version stamp  i. Example: Given this persistent structure, access version v 11 5 20 8 156 2 28 12 1 v 1 -v 10 v6v6 v7v7 v2v2 v3v3 v4v4 v5v5 v8v8 v9v9 v 10 v 11 v 12 v 11 -v 12

15 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann15 Analysis – Fat Node Method Assumption: The version stamps in a Fat node are ordered and stored in a balanced binary search tree. Update operation Space per update: Time per update: Access operation Time per access: (multiplicative slow-down)

16 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann16 Path-Copying Method – Partial Persistence Creates a set of search trees, one per update, having different roots but sharing common subtrees Copy only the nodes in which changes are made, such that any node in the current version that contains a pointer to a node must itself be copied In our linked data structure, each node contains pointers to its children Copying one node in the current version requires copying the entire path from the node to the root – hence the name “Path-Copying”

17 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann17 Update Operation – Path-Copying Consider update operation i. Identify the node in the current version that will be affected by the update operation Make a copy of this node (and hence the path to the root in the current version) Modify the path accordingly to the operation

18 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann18 Update Operation – Example (Insert) (Versions 1 to 9) Insert: 5, 20, 8, 15, 6, 2, 1, 28, 12 5 20 8 156 2 1 … v 7

19 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann19 Update Operation – Example (Insert) (Versions 1 to 9) Insert: 5, 20, 8, 15, 6, 2, 1, 28, 12 5 20 8 156 2 281 … v 7 5 20 v8v8

20 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann20 Update Operation – Example (Insert) (Versions 1 to 9) Insert: 5, 20, 8, 15, 6, 2, 1, 28, 12 5 20 8 156 2 28 12 1 … v 7 5 20 v8v8 5 v9v9 8 15

21 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann21 Update Operation – Example (Delete) (Versions 10 to 12) Delete: 1, 20, 5 5 20 8 156 2 1 … v 9 12 28

22 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann22 Update Operation – Example (Delete) (Versions 10 to 12) Delete: 1, 20, 5 5 20 8 156 2 1 … v 9 12 28 5 2 v 10

23 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann23 Update Operation – Example (Delete) (Versions 10 to 12) Delete: 1, 20, 5 5 20 8 156 2 1 … v 9 12 28 5 2 v 10 5 v 11 15 8

24 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann24 Update Operation – Example (Delete) (Versions 10 to 12) Delete: 1, 20, 5 5 20 8 156 2 1 … v 9 12 28 5 2 v 10 5 v 11 15 8 2 v 12

25 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann25 Access Operation – Path-Copying Assumption: The version roots are ordered and stored in some accessible structure on top of all the m persisted versions. To access any version v i : We only need to locate the correct root from the accessible top structure to access the required version i

26 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann26 Analysis – Path-Copying Method Update operation Space per update: Time per update: Access operation Time per access:

27 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann27 Node-Copying Method – Partial Persistence An improvement to the Fat node method We do not allow nodes to become arbitrarily “fat”, but fix this number When we run out of space for version stamps, we then create a new copy of the node In our deliberation, we allow only 1 additional pointer, contained in the node and call it the version stamp modification box. k lprp v t : ptr Original left pointer to left child with version before v t Original right pointer to right child with version before v t Version stamp modification box

28 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann28 Update Operation – Node-Copying Consider update operation i. Identify the node in the current version that will be affected by the update operation Make a copy of this node if the version stamp modification box is not empty Modify the node accordingly to the operation

29 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann29 Update Operation – Example (Insert) v0v0 5 208 (Versions 1 to 6) Insert: 15, 6, 2, 1, 28, 12

30 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann30 Update Operation – Example (Insert) v0v0 5 20 v 2 : lp 8 v 1 : rp (Versions 1 to 6) Insert: 15, 6, 2, 1, 28, 12 1586

31 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann31 Update Operation – Example (Insert) v 0 -v 4 5 v 3 : lp 20 v 2 : lp 8 v 1 : rp (Versions 1 to 6) Insert: 15, 6, 2, 1, 28, 12 15 v 6 : lp 862 v 4 : lp 128205 v 5 -v 6 12

32 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann32 Update Operation – Example (Delete) v 0 -v 4 5 v 3 : lp 20 v 2 : lp 8 v 1 : rp (Versions 7 and 8) Delete: 1, 20 15 v 6 : lp 862 v 4 : lp 128205 v 5 -v 6 12

33 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann33 Access Operation – Node-Copying Navigating through this persistent structure is exactly the same as the Fat node method. To access any version v i : Find the root node at version i. Then traverse nodes in the structure, choosing only version values with the maximum version stamp  i. Exercise: From the previous figure, access version v 6

34 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann34 Analysis – Node-Copying Method Update operation Space per update: Time per update: Access operation Time per access:

35 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann35 Planar Point Location

36 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann36 Planar Point Location: Sarnak-Tarjan Solution Idea: (partial) persistence –Query time: O(log n), Space: O(n) –Relies on Dobkin-Lipton construction and Cole’s observation. Dobkin-Lipton: –Partition the plane into vertical slabs by drawing a vertical line through each endpoint. –Within each slab, the lines are totally ordered. –Allocate a search tree per slab containing the lines, and with each line associate the polygon above it. –Allocate another search tree on the x-coordinates of the vertical lines.

37 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann37 Dobkin-Lipton Construction Partition the plane into vertical slabs.

38 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann38 Dobkin-Lipton Construction Locate a point with two binary searches. Query time: O(log n). Nice but space inefficient! Can cause O(n 2 ).

39 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann39 Worst-Case Example Θ(n) segments in each slabs, and Θ(n) slabs.

40 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann40 Cole’s Observation A B Sets of line segments intersecting contiguous slabs are similar. Reduces the problem to storing a “persistent” sorted set.

41 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann41 Improving the Space Bound Create the search tree for the first slab. Then obtain the next one by deleting the lines that end at the corresponding vertex and adding the lines that start at that vertex. Total number of insertions / deletions: –2n –One insertion and one deletion per segment.

42 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann42 Planar Point Location and Persistence Updates should be persistent (since we need all search trees at the end). Partial persistence is enough (Sarnak and Tarjan). Method 1: Path-copying method; simple and powerful (Driscoll et al., Overmars). –O(n log n) space + O(n log n) preprocessing time. Method 2: Node-copying method –We can improve the space bound to O(n).

43

44


Download ppt "Persistent Data Structures Computational Geometry, WS 2007/08 Lecture 12 Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut."

Similar presentations


Ads by Google