Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MinHeap Forthisassignment, you will be coding a MinHeap that is backed by an array of contiguous elements. Here is a tree and array representation of




MinHeap


Forthisassignment, you will be coding a MinHeap that is backed by an array of contiguous elements. Here is a tree and array representation of the same MinHeap:

IMPORTANT:

  • You will be given 5 attempts on this assignment, with a 30 minute cooldown between submissions.
  • Please run your code before each submission to ensure that there are no formatting errors! If there are formatting errors in your code, your code will not be graded and a submission attempt will be logged. For more information, please review the Vocareum overview below.

Properties


A MinHeap is a type of binary tree with two main properties:

  • Shape Property: The tree must be complete. All levels of the tree must be full except the bottom-most level. If the bottom-most level is not full, it must be filled from left to right with no gaps.
  • Order Property: Each node's data is smaller than the data in its children. There is no explicit relationship between sibling nodes.

These properties guarantee that the smallest element in the heap will be at the root of the heap.

Implementation Details


Although heaps are usually classified as a type of tree, they are commonly implemented using an array due to their completeness. In your implementation, you should leave index 0 empty and begin your heap at index 1. This will make the arithmetic for finding parent and children indices simpler.

When resizing your backingArray, double the current capacity. Therefore, if the initial capacity is 13, the first resize should bring the total backingArray capacity to 26. Note that this includes the 0th index!

You may assume that your implementation does not need to handle duplicate elements. That is, the add method will never be passed duplicates and the remove method will never have to deal with the heap having duplicates. To be clear, your implementation would most likely work even if we were to test for duplicates; however, this will help remove ambiguity surrounding grading and testing your implementation.

Unlike your BST homework, you are not required to use recursion in this assignment. Use whatever you find most intuitive - recursion, iteration, or both. However, regardless of the technique you use, make sure to meet the efficiency requirements as discussed in this course.

imageimageimageimageimageimageimageimageimageimageimageimage

Initial MinHeap add() Example 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9

Step by Step Solution

There are 3 Steps involved in it

Step: 1

implementation of a MinHeap in Java minheap implementation using array public class MinHeap private ... 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

Introduction to Algorithms

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

3rd edition

978-0262033848

More Books

Students also viewed these Programming questions

Question

Using a graphing utility, graph y = cot -1 x.

Answered: 1 week ago

Question

What does a polygraph measure and why are its results questionable?

Answered: 1 week ago