Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this presentation? Why not share!

2,120 views

Published on

This talk is based on Chris Okasaki's book title Purely Functional Data Structures. The gist is that immutable and persistent data structures can be designed without sacrificing performance.

Published in:
Technology

No Downloads

Total views

2,120

On SlideShare

0

From Embeds

0

Number of Embeds

644

Shares

0

Downloads

36

Comments

0

Likes

6

No embeds

No notes for slide

- 1. Purely Functional Data Structures Demystiﬁed Mohit Thatte Functional Conf 2014, Bangalore
- 2. About Me Work The great outdoors @mohitthatte github.com/pastafari
- 3. Why? What? Learnings
- 4. Image: User:Matthew,Wikimedia Commons
- 5. Programs that use Maps Towers of Abstraction Map as ADT Map implementation Primitives…
- 6. Image: https://www.ﬂickr.com/photos/cverdier/4321365261
- 7. Any sufﬁciently advanced data structure is indistinguishable from magic With apologies to Arthur C. Clarke!
- 8. Why? What? Learnings
- 9. Data Structures
- 10. AbstractionsData
- 11. Abstract Data Type Invariants Stack push, pop LIFO Name Operations ADT
- 12. Image: Apollo 8,NASA
- 13. Change perspective Think like a data structure designer
- 14. The ADT Challenge Given an ADT, give a correct implementation of all operations.
- 15. Source: https://www.ﬂickr.com/photos/manicstreetpreacher/5310984196/
- 16. “You can program in any language you want… as long as it is imperative”
- 17. make it easier to reason about code Why Functional? Immutability Persistence
- 18. x = 5 y = x + 1 pr!nt x x = [1,2] y = x << 3 pr!nt x 5 is immutable [1,2] is NOT!
- 19. x = [1,2] foo(x) x ("et [x [1 2]] (foo x) x) What is x now? What is x now?
- 20. The ADT Challenge Given an ADT, give a correct and functional implementation of all operations.
- 21. Performance matters too. A lot.
- 22. The ADT Challenge Correct Performant Functional X
- 23. The ADT Challenge Given an ADT, give a correct, functional and performant implementation of all operations.
- 24. Challenge Accepted!
- 25. Why? What? Learnings
- 26. 3 -2 3 -2 The Pair cons (def x (cons 3 -2)) (head x) (ta!" x) 3 -2 head ta!"
- 27. Cons, the Magniﬁcent (defn ta!" [z] (z (fn [p q] q))) (defn head [z] (z (fn [p q] p))) (defn cons [x y] (fn [m] (m x y)))
- 28. Voila, a list! 3 2 1 nil (cons 3 (cons 2 (cons 1 n!")))
- 29. And so it goes… Pair List Sets …
- 30. A functional ‘update’
- 31. 3 2 1 nil 3 4 Structural Sharing
- 32. Queue ADT enqueue peek dequeue append an e"ement f!rst e"ement rema!n!ng e"ements Invar!ant FIFO Operat!ons
- 33. Queue ADT
- 34. Ideas? Structural Decomposition Use a List
- 35. Pattern Matching
- 36. Correct Functional Performant
- 37. Use 2 lists… Be clever!
- 38. Correct Functional Performant
- 39. Amortized Analysis Care about a sequence of operations rather than worst case Earn credits each time you don’t do an expensive operation, spend credits when you do
- 40. Why? What? Learnings
- 41. Map ADT put get assoc!ate a key w!th va"ue "ookup key, return va"ue de"ete remove key & va"ue Invar!ant Operat!ons what you put !s what you get
- 42. Map ADT
- 43. Ideas?
- 44. Use a list? Nope. Too slow.
- 45. Use a Tree Yep!
- 46. Source: Wikipedia
- 47. All is well… 13 15 17 21 11 9 12
- 48. 13 … until this happens 15 17 21
- 49. स"तuलन का होना ब,त ज़.री 1 !
- 50. Balance is essential
- 51. Red Black Tree No red node can have a red child Every path from root to an empty node contains the same number of black nodes Guibas, Sedgewick 1978 Each node is colored Red or Black
- 52. Red Black Tree Source: Wikipedia
- 53. Red Black Tree Source: Wikipedia 7
- 54. Red Black Tree Source: Wikipedia 7
- 55. Red Black Tree Source: Wikipedia 7
- 56. Red Black Tree Source: Wikipedia 7
- 57. Red Black Tree Source: Wikipedia 7
- 58. Red Black Tree Source: Wikipedia 7
- 59. z a b c d a b y x y x z c d y x z x y z a b c d a b c d a b c d y z x
- 60. Pattern Matching is awesome!
- 61. Persistent Bit-Partitioned Vector Trie Phil Bagwell, Rich Hickey
- 62. Source: Wikipedia
- 63. Image: Jean Niklas L’orange http://hypirion.com/musings/understanding-persistent-vector-pt-1
- 64. Why? What? Learnings
- 65. Abstraction is vital
- 66. Study implementations to understand tradeoffs.
- 67. Structural Decomposition Structural Sharing
- 68. Amortized Analysis ! Laziness
- 69. Extreme Cleverness DJ Spiewak ©
- 70. Further study
- 71. Persistent vectors in Clojure http://hypirion.com/musings/understanding-persistent-vector-pt-1
- 72. Red Black Trees http://www.eternallyconfuzzled.com/tuts/datastructures/jsw_tut_rbtree.aspx Julienne Walker
- 73. Persistent Data Structures http://debasishg.blogspot.in/2010/06/functional-data-structures-in.html
- 74. Coursera https://www.coursera.org/course/algo Algorithms, Tim Roughgarden https://www.coursera.org/course/algs4partI Algorithms, Wayne &Sedgewick

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment