1 / 53

Algorithmic Aspects of Searching in the Past

Algorithmic Aspects of Searching in the Past. Lecture 1: Persistent Data Structures Advanced Topics in Algorithms & Data Structures. Christine Kupich Institut für Informatik, Universität Freiburg. Overview. Motivation Example : Natural search trees

patty
Download Presentation

Algorithmic Aspects of Searching in the Past

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Algorithmic Aspects of Searching in the Past Lecture 1: Persistent Data Structures Advanced Topics in Algorithms & Data Structures Christine Kupich Institut für Informatik, Universität Freiburg

  2. Overview • Motivation • Example: Natural search trees • Making data structures partially persistent • Example: Partially persistent red-black trees • An application: Point location • An application: Grounded 2-dimensional range searching • Making data structures fully persistent

  3. Motivation Ephemeral: no mechanism to revert to previous states A structure is called persistent, if it supports access to multiple versions. Partially persistent: All versions can be accessed but only the newest version can be modified. Fully persistent: All versions can be accessed and modified. Confluently persistent: Two or more old versions can be combined into one new version. Oblivious: The data structure yields no knowledge about the sequence of operations that have been applied to it other than the final result of the operations.

  4. 1 5 3 1 7 5 3 7 Example: Natural search trees Only partially oblivious! • Insertion history can sometimes be reconstructed. • Deleted keys are not visible.

  5. Simple methods for making structures persistent • Structure-copying method: Make a copy of the data structure each time it is changed. Yields full persistence at the price of W(n) time and space per update to a structure of size n • Store a log-file of all updates! In order to access version i, first carry out i updates, starting with the initial structure, and generate version i. (i) time per access, O(1) space and time per update • Hybrid-method: Store the complete sequence of updates and additionally each k-th version for a suitably chosen k. Result: Any choice of k causes blowup in either storage space or access time Are there any better methods?

  6. Making data structures persistent Several constructions to make various data structures persistent have been devised, but no general approach has been taken until the seminal paper by Driscoll, Sarnak, Sleator and Tarjan, 1986. They propose methods to make linked data structures partially as well as fully persistent. Let’s first have a look at how to make structures partially persistent

  7. Fat node method - partial persistence • Record all changes made to node fields in the nodes • Each fat node contains same fields as ephemeral node and a version stamp • Add a modification history to every node: each field in a node contains a list of version-value pairs

  8. Fat node method - partial persistence • Modifications • Ephemeral update step i creates new node: create a new fat node with version stamp i and original field values • Ephemeral update step i changes a field: store the field value plus a timestamp • Each node knows what its value was at any previous point in time • Access field f of version i • Choose the value with maximum version stamp no greater than i

  9. Fat node method - analysis • Time cost per access gives O(log m) slowdown per node (using binary search on the modification history) • Time and Space cost per update step is O(1) (to store the modification along with the timestamp at the end of the modification history)

  10. Fat node method - Example A partially persistent search tree. Insertions:5,3,13,15,1,9,7,11,10, followed by deletion of item 13. 1-10 5 2 3 3 13 4 4 6 5 15 9 1 10 7 7 8 10 10 7 11 10 9 10

  11. Path-copying method -partial persistence • Make a copy of the node before changing it to point to the new child. Cascade the change back until root is reached. Restructuring costs O(height_of_tree) per update operation • Every modification creates a new root • Maintain an array of roots indexed by timestamp.

  12. Path-copying method -Example 0 version 0: version 1: Insert (2) version 2: Insert (4) 5 7 1 3

  13. Path-copying method -Example 0 version 0: 5 7 1 3

  14. Path-copying method -partial persistence 0 1 version 1: Insert (2) 5 5 1 7 1 3 3 2

  15. Path-copying method -partial persistence 0 1 2 version 1: Insert (2) version 2: Insert (4) 5 5 5 1 1 7 1 3 3 3 2 4

  16. k lp t: rp rp Node-copying method -partial persistence Extend each node by a time-stamped modification box (initially empty) Version at/ after time t Version before the modification time t Searching in version j Follow an entry pointer with largest version number i, i <= j Compare keys and follow newest pointer no greater than j

  17. Node-copying method -partial persistence 5 1 7 3 version 0 version 1: Insert (2) version 2: Insert (4)

  18. Node-copyingmethod -partial persistence 5 1 7 3 version 0: version 1: Insert (2) 1 lp 2

  19. Node-copyingmethod -partial persistence 5 1 7 3 version 1: Insert (2) version 2: Insert (4) 3 1 lp 2 4

  20. Node-copyingmethod -partial persistence 5 1 7 2 rp 3 version 1: Insert (2) version 2: Insert (4) 3 1 lp 2 4

  21. Node-copying method -partial persistence Modification If modification box empty, fill it. Otherwise, make a copy of the node, using only the latest values, i.e. value in modification box plus the value we want to insert, without using modification box Cascade this change to the node’s parent If the node is a root, add the new root to a sorted array of roots Access time gets O(1) slowdown per node, plus additive O(log m) cost for finding the correct root

  22. Node-copyingmethod -Example A partially persistent search tree. Insertions: 5,3,13,15,1,9,7,11,10, followed by deletion of item 13. 1-2 3-9 10 5 5 5 2 2 6 3 13 13 5 4 1 8 15 9 9 7 7 10 11 11 9 10

  23. Node-copyingmethod -partial persistence The amortized costs (time and space) per modification are O(1). Proof: Using the potential technique

  24. Potential technique • Potential technique • The potential is a function of the entire data structure • Definition potential function: A measure of a data structure whose change after an operation corresponds to the time cost of the operation • The initial potential has to be equal to zero and non-negative for all versions • The amortized cost of an operation is the actual cost plus the change in potential • Different potential functions lead to different amortized bounds

  25. Node-copyingmethod -partial persistence • Definitions • Live nodes: they form the latest version (reachable from the root of the most recent version), dead otherwise • Full live nodes: live nodes whose modification boxes are full

  26. Node-copyingmethod -potential paradigm The potential function f (T): the number of full live nodes in T (initially zero) The amortized cost of an operation is the actual cost plus the change in potential Δ f =? Each modification involves k number of copies, each with a O(1) space and time cost, and one change to a modification box with O(1) time cost Change in potential after update operation i: Δ f = Space: O(k + Δ f), time: O(k + 1 + Δ f) Hence, a modification takes O(1) amortized space and O(1) amortized time

  27. Red-black trees • Constraints • All missing nodes are regarded as black • Any red node has a black parent • From any node, all paths to a missing node contain the same number of black nodes • Depth of an n-node red-black tree is at most 2 log n • Root is colored black

  28. Red-black trees Rebalancing transformations - insertion 1. recolor bubble the violation up the tree 2. recolor

  29. Red-black trees Rebalancing transformations - insertion 3. leaving no inconsistency lr + recolor parent and gran-parent 4. 11 rr Case 3. An insertion requires O(log n) recolorings plus at most 2 rotations

  30. Red-black trees -partial persistence • A red-black tree can be made partially persistent using the node copying method at an amortized space cost of O(1) per insertion or deletion and a worst-case time cost of O(log n) per access, insertion or deletion. • Each node contains: • a key • 2 pointers for the successors • a color bit and • an extra pointer (version stamp, direction) • Colors are not used in access operations. Old colors can be overwritten

  31. Red-black trees -partial persistence An Example: insert E, C, M, O, N

  32. 1-2 1-2 1 3 r,b b E E r,b r,b E E 2 r 2 r r C M C 1-2 1-2 3-4 3-4 r,b b E E r,b b,r,b E E 2 2 r r C M r,b C M r,b 4 4 r O r O Red-black trees -partial persistence An Example: insert E, C, M, O, N Insert C Insert O Insert M recolor

  33. 1-2 1-2 3-4 3-4 r,b b r,b b E E E E 2 2 r,b r,b C M C M r,b r,b 4 4 r O r O 5 r M N r,b r N r O Red-black trees -partial persistence Insert N RR

  34. M r,b r,b N r N r M r O r O 1-2 1-2 3-5 3-4 r,b b r,b b E E E E 5 r,b 2 N 2 r,b r,b C M C r,b M r,b M 4 r r O 4 O r 5 r N LR + recolor

  35. Application: Grounded 2-Dimensional Range Searching Given a set of points, and a query triple (a,b,i) Report the set of points a<x<b and y<i. y i x a b

  36. Application: Grounded 2-Dimensional Range Searching Version i contains every point for which y<i. Use x-coordinates as keys. i a b To answer a query: Report all points in version i whose x-coordinates are in [a,b]. Query time? Persistent red-black tree: Space ? , preprocessing time ?

  37. 1-Dimensional Range Search

  38. Application: Planar point location Suppose that the Euclidian plane is subdivided into polygons by n line segments that intersect only at their endpoints. Given such a polygonal subdivision and an on-line sequence of query points in the plane, the planar point location problem, is to determine for each query point the polygon containing it. Measure an algorithm by three parameters: 1) The preprocessing time. 2) The space required for the data structure. 3) The time per query.

  39. Planar point location - example

  40. Solving planar point location (Cont.) 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

  41. Planar point location -- example

  42. Solving planar point location (Cont.) To answer a query: first find the appropriate slab then search the slab to find the polygon Query time is O(log n) How about the space ?

  43. Planar point location -- bad example Total # lines O(n), and number of lines in each slab is O(n).

  44. Planar point location & persistence So how do we improve the space bound ? Key observation: The lists of the lines in adjacent slabs are very similar. 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 How many insertions/deletions are there all together ? 2n (One insertion and one deletion per segment)

  45. Planar point location & persistence (cont) Updates should be persistent since we need all search trees at the end. Partial persistence is enough. Well, we already have the path copying method, lets use it. What do we get ? O(n log n) space and O(n log n) preprocessing time. Using the node-copying method, we can improve the space bound to O(n).

  46. Making data structures fully persistent • With this type of persistence the versions don't form a simple linear path, they form a version tree (since you can also update in the past). Lack of linear ordering. • Impose a total ordering on the versions (version list) • The version list defines a preorder on the version tree (for navigation): for any version i, the descendants of i in the version tree occur consecutively in the version list, starting with i. 0 1 version list: 5 2 7 6 3 A version tree 4

  47. Making data structures fully persistent Search tree versions: 0 1 iE 6 2 iA iC 8 7 3 iG iA iM 10 9 4 iK iM iI 5 11 dE dM 12 iO

  48. Full persistence It must be possible to: • perform insertions in the version list and • given two versions i and j, determine whether i precedes or follows j in the version list This list order problem has been addressed by Dietz and Sleator • order queries are answered in O(1) worst case time with an O(1) amortized time bound for insertion

  49. Fat node method - full persistence • Each fat node contains same fields as ephemeral node plus space for extra fields (each with a field name and a version stamp) • Each field in a node contains a list of version-value pairs Access • Versions are compared with respect to their position in the version list, not with respect to their numeric values • Access a field in version i: search for the version stamp rightmost in version list, but not to the right of i

  50. Fat node method - Example Version list: 1,6,7,10,11,2,8,9,3,4,5,12 1-10, 12 1-10,12 0 E 2 11 3 1 6 2 iE 7 9 6 2 A C M M iA 5 iC 2 3 4 11 G 2 3 8 8 7 3 iG iA iM 10 I 10 A 12 9 K 4 iK iM iI O 5 11 dE dM A fully persistent search tree 12 iO

More Related