1 Functional Data Structures Purely functional car cdr never modify only create new pairs only DAGs [C. Okasaki, Simple and efficient purely functional.

Slides:



Advertisements
Similar presentations
Data Structures Through C
Advertisements

Turning Amortized to Worst-Case Data Structures: Techniques and Results Tsichlas Kostas.
Planar point location -- example
CS252: Systems Programming Ninghui Li Program Interview Questions.
Priority Queues  MakeQueuecreate new empty queue  Insert(Q,k,p)insert key k with priority p  Delete(Q,k)delete key k (given a pointer)  DeleteMin(Q)delete.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 6.
1 Persistent data structures. 2 Ephemeral: A modification destroys the version which we modify. Persistent: Modifications are nondestructive. Each modification.
D. D. Sleator and R. E. Tarjan | AT&T Bell Laboratories Journal of the ACM | Volume 32 | Issue 3 | Pages | 1985 Presented By: James A. Fowler,
Msb(x) in O(1) steps using 5 multiplications Word size n = g∙g, g a power of 2 [M.L. Fredman, D.E. Willard, Surpassing the information-theoretic bound.
Today’s Agenda  Stacks  Queues  Priority Queues CS2336: Computer Science II.
Rank-Pairing Heaps Robert Tarjan, Princeton University & HP Labs Joint work with Bernhard Haeupler and Siddhartha Sen, ESA
1 Finger search trees. 2 Goal Keep sorted lists subject to the following operations: find(x,L) insert(x,L) delete(x,L) catenate(L1,L2) : Assumes that.
Implementation and Evaluation of Search Methods. Use a stack data structure. 1. Push root node of tree on the stack. 2. Pop the top node off the stack.
1 Self-Adjusting Data Structures. 2 Lists [D.D. Sleator, R.E. Tarjan, Amortized Efficiency of List Update Rules, Proc. 16 th Annual ACM Symposium on Theory.
Outline Scapegoat Trees ( O(log n) amortized time)
Number Systems and Data structures Amr Elmasry A. Elmasry, C. Jensen and J. Katajainen, The strictly-regular number system and worst-case.
A Linear Time Algorithm for the k Maximum Sums Problem By Gerth S. Brodal and Allan G. Jørgensen.
Unified Access Bound 1 [M. B ă doiu, R. Cole, E.D. Demaine, J. Iacono, A unified access bound on comparison- based dynamic dictionaries, Theoretical Computer.
Multiversion Access Methods - Temporal Indexing. Basics A data structure is called : Ephemeral: updates create a new version and the old version cannot.
O(log n) bits or atomic elements
Update Persistent Data Structures (Version Control) v0v0 v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 Ephemeral query v0v0 v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 Partial persistence.
Update 1 Persistent Data Structures (Version Control) v0v0 v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 Ephemeral query v0v0 v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 Partial persistence.
Purely Functional Worst Case Constant Time Catenable Sorted Lists Gerth Stølting Brodal University of Aarhus Joint work with Christos Makris Kostas Tsichlas.
UnInformed Search What to do when you don’t know anything.
Lisp A functional language. As always… How is it similar? First it runs on the same OS as all applications Uses runtime activation stack as others Needs.
Rank-Pairing Heaps Bernhard Haeupler, Siddhartha Sen, and Robert Tarjan, ESA
Fully Persistent B-Trees 23 rd Annual ACM-SIAM Symposium on Discrete Algorithms, Kyoto, Japan, January 18, 2012 Gerth Stølting Brodal Konstantinos Tsakalidis.
Nick Harvey & Kevin Zatloukal
Point Location Computational Geometry, WS 2007/08 Lecture 5 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät für.
CS112 Intro to CS II with C++ Introduction. 6/25/2015Gene Itkis; cs1122 Problems and Programs Program helps articulate structure of Problem, and maybe.
Andreas Klappenecker [based on the slides of Prof. Welch]
1 Persistent data structures. 2 Ephemeral: A modification destroys the version which we modify. Persistent: Modifications are nondestructive. Each modification.
TCSS 342, Winter 2005 Lecture Notes
5.9 Heaps of optimal complexity
HOW TO SOLVE IT? Algorithms. An Algorithm An algorithm is any well-defined (computational) procedure that takes some value, or set of values, as input.
5.1 and 5.4 through 5.6 Various Things. Terminology Identifiers: a name representing a variable, class name, method name, etc. Operand: a named memory.
Stack and Queue.
ISOM MIS 215 Module 3 – Stacks and Queues. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Course Review Midterm.
Time O(log d) Exponential-search(13) Finger Search Searching in a sorted array time O(log n) Binary-search(13)
CS 61B Data Structures and Programming Methodology July 21, 2008 David Sun.
Kinetic data structures. Goal Maintain a configuration of moving objects Each object has a posted flight plan (this is essentially a well behaved function.
Λίστα Εργασιών Data Structures for Tree Manipulation D. Harel and R.E. Tarjan. Fast Algorithms for finding nearest common ancestors. SIAM J. Computing,
Amortized Algorithm Analysis COP3503 July 25, 2007 Andy Schwartz.
Four different data structures, each one best in a different setting. Simple Heap Balanced Heap Fibonacci Heap Incremental Heap Our results.
Heaps and basic data structures David Kauchak cs161 Summer 2009.
1ADS Lecture 11 Stacks contd.. ADS Lecture 113 Singly Linked list-based Stack Top of stack is head of list (can insert elements at head in constant.
Kinetic Heaps K, Tarjan, and Tsioutsiouliklis. Broadcast Scheduling Parametric and Kinetic Heaps Broadcast Scheduling Using a Kinetic Heap The Computational.
CSCI 383 Object-Oriented Programming & Design Lecture 25 Martin van Bommel.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
Scalable lock-free Stack Algorithm Wael Yehia York University February 8, 2010.
Lecture 10 b Stacks b Queues. 2 Stacks b A stack ADT is linear b Items are added and removed from only one end of a stack b It is therefore LIFO: Last-In,
CSE373: Data Structures & Algorithms Lecture Supplement: Amortized Analysis Hunter Zahn Summer 2016 CSE373: Data Structures & Algorithms1.
CSC317 Selection problem q p r Randomized‐Select(A,p,r,i)
Data Structures Interview Questions.
Self-Adjusting Data Structures
List Order Maintenance
MEMORY REPRESENTATION OF STACKS
Experimental evaluation of Navigation piles
Persistent Data Structures (Version Control)
Basic Data Structures.
Basic Data Structures.
CSE 143 Lecture 5 More Stacks and Queues; Complexity (Big-Oh)
Persistent deques.
What to do when you don’t know anything know nothing
Strict Fibonacci Heaps
Dynamic Sets (III, Introduction)
CSE 143 Lecture 8 More Stacks and Queues; Complexity (Big-Oh)
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
CSE 143 Lecture 8 More Stacks and Queues; Complexity (Big-Oh)
Presentation transcript:

1 Functional Data Structures Purely functional car cdr never modify only create new pairs only DAGs [C. Okasaki, Simple and efficient purely functional queues and deques, J. of Functional Programming, 5(4), , 1995] [H. Kaplan, R. Tarjan, Purely functional, real-time deques with catenation, Journal of the ACM, 46(5), , 1999] (Atomic values: Integers, Chars, Float, Bool,....) inc(()) = () inc(e::L’) = (e+1)::inc(L’) Strict evaluation Evaluate list now Lazy evaluation/memoization First add element when head needed and return function lazy incrementing the rest Example

List operations  makelist(x)  push(x,L)  pop(L)  inject(x,L)  eject(L)  catenate(K,L) 2 Catenable deques Catenable lists Deque Queue Stack x1x1 x2x2 x3x3 x4x4 x5x5 push pop inject eject head Deque = Double Endede Queue (Donald E. Knuth 74)

Catenable lists (slow) 3 cat((),L) = L cat(e::K,L) = e::cat(K,L) rev(L) = rev’(L,()) rev’((),T) = T rev’(e::L,T) = rev’(L,e::T) inject(e,(H,T)) = (H,e::T) Version 1 pop((e::H,T)) = (e,(H,T)) pop(((),T)) = (e,(T’,())) where e::T’ = rev(T) Version 2 (Invariant |H|≥|T|) pop((e::H,T)) = (e,(H,T)) if |H|  |T| = (e,(cat(H,rev(T)),()))if |H|<|T| Inject(e,(H,T))= (H,e::T) if |H|>|T| = (cat(H,rev(e::T)),()))if |H|  |T| Queues List reversal O(length 1 st list) O(|L|) Ex: ((1,2,3),(5,4))  [1,2,3,4,5] O(1) Strict O(1) amortized  = |T| Lazy O(1) amortized [C. Okasaki, Simple and efficient purely functional queues and deques, J. of Functional Programming, 5(4), , 1995] Bad if expensive operation repeated Good (Head,Tail)

4 cat((),L) = L cat(e::K,L) = e::cat(K,L) rev(L) = rev’(L,()) rev’((),T) = T rev’(e::L,T) = rev’(L,e::T) inject(e,(H,T)) = (H,e::T) Version 2 (Invariant |H|≥|T|) pop((e::H,T)) = (e,(H,T)) if |H|>|T| = (e,(cat(H,rev(T)),()))if |H|  |T| [C. Okasaki, Simple and efficient purely functional queues and deques, J. of Functional Programming, 5(4), , 1995] lazy evaluation lazy evaluation  recursive call first evaluated when 1 st element accessed lazy evaluation  everything evaluated when 1 st element accessed TRICK In cat(H,rev(T) the cost for rev (T) is paied by the subsequent pops (with no reversals) from the H part of the catenation. All pops deleting from H pays O(1) for doing O(1) work of the reverse.

5 Q0Q0 Q1Q1 Q2Q2 Q3Q3 Q4Q4 Q5Q5 v6v6 setup expensive lazy evaluation execute expensive cheap operations amortize cost of upcomming expensive lazy evaluation Q5Q5 only one of Q 5 or Q 5 is expensive

Real-time Queues i.e. strict worst-case O(1) time 6  incremental version of the amortized solution [R. Hood, R. Melville, Real-time queue operations in pure Lisp. Information Processing Letters, 13, 50-54, 1981] F makelist(x) = (0,(x),(),(x),(),(),()) inject(x,(d,F,A,B,C,D,E)) = f(f(d,F,A,B,C,D,x::E)) pop((0,F,A,(),(),x::D,E)) = (x,f(0,D,(),D,E,(),())) pop((d,x::F,A,B,C,D,E)) = (x,f(f(d-1,F,A,B,C,D,E))) f(d,F,A,B,x::C,D,E) = (d,F,A,B,C,x::D,E) f(d,F,A,x::B,C,D,E) = (d+1,F,x::A,B,C,D,E) f(d,F,x::A,(),(),D,E) = (d-1,F,A,(),(),x::D,E) if d>0 f(d,F,A,(),(),D,E) = (0,D,(),D,E,(),()) if d=0 ABCDE remaining elements in A (possibly negative) d pop inject dFABCDE Queue = ABCDE with first |A|-d removed F = prefix of queue with |F|  d+|B| 0  d+(|B|-|C|)/2 |E|+|A|/2  |D|+d

Queues [R. Hood, R. Melville, Real-time queue operations in pure Lisp. Information Processing Letters, 13, 50-54, 1981] [C. Okasaski, Simple and efficient purely functional queues and deques. Journal of Functional Programming 5,4, , 1995] Catenable lists [S.R. Kosaraju, Real-time simulation of concatenable double-ended queues by double-ended queues, Proc. 11th Annual ACM Symposium on Theory of Computing, , 1979] [S.R. Kosaraju, An optimal RAM implementation of catenable min double-ended queues, Proc. 5th Annual ACM-SIAM Symposium on Discrete Algorithms, , 1994] [J.R. Driscoll, D.D. Sleator, R.E. Tarjan, Fully persistent lists with catenation, Journal of the ACM, 41(5), , 1994] [A.L. Buchsbaum, R.E. Tarjan, Confluently persistent deques via data- structural bootstrapping, Journal of Algorithms, 18(3), , 1995] [H. Kaplan, R. Tarjan, Purely functional, real-time deques with catenation, Journal of the ACM, 46(5), , 1999] [H. Kaplan, C. Okasaki, R.E. Tarjan, Simple Confluently Persistent Catenable Lists, SIAM Journal of Computing 30(3), (2000)] 7 Strict, worst-case O(1) O(loglog k) Lazy, amortized O(1) Not confluently persistent Not funtional Lazy, amortized O(1) Strict, worst-case O(1) 2 O(log* k) O(log* k)

Functional Concatenable Search Trees  Search, update O(log n)  Catenation O(1) Open problems  Split O(log n) ?  Finger search trees with O(1) time catenation ?  Search trees with O(1) space per update ? 8 [G.S. Brodal, C.Makris, K. Tsichlas, Purely Functional Worst Case Constant Time Catenable Sorted Lists, In Proc. 14th Annual European Symposium on Algorithms, LNCS 4168, , 2006]