Question: Exercise: Heaps Background A heap is a binary tree - based data structure that satisfies the heap property. In a max heap, the value of

Exercise: Heaps
Background
A heap is a binary tree-based data structure that satisfies the heap property. In a max heap, the value of any parent node is greater than or equal to the values of its
children. Conversely, in a min heap, the value of any parent node is less than or equal to the values of its children. Heaps are commonly used for priority queues,
resource allocation, and sorting algorithms.
Task
Your task is to implement a max or min heap. Create a Heap class, which can build either a min or max heap, depending on the build option: max or min. When
complete, calculate the BigO for your algorithm.
Specification
Initializer: Initializes an empty heap and sets the build type to max or min.
insert(value): Inserts a value into the heap while maintaining the min or max heap property:
extract(): Removes and returns the min or max value from the heap.
peek(): Returns the min or max value without removing it.
size(): Returns the number of elements in the heap.
is_empty(): Returns True if the heap is empty, otherwise False.
Implement the necessary helper methods (e.g., heapify, swap, etc.) to maintain the max heap property during insertion and extraction
Requirements
Your implementation should use an array-based representation for the heap. You may use the heap example code as a starting point. Java and Python versions are
not available. If you need assistance translating the C++ code into Java or Python, let me know. You can assume that the input values are integers.
 Exercise: Heaps Background A heap is a binary tree-based data structure

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!