Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Master The Art Of Data Storytelling With Visualizations

Authors: Alexander N Donovan

1st Edition

B0CNMD9QRD, 979-8867864248

More Books

Students also viewed these Databases questions

Question

What is the difference between Net return and gross return

Answered: 1 week ago