1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
forsale [732]
3 years ago
5

Please write down a java program for below instruction.Min-Heap: Construct a Min_Heap from the following set of integers. Rememb

er to use successive adds to arrive at your final Heap. (You do not need to show all the intermediate steps, however, showing those can help in case you make an error somewhere down the line.)1, 19, 7, 5, 6, 42, 21, 13, 56, 78, 29, 3, 14
Remove_Min: Show the result of two successive Remove_Min operations on the heap formed in part a.Perform the following operations on the Min_Heap: add(45)
As you must have noticed the set of integers provided to both the BST and Heap problems were the same. However, the structures formed are vastly different.

What can you say about the relative heights (and therefore the worst-case cost of operations) of the BST as compared to the Heap?

What conclusions are you able to draw regarding the relative efficiency of the 2 data structures? (Remember that log213 = 3.7)
Computers and Technology
1 answer:
Leona [35]3 years ago
4 0

Answer:

Following are the program in the Java Programming Language.

//define class

class Heap{

 //set private integer data type array variable

  private int a[];

 //set two private integer data type variables

  private int s,capacity;

 //define private void function for down heap

  private void downheap(int indx) {

    //set if conditional statement

   if(indx>=s)return;

   //set integer type variable and initialize

   int lft=2*indx+1;

   int rgt=2*indx+2;

   int min=indx;

   //set the if-else if conditional statement  

   if(rgt<=s&&a[rgt]<a[indx])

     min=rgt;

   else if(lft<=s&&a[lft]<a[min])

     min=lft;

   //check index is not equal to min    

   if(indx!=min){

     //perform swapping

     int temp=a[indx];

     a[indx]=a[min];

     a[min]=temp;

     downheap(min);

   }  

  }

  //define private void type function for upheap

  private void upheap(int indx) {

      if(indx==0)return;

      int parent=(indx-1)/2;

      if(a[indx]<a[parent]) {

          int temp=a[indx];

          a[indx]=a[parent];

          a[parent]=temp;

          upheap(parent);

      }

  }

 

 public Heap(int q) {

   a=new int [q];

   s=0;

   capacity=q;

 }

 public int _size () {

   return s;

 }

 public int minLookup() {

   if(s>0)return a[0];

   return 0;

 }

 public int remove() {

   int data=a[0];

   a[0]=a[s-1];

   s--;

   downheap(0);

   return data;

 }

 

 public void add (int data) {

   if(s>=capacity)return;

   a[s++] = data;

   upheap(s-1);  

 }

 

 public void print_heap() {

   System.out.print("Heap : ");

   for(int i=0;i<s;i++) {

     System.out.print(a[i]+" ");

   }

   System.out.println();

 }

}

//define class to define main method

public class Main {

 //main method

 public static void main(String srgs[]) {

   //cretae class object

   Heap heap = new Heap(20);

   //call function through object with argument list

   heap.add(1);

   heap.add(19);

   heap.add(7);

   heap.add(5);

   heap.add(6);

   heap.add(42);

   heap.add(21);

   heap.add(13);

   heap.add(56);

   heap.add(78);

   heap.add(29);

   heap.add(3);

   heap.add(14);

   heap.print_heap();

   //print the Output and remove the minimum element

   System.out.println("Minimum element : "+heap.remove());

   heap.print_heap();

   System.out.println("minimum element : "+heap.remove());

   heap.add(45);

   heap.print_heap();

  }

}

<u>Output:</u>

Heap : 1 5 3 13 6 7 21 19 56 78 29 42 14

Minimum element : 1

Heap : 3 5 7 13 6 14 21 19 56 78 29 42

Minimum element : 3

Heap : 7 5 21 13 6 14 42 19 56 78 29 45

Explanation:

Here, we define a class "Heap" inside the class.

  • Set private integer data type array variable.
  • set private two integer data type variables.
  • Then, we define private void type function "downheap()" for down heap and pass an integer data type argument list in its parameter "indx".
  • Then, we define private void type function "upheap()" for upper heap and pass an integer data type argument list in its parameter "indx".
  • Define constructor of the class for the capacity pf the array list.
  • Define void type function "add()" for adding elements in heap.
  • Define void type function "print_heap()" to print the heap.

Finally, we define class to define main function and we create the object of the class "Heap"  then, call all the functions through the class object abd print the output.

You might be interested in
How to print<br> 1<br> 321<br> 54321<br> 7654321<br> triangle pattern in python
krok68 [10]

Hope this helps, Upvote if you like it :)

6 0
2 years ago
White lines
kykrilka [37]

Answer:

Its B                                                                                                                                            

Explanation:

7 0
3 years ago
Read 2 more answers
A vlan ________.
tensa zangetsu [6.8K]

A vlan can span multiple interconnected switches.

<h3>What is a vlan?</h3>

A virtual LAN (VLAN) is a logical overlay network that groups together a subset of devices that share a physical LAN, isolating the traffic for each group.

A LAN is a group of computers or other devices in the same place -- e.g., the same building or campus -- that share the same physical network.

Each virtual switch, or VLAN, is simply a number assigned to each switch port.

For example, the two switch ports in the red mini-switch might be assigned to VLAN #10 . The two ports in the orange mini-switch might be assigned to VLAN #20 .

VLANs can be used for different groups of users, departments, functions, etc., without needing to be in the same geographical area.

VLANs can help reduce IT cost, improve network security and performance, provide easier management, as well as ensuring network flexibility.

To learn more about vlan, refer

https://brainly.in/question/2890503

#SPJ4

6 0
1 year ago
.true or false? one disadvantage of cloudware is that it is never free<br> A. true<br> B. false
ser-zykov [4K]

Answer:

true

Explanation:

cloudware is used for many reasons and It is sometimes too much of an expense to the company

7 0
3 years ago
Hypertext Markup language (HTML) version _____ added support for style sheets to give web designers greater control over page la
Ipatiy [6.2K]

Answer:

4.01 version .

Explanation:

A hypertext Markup language is used for designing the web page when we added the CSS on the web page we can create the web page more efficient manner and also there is more control over the web page because we can easily call the classes of CSS.

The Hypertext Markup language version 4.01 provides greater flexibility on the web page also We can also control the page layout in a very easy manner. The appearance of the web page is good as compared to version HTML 4

8 0
3 years ago
Other questions:
  • Where does the term for a star network describe? A) a network for Department of Defense scientists to share data about the stars
    13·2 answers
  • Which of these describes the functionality of a database? Check all of the boxes that apply.
    10·2 answers
  • Join my discord server! CODE IS (CebjBXN)​
    12·2 answers
  • can you give me a tip to fix my SIM card becuaus when i put it on my phone it has no signal , can anyone fix this , thank you.​
    9·2 answers
  • Please answer immediately!!!
    6·1 answer
  • Haley is responsible for checking the web server utilization. Which things should she review while checking the server utilizati
    8·2 answers
  • 2. Explain the difference between a JMP instruction and CALL instruction
    6·1 answer
  • What are general purpose computer and special purpose computer?​
    10·2 answers
  • Which of the following best describes a hotspot as
    10·1 answer
  • consider a pipelined risc cpu with 14 stages. what is maximum speedup of this cpu over a non-pipelined implementation?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!