Skip to Main Content
Haskell Data Analysis cookbook
book

Haskell Data Analysis cookbook

by Nishant Shukla
June 2014
Beginner to intermediate content levelBeginner to intermediate
334 pages
6h 8m
English
Packt Publishing
Content preview from Haskell Data Analysis cookbook

Implementing a min-heap data structure

A heap is a binary tree with both a shape property and a heap property. The shape property enforces the tree to behave in a balanced way by defining each node to have two children unless the node is in the very last level. The heap property ensures that each node is less than or equal to either of its child nodes if it is a min-heap, and vice versa in case of a max-heap.

Heaps are used for constant time lookups for maximum or minimum elements. We will use a heap in the next recipe to implement our own Huffman tree.

Getting started

Install the lens library for easy data manipulation:

$ cabal install lens

How to do it...

  1. Define the MinHeap module in a file MinHeap.hs:
    module MinHeap (empty, insert, deleteMin, weights) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Haskell Quick Syntax Reference: A Pocket Guide to the Language, APIs, and Library

Haskell Quick Syntax Reference: A Pocket Guide to the Language, APIs, and Library

Stefania Loredana Nita, Marius Mihailescu

Publisher Resources

ISBN: 9781783286331Supplemental Content