Union-based heaps

Union-based heaps

Binary heap, problems and how to solve them with Skew and Pairing heaps #Haskell #Python #CS (slides from KyivPy 11 talk)

B9b7a5ffa24e2af6f877a7950461ba0f?s=128

Oleksii Kachaiev

October 26, 2013
Tweet

Transcript

  1. Union-based heaps Alexey Kachayev KyivPy #11 Sunday, October 27, 13

  2. •@kachayev •github: kachayev •kachayev@gmail.com •attendify.com Sunday, October 27, 13

  3. Problem extract min (quickly) Sunday, October 27, 13

  4. •priority queue •bounded leadership •greedy algorithms •.. and more Sunday,

    October 27, 13
  5. Solution heaps Sunday, October 27, 13

  6. •binary •binominal •2/3 •fibonacci •leftist •skew •pairing Heaps Sunday, October

    27, 13
  7. In Python heapq.* Sunday, October 27, 13

  8. •binary heap •push •pop •heapify •nlargest •merge heapq. Sunday, October

    27, 13
  9. Sunday, October 27, 13

  10. Sunday, October 27, 13

  11. Sunday, October 27, 13

  12. Sunday, October 27, 13

  13. Use: Dijkstra Sunday, October 27, 13

  14. Sunday, October 27, 13

  15. Sunday, October 27, 13

  16. •push = O(log N) •pop = O(log N) •merge =

    O(N+M) •build = O(N) Binary Sunday, October 27, 13
  17. •union :( •size bounding •array resizing •mutable But.. Sunday, October

    27, 13
  18. Union-based Sunday, October 27, 13

  19. •still one tree •union is a King •low branching •persistent

    Idea Sunday, October 27, 13
  20. Persistent each operation returns new structure Sunday, October 27, 13

  21. Skew heaps Sunday, October 27, 13

  22. Sunday, October 27, 13

  23. Haskell Sunday, October 27, 13

  24. Skew Python 2.* only Sunday, October 27, 13

  25. Sunday, October 27, 13

  26. •push= O(log N)* •pop= O(log N)* •union= O(log N)* Skew

    Sunday, October 27, 13
  27. Pairing heaps Sunday, October 27, 13

  28. Sunday, October 27, 13

  29. Haskell Sunday, October 27, 13

  30. Pairing Python 2.* only Sunday, October 27, 13

  31. Sunday, October 27, 13

  32. Sunday, October 27, 13

  33. •push= O(1) •pop= O(1)* •union= O(1) Pairing Sunday, October 27,

    13
  34. More more persistent structure Sunday, October 27, 13

  35. More fn.py module Sunday, October 27, 13

  36. Links http://en.wikipedia.org/wiki/Heap_(data_structure) http://en.wikipedia.org/wiki/Skew_heap http://interactivepython.org/runestone/static/ pythonds/Trees/heap.html https://gist.github.com/kachayev/7161521 https://gist.github.com/kachayev/6081643 https://gist.github.com/kachayev/7167046 Sunday, October

    27, 13
  37. Q/A Sunday, October 27, 13