public class BinaryHeap extends Object
| Constructor and Description |
|---|
BinaryHeap(int capacity)
This will initialize our heap with default size.
|
| Modifier and Type | Method and Description |
|---|---|
int |
delete(int x)
This will delete element at index x Complexity: O(log N)
|
boolean |
equals(Object o) |
int |
findMax()
This method returns the max element of the heap.
|
int |
hashCode() |
void |
insert(int x)
This will insert new element in to heap Complexity: O(log N) As worst case scenario, we need to traverse till the
root
|
boolean |
isEmpty()
This will check if the heap is empty or not Complexity: O(1)
|
boolean |
isFull()
This will check if the heap is full or not Complexity: O(1)
|
static void |
main(String[] args) |
void |
printHeap()
This method used to print all element of the heap
|
String |
toString() |
public BinaryHeap(int capacity)
capacity - the capacity of the heappublic boolean isEmpty()
public boolean isFull()
public void insert(int x)
x - the value to insertpublic int delete(int x)
x - the value to deletepublic void printHeap()
public int findMax()
public static void main(String[] args)
Copyright © 2023. All rights reserved.