You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A priority queue is an abstract data type that behaves similarly to the normal queue except that each element has some priority, i.e., the element with the highest priority would come first in a priority queue. The priority of the elements in a priority queue will determine the order in which elements are removed from the priority queue.
The priority queue supports only comparable elements, which means that the elements are either arranged in an ascending or descending order.
For example, suppose we have some values like 1, 3, 4, 8, 14, 22 inserted in a priority queue with an ordering imposed on the values is from least to the greatest. Therefore, the 1 number would be having the highest priority while 22 will be having the lowest priority.
int parent(int i): This function returns the index of the parent node of a child node, i.e., i.
int left_child(int i): This function returns the index of the left child of a given index, i.e., i.
int right_child(int i): This function returns the index of the right child of a given index, i.e., i.
void moveUp(int i): This function will keep moving the node up the tree until the heap property is restored.
void moveDown(int i): This function will keep moving the node down the tree until the heap property is restored.
void removeMax(): This function removes the element which is having the highest priority.
void insert(int p): It inserts the element in a priority queue which is passed as an argument in a function.
void delete(int i): It deletes the element from a priority queue at a given index.
int get_Max(): It returns the element which is having the highest priority, and we know that in max heap, the root node contains the element which has the largest value, and highest priority.
int get_Min(): It returns the element which is having the minimum priority, and we know that in max heap, the last node contains the element which has the smallest value, and lowest priority.
The text was updated successfully, but these errors were encountered:
A priority queue is an abstract data type that behaves similarly to the normal queue except that each element has some priority, i.e., the element with the highest priority would come first in a priority queue. The priority of the elements in a priority queue will determine the order in which elements are removed from the priority queue.
The priority queue supports only comparable elements, which means that the elements are either arranged in an ascending or descending order.
For example, suppose we have some values like 1, 3, 4, 8, 14, 22 inserted in a priority queue with an ordering imposed on the values is from least to the greatest. Therefore, the 1 number would be having the highest priority while 22 will be having the lowest priority.
int parent(int i): This function returns the index of the parent node of a child node, i.e., i.
int left_child(int i): This function returns the index of the left child of a given index, i.e., i.
int right_child(int i): This function returns the index of the right child of a given index, i.e., i.
void moveUp(int i): This function will keep moving the node up the tree until the heap property is restored.
void moveDown(int i): This function will keep moving the node down the tree until the heap property is restored.
void removeMax(): This function removes the element which is having the highest priority.
void insert(int p): It inserts the element in a priority queue which is passed as an argument in a function.
void delete(int i): It deletes the element from a priority queue at a given index.
int get_Max(): It returns the element which is having the highest priority, and we know that in max heap, the root node contains the element which has the largest value, and highest priority.
int get_Min(): It returns the element which is having the minimum priority, and we know that in max heap, the last node contains the element which has the smallest value, and lowest priority.
The text was updated successfully, but these errors were encountered: