Skip to content

A simple and clear implementation of a binary heap in C# as .NET framework does not provide an implementation for this data structure

License

Notifications You must be signed in to change notification settings

itivadar/BinayHeap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Binay Heap

My idea was to create simple and clear implementation of the binary heap data structure. The .NET framework lacks an implementation for this data structure. However, binary heaps are needed for some algorithms like A* or IDA* search algorithms.

The implemented type is max-heap but it can be easy transformed into a min-heap if needed.

Creating a new binary heap

A new heap containing ints can be created as follows

H<int> heap = new H<int>();

Adding keys

After the heap is created, we can add new keys.

heap.AddKey(2);
heap.AddKey(4);
heap.AddKey(6);

This operation is O(log N) where N is the number of elements within the heap.

Getting the max

The main feature of the heap is that it get the max (or min) element in constant time.

var max = heap.PopMax();

This method removes and returns the max element of the heap. It is O(1) operation.

About

A simple and clear implementation of a binary heap in C# as .NET framework does not provide an implementation for this data structure

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages