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
The next elected president should be someone who can be very nice, kind, stick-up for him/herself, and take care of the people w
PSYCHO15rus [73]

Answer:trump

Explanation:

3 0
3 years ago
Read 2 more answers
"So far this month you have achieved $100.00 in sales, which is 50% of your total monthly goal. With only 5 more workdays this m
Rus_ich [418]

Answer:

$20 per day for next 5 working days.

Explanation:

if 50% is $100.00 another $100 need to achieve in 5 days.

100/5=20

3 0
3 years ago
Read 2 more answers
Role and responsibility of an IT professional
RUDIKE [14]
Create the computer, network, and communication systems that an organization needs
4 0
2 years ago
Assume that you have been hired by a small veterinary practice to help them prepare a contingency planning document. The practic
nikdorinn [45]

Answer:

Answer explained below

Explanation:

Given: The information provided is given as follows:

  • There is a small veterinary practice which includes the services like office visits, surgery, hospitalization and boarding.
  • The clinic only has a small LAN, four computers and internet access.
  • The clinic only accepts cats and dogs.
  • Hurricanes are the major threatening factor in the geographical region where the clinic is located.
  • The clinic is established in a one-story building with no windows and meet all the codes related to hurricanes.
  • As public shelters do not allow animals to stay when there is a possibility of hurricanes, therefore the clinic does not accept animals for boarding during that time

Contingency planning documents for the tasks given is as follows:

  1. Threat category along with their business impact:
  • Hurricane: It is given that the region where the clinic is located is highly threatened by hurricanes. This type of disaster can affect the life of the employees as well as patients present in the building. Also, in case of a strong hurricane, the building can also be damaged.
  • Preventive measures: Separate shelters can be installed for animals in case of emergency.

  • Fire: In case of fire due to malfunctioning of any electrical equipment or any other reason, there is no window or emergency exit available. It can damage the building and the life of the employees and animals will be in danger.
  • Preventive measures: Services should be provided to all the electrical equipment’s from time to time and emergency exits should be constructed so that there is a way to get out of the building in case the main entrance is blocked due to any reason in the time of emergency.

  • Viral Influenza: If an employee or animal is suffering from any serious viral disease. That viral infection can easily spread to others and make other animals as well as employees sick. If the employees working in the clinic are sick. This will highly affect the efficiency of them which will then affect the business.
  • Preventive measures: This can be avoided by giving necessary vaccines to the employees from time to time and taking care of the hygiene of the patient as well as the clinic which will make the chance of infection to spread low.

  • Flood: In case of a flood like situation, as given the building has only one story and there is no emergency exit for employees and animals to escape. This can put the life of the employees and animals in danger and can affect the working of the clinic as well.
  • Preventive measures: This can be prevented by collecting funds and increasing the story’s in the building or constructing alternate site location so that in case of emergency, the animals or employees can be shifted to other locations.
4 0
4 years ago
The Hazard Communication Standard, commonly called the “Right-to-Know” law, gives you the right to know what information?
statuscvo [17]
Lets you know if their are any certain hazards or messes on the property like mold or ants
8 0
3 years ago
Other questions:
  • Gettier contributed to what we know about the __________ model, while Rosch contributed to what we know about the __________ mod
    12·2 answers
  • In the Word 2016 window, where is the Status bar located?
    11·1 answer
  • An executable file that was determined to be infected with a virus was terminated from the running processes list. However, afte
    14·1 answer
  • What is the purpose of the Excel Function Reference?
    9·1 answer
  • A ___ is an online collaborative event that may include such features as chat, slideshows, and PowerPoint presentations.
    8·1 answer
  • 8.18 **zyLab: Schedule Generator Write this program using an IDE. Comment and style the code according to the CS 200 Style Guide
    13·1 answer
  • Submit your newsletter that includes the following: two or three columns a title at least three graphics, but not more than six
    10·2 answers
  • चार फरक छुट्याउनुहोस् ।) 3. Write down any four provisions of cyber ethic साइबर नैतिकताका कुनै चार प्रावधानहरु लेख्नुहोस् ।​
    11·1 answer
  • Today's consoles and games have audio features that rival cinematic audio.<br> True or False?
    6·2 answers
  • Consumers affect which goods and services are produced because they _____.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!