Consider the following two methods for implementing the buildHeap function for a
ID: 3799937 • Letter: C
Question
Consider the following two methods for implementing the buildHeap function for a binomial heap. The first method is to represent all the input values as B_0 trees and to merge them one at a time into an initially empty heap. We can estimate the run time of this approach by considering the number of bits that change when repeatedly adding one to binary to a number that is initially zero. Develop an expression for the run time of this version of buildHeap in terms of N, where N = 2^p The second method is to represent all the input values as B_0 trees, place them on a queue, then repeatedly take two trees from the head of the queue, merge them, and put the resulting tree on the back of the queue. This process is repeated until the queue contains only one tree. Develop an expression for the run time of this version of buildHeap in terms of N, where N = 2^p. Considering all factors, which method is best? Explain.Explanation / Answer
public category MaxHeap
personal int[] Heap;
personal int size;
personal int maxsize;
personal static final int FRONT = 1;
public MaxHeap(int maxsize)
number.MAX_VALUE;
}
personal int parent(int pos)
come pos / 2;
}
personal int leftChild(int pos)
come (2 * pos);
}
personal int rightChild(int pos)
come (2 * pos) + 1;
}
personal Boolean isLeaf(int pos)
{
if (pos >= (size / 2) && pos <= size)
come true;
}
come false;
}
personal void swap(int fpos,int spos)
personal void maxHeapify(int pos)
Heap[pos] < Heap[rightChild(pos)])
{
if (Heap[leftChild(pos)] > Heap[rightChild(pos)])
{
swap(pos, leftChild(pos));
maxHeapify(leftChild(pos));
else
}
}
}
public void insert(int element)
}
public void print()
kid : " + Heap[2*i]
+ " RIGHT kid :" + Heap[2 * i + 1]);
System.out.println();
}
}
public void maxHeap()
}
public int remove()
{
int popped = Heap[FRONT];
Heap[FRONT] = Heap[size--];
maxHeapify(FRONT);
come popped;
}
public static void main(String...arg)