Question

In: Computer Science

I have few questions to be ask for search in computer: 1) Draw a min heap...

I have few questions to be ask for search in computer:

1) Draw a min heap with at least 8 nodes.

2) What are two real life examples of a Priority Queue?

3) Draw a min heap with at least 8 nodes.

r

Solutions

Expert Solution

Draw a min heap with at least 8 nodes.

A heap data structure in computer science is spacial tree that satisifies the heap property, this just means that the parent is less than or equal to child node for a minimum heap A.K.A min heap.

Build a min heap : Let's take an array and make a heap with an empty heap using the wiliams method. We will insert the values 3,1,6,5,2,4,7 and 8. in our heap.

3 1 6 5 2 4 7 8

array

To add an element to a heap we must perform an up-heap operation(also known as bubbe-up, precolated-up,sift-up trickle-up,heapify-up, or cascade-up), by following this alogrithm:

  1. If heap is emptu place element at root.
  2. Add the element to the bottom level of heap .
  3. Compare the added element with its parent; if they are in the correct order, stop.
  4. If not, swap the element with its parent and return to the previous step.

First Insert 3 in root of the empty heap:

What are two real life examples of a Priority Queue?

  • Prim's algorithm implementaion cn be done using priority queues.
  • Dijkstra's shortest path alogrithm implementation can be done using queues.
  • Priority queues are used to sort heaps.
  • priority queuesare used in operating system for loading balance and interrupt handling.
  • priority queues are used in huffman codes for data compression.
  • In traffic light,depending upon the traffic, the colors will be given priority

Real example for priority queue:

Printer .

Each traffic light in our simulation would have an event scheduled for its next change. When a light changes to red, we schedule it's next change to green some bnumber of seconds later. When a light changes to green, we scheduled a change to yellow event some time a lttle later, and so on.

Each moving car on the street would have an event associated with the time it it needs to reach the next intersection along it's path. When it reaches that intersection, we schedule a new event for the intersection after that, and so on.

All scheduled event could be kept in a priority queue ordered on the time at which the event is scheduled. The main logic of the silumation is simply

while(simulation has not ended)

{

get next event form the priority queue;

trigger that event;

}


Related Solutions

On the subject of Social Determinants of Health, I have a few questions I have to...
On the subject of Social Determinants of Health, I have a few questions I have to answer like describe overall impression of how we are doing in terms of social determinants? What surprised you the most? Where do you see us doing a good job? What social determinants factors negatively the health of individuals? From a ethical standpoint how can we do bter as a country? As a state? As a community? As a individual?
Suppose you have a min-heap in an array a[] where: ● The root isstored at...
Suppose you have a min-heap in an array a[] where: ● The root is stored at index 1 ● There are 15 elements (in a[1]...a[15]) ● There are no duplicates (this is not true in general for heaps; but assume it is true for this problem). Fill in the blanks in the statements below; the resulting statement must be true for any heap obeying the above properties.There are/is at least ____6_______ elements in theheap that are/is larger than a[3] ""There...
I have draw a random sample of 20 of my neighbors. I ask them their income...
I have draw a random sample of 20 of my neighbors. I ask them their income (What can I say? I'm a nosy neighbor). My sample average (x bar) is $41,000. I want to create a 95% confidence interval around x bar. My estimated standard deviation is $5,000. What is the 95% confidence internal for the average income in my neighborhood? $38,652 to $43.347, $38,663 to $43,336, $38,809 to $43,191, or not enough information?
I have a few questions relating to ph and whatnot.. 1) Calculate the pH of 0.0010...
I have a few questions relating to ph and whatnot.. 1) Calculate the pH of 0.0010 M Ca(OH)2 solution. (to 2 decimal places) 2) Determine the pH of a KOH solution made by mixing 0.251 g KOH with enough water to make 1.00 � 102 mL of solution. 3) Calculate the pH of 0.0171 butanoic acid, Ka=1.52 x 10-5. Answer in 4 significant figures. 4) Calculate the pH of 0.00000M C5H5N solution. Kb=1.5 x 10-9. Answer in 3 decimal places....
Although the following questions ask you to draw diagrams, you do not have to submit these....
Although the following questions ask you to draw diagrams, you do not have to submit these. You do, however, need to know how to draw them. Suppose Apple has a monopoly on a new product, the iFraud. The market is characterized by:             Short Run Marginal Cost of Supply:             MC = 100 + 2Q             Short Run Average Total Cost:                      AC = 100 + Q + 150,000/Q             Marginal Willingness to Pay:                         P = 1600 – 4Q A....
I got the read-ahead package from the project staff. And I have a few questions. Q#1...
I got the read-ahead package from the project staff. And I have a few questions. Q#1 (100 points)   This table shows some of the info for the week. 20 sample M923’s were produced. It looks like the parts are in some kind of multiple per unit. The first section shows the quantity of each part and the total cost. But doesn’t anybody think that I’d be interested in knowing the price for the part? And I see the direct labor...
Hello, I have another case study to ask. Thank you. Question. For the last few days,...
Hello, I have another case study to ask. Thank you. Question. For the last few days, you have been taking care of Mr. Smith, a 30 years old patient with end stage cystic fibrosis. You have developed a caring relationship with Mr. Smith and his wife. They are both aware of the prognosis of his disease and realize that he has only a short time left to live. When Dr. William made rounds with you this morning, she told Mrs....
Let's suppose that you have a binary min-heap with S elements. Please write an an algorithm...
Let's suppose that you have a binary min-heap with S elements. Please write an an algorithm that will find all the elements that are in the heap that are smaller than a given value X. Please make sure that the time complexity of the algorithm that you propose has to be O(K), where is the number of elements smaller than X that is in the heap. Please type answer if you can
For somebody who has or currently works in the sports industry I have a few questions...
For somebody who has or currently works in the sports industry I have a few questions and if you could answer any I would greatly appreciate it. How did you choose this position or company over others in your field? What’s the most rewarding thing about working in sport and the most challenging? What advice can you give about how to best prepare for my future? What experiences, skills, or personality traits do you (does your company) look for in...
For somebody who has or currently works in the sports industry I have a few questions...
For somebody who has or currently works in the sports industry I have a few questions and if you could answer any I would greatly appreciate it. How did you get started in your field? What’s it like working at your company? What projects are you working on right now? What is your job like on a day-to-day basis? How did you choose this position or company over others in your field? What’s the most rewarding thing about working in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT