Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Convert reheapUp (bubbleUp) Heap algorithm from iterative to recursive I need a working recursive version of this reheapUp algorithm, which is used when something is

Convert reheapUp (bubbleUp) Heap algorithm from iterative to recursive

I need a working recursive version of this reheapUp algorithm, which is used when something is enqueued into the heap. Here is the iterative version of the algorithm:

private void reheapUp(T element) // Current lastIndex position is empty. // Inserts element into the tree and ensures shape and order properties. { int hole = lastIndex; while ((hole > 0) // hole is not root and element > hole's parent  && (element.compareTo(elements.get((hole - 1) / 2)) > 0)) { // move hole's parent down and then move hole up  elements.set(hole,elements.get((hole - 1) / 2)); hole = (hole - 1) / 2; } elements.set(hole, element); // place element into final hole } 

Every attempt i've made has resulted in stack overflow. thanks in advance!

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

Oracle Database 19c DBA By Examples Installation And Administration

Authors: Ravinder Gupta

1st Edition

B09FC7TQJ6, 979-8469226970

More Books

Students also viewed these Databases questions

Question

Question How are IRAs treated for state tax law purposes?

Answered: 1 week ago