Interface IBinaryHeap<TKey, TValue>
Provides interface definition for a binary heap.
Namespace: AlgorithmsAndDataStructures.DataStructures.BinaryHeaps.API
Assembly: AlgorithmsAndDataStructures.dll
Syntax
public interface IBinaryHeap<TKey, TValue>
where TKey : IComparable<TKey>
Type Parameters
Name | Description |
---|---|
TKey | The type of the keys, based on which priorities in a priority queue are defined. |
TValue | The type of the values stored with keys. |
Methods
| Improve this Doc View SourceBubbleDown_Iteratively(Int32, Int32)
This method implements the bubble down/trickle down operation using iteration.
Declaration
void BubbleDown_Iteratively(int rootIndex, int heapArrayLength)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rootIndex | The index of the root element, the element for which the trickle down should be performed. |
System.Int32 | heapArrayLength | The length of the heap array. |
BubbleDown_Recursively(Int32, Int32)
This method implements the bubble down/trickle down operation using recursion.
Declaration
void BubbleDown_Recursively(int rootIndex, int heapArrayLength)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rootIndex | The index of the root element, the element for which the trickle down should be performed. |
System.Int32 | heapArrayLength | The length of the heap array. |
BubbleUp_Iteratively(Int32, Int32)
Moves the value in the given index, up in the heap till its position is found. The position is defined such to respect heap ordering property.
Declaration
void BubbleUp_Iteratively(int index, int heapArrayLength)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the element that should be bubbled up. |
System.Int32 | heapArrayLength | The length/size of the heap array. |
BuildHeap_Iteratively(Int32)
Builds a heap iteratively, and does so in situ.
Declaration
void BuildHeap_Iteratively(int heapArrayLength)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | heapArrayLength | The length of the heap array. |
BuildHeap_Recursively(Int32)
Builds a heap using recursion, and does so in situ.
Declaration
void BuildHeap_Recursively(int heapArrayLength)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | heapArrayLength | The length of the heap array. |
GetLeftChildIndexInHeapArray(Int32)
Returns the index of the left child for the given index in a heap array.
Declaration
int GetLeftChildIndexInHeapArray(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of a node in an array. |
Returns
Type | Description |
---|---|
System.Int32 | The index of the left child. |
GetNodeLevel(Int32)
Returns the level of a node in the heap, given the node's index in the heap array.
Declaration
int GetNodeLevel(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of a node in an array. |
Returns
Type | Description |
---|---|
System.Int32 | Returns the level of the node. |
GetParentIndex(Int32)
Returns the index of the parent for the given index in a heap array.
Declaration
int GetParentIndex(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of a node in an array. |
Returns
Type | Description |
---|---|
System.Int32 | The index of the parent. |
GetRightChildIndexInHeapArray(Int32)
Returns the index of the right child for the given index in a heap array.
Declaration
int GetRightChildIndexInHeapArray(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of a node in an array. |
Returns
Type | Description |
---|---|
System.Int32 | The index of the right child. |
Insert(KeyValuePair<TKey, TValue>, Int32)
This method is for inserting a new value into heap.
Declaration
void Insert(KeyValuePair<TKey, TValue> keyValue, int heapArrayLength)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<TKey, TValue> | keyValue | The key-value to be inserted into the heap. |
System.Int32 | heapArrayLength | The length of the heap array. |
TryFindRoot(out KeyValuePair<TKey, TValue>, Int32)
This method is for finding the root of the heap, without removing it.
Declaration
bool TryFindRoot(out KeyValuePair<TKey, TValue> keyValue, int heapArrayLength)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<TKey, TValue> | keyValue | The key-value of the root. |
System.Int32 | heapArrayLength | The length of the heap array. |
Returns
Type | Description |
---|---|
System.Boolean | True in case of success, and false in case of failure. |
TryRemoveRoot(out KeyValuePair<TKey, TValue>, Int32)
This method is for removing the root of the heap. In a MinHeap and MinMaxHeap this is the min, and in a MaxHeap and MaxMinHeap this is the max.
Declaration
bool TryRemoveRoot(out KeyValuePair<TKey, TValue> keyValue, int heapArrayLength)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<TKey, TValue> | keyValue | The key-value of the root. |
System.Int32 | heapArrayLength | The length of the heap array. |
Returns
Type | Description |
---|---|
System.Boolean | True in case of success, and false otherwise. |