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
Ivahew [28]
2 years ago
6

Once you have your heap structure created, next you must use it as a backing structure to a priority queue. Develop a PriorityQu

eue data structure in a file named PriorityQueue that is backed by a linked heap. Implement the normal methods that accompany a priority queue structure:
SAT
1 answer:
saveliy_v [14]2 years ago
6 0

Using the knowledge in computational language in python it is possible to write a code that Develop a PriorityQueue data structure in a file.

<h3>Writting the code in python:</h3>

<em>import sys</em>

<em>class Node:</em>

<em>def __init__(self,key):</em>

<em>self.left = None</em>

<em>self.right = None</em>

<em>self.val = key</em>

<em>self.parent = None</em>

<em>class MinHeap:</em>

<em>def __init__(self, maxsize):</em>

<em>self.maxsize = maxsize</em>

<em>self.size = 0</em>

<em>self.Heap = Node(-1 * sys.maxsize )</em>

<em>self.FRONT = self.Heap</em>

<em># A utility function to do inorder tree traversal</em>

<em>def isLeaf(self, node):</em>

<em>if node.left == None and node.right == Node:</em>

<em>return True</em>

<em>return False</em>

<em># Function to swap two nodes of the heap</em>

<em>def swap(self, node1, node2):</em>

<em>node1.data, node2.data = node2.data, node1.data</em>

<em># Function to heapify the node at pos</em>

<em>def minHeapify(self, node):</em>

<em># If the node is a non-leaf node and greater</em>

<em># than any of its child</em>

<em>if not self.isLeaf(node):</em>

<em>if (node.data > node.left.data or</em>

<em>node.data > node.right.data):</em>

<em># Swap with the left child and heapify</em>

<em># the left child</em>

<em>if node.left.data < node.right.data:</em>

<em>self.swap(node, node.left)</em>

<em>self.minHeapify(node.left)</em>

<em># Swap with the right child and heapify</em>

<em># the right child</em>

<em>else:</em>

<em>self.swap(node, node.right)</em>

<em>self.minHeapify(node.right)</em>

<em># Function to insert a node into the heap</em>

<em>def insert(self, element):</em>

<em>if self.size >= self.maxsize :</em>

<em>return</em>

<em>self.size+= 1</em>

<em>self.bst_insert(FRONT, element)</em>

<em>current = FRONT</em>

<em>while current.parent != None and current.data < current.parent.data:</em>

<em>self.swap(current, current.parent)</em>

<em>current = current.parent</em>

<em># Function to print the contents of the heap</em>

<em>def Print(self):</em>

<em>self.inorder()</em>

<em># Function to build the min heap using</em>

<em># the minHeapify function</em>

<em>def inorder(self, root):</em>

<em>if root:</em>

<em>inorder(root.left)</em>

<em>print(root.val)</em>

<em>inorder(root.right)</em>

<em>def bst_insert(self, root, node):</em>

<em>if root is None:</em>

<em>root = node</em>

<em>else:</em>

<em>root.next = node</em>

<em>self.FRONT = node</em>

<em># Driver Code</em>

<em>if __name__ == "__main__":</em>

<em>r = Node(50)</em>

<em>bst_insert(r,Node(30))</em>

<em>bst_insert(r,Node(20))</em>

<em>bst_insert(r,Node(40))</em>

<em>bst_insert(r,Node(70))</em>

<em>bst_insert(r,Node(60))</em>

<em>bst_insert(r,Node(80))</em>

<em># Print inoder traversal of the BST</em>

<em>inorder(r)</em>

<em>print('The minHeap is ')</em>

<em>minHeap = MinHeap(15)</em>

<em>minHeap.insert(5)</em>

<em>minHeap.insert(3)</em>

<em>minHeap.insert(17)</em>

<em>minHeap.insert(10)</em>

<em>minHeap.insert(84)</em>

<em>minHeap.insert(19)</em>

<em>minHeap.insert(6)</em>

<em>minHeap.insert(22)</em>

<em>minHeap.insert(9)</em>

<em>minHeap.minHeap()</em>

<em>minHeap.Print()</em>

<em>print("The Min val is " + str(minHeap.remove()))</em>

See more about python at brainly.com/question/13437928

#SPJ1

You might be interested in
Which of the following was a policy created by Alexander Hamilton
sleet_krkn [62]

The policy that was created by Alexander Hamilton was the sale of national bank stock.

<h3>Who was Alexander Hamilton?</h3>

The man Alexander Hamilton is regarded as one of the founding fathers of the United States of America owing to the role that he played during and after the revolutionary war.

Now, the policy that was created by Alexander Hamilton was the sale of national bank stock.

Learn more about Alexander Hamilton:brainly.com/question/27837951

#SPJ1

Missing parts;

Which of the following was a policy created by Alexander Hamilton?

A. Sold of national bank stock

B. Ended certain diplomatic missions

C. Gave more federal offices to Democratic-Republican

D. Moving the capital to the District of Columbia

5 0
2 years ago
Hurricanes usually last much longer than other types of storms. Some can last a week or longer. As a hurricane makes landfall an
Reptile [31]

Answer:

There are six widely accepted conditions for hurricane development:

1. The first condition is that ocean waters must be above 26 degrees Celsius (79 degrees Fahrenheit). Below this threshold temperature, hurricanes will not form or will weaken rapidly once they move over water below this threshold. Ocean temperatures in the tropical East Pacific and the tropical Atlantic routinely surpass this threshold.

2. The second ingredient is distance from the equator. Without the spin of the earth and the resulting Corioles force, hurricanes would not form. Since the Corioles force is at a maximum at the poles and a minimum at the equator, hurricanes can not form within 5 degrees latitude of the equator. The Corioles force generates a counterclockwise spin to low pressure in the Northern Hemisphere and a clockwise spin to low pressure in the Southern Hemisphere.

3. The third ingredient is that of a saturated lapse rate gradient near the center of rotation of the storm. A saturated lapse rate insures latent heat will be released at a maximum rate. Hurricanes are warm core storms. The heat hurricanes generate is from the condensation of water vapor as it convectively rises around the eye wall. The lapse rate must be unstable around the eyewall to insure rising parcels of air will continue to rise and condense water vapor.

4. The fourth and one of the most important ingredients is that of a low vertical wind shear, especially in the upper level of the atmosphere. Wind shear is a change in wind speed with height. Strong upper level winds destroy the storms structure by displacing the warm temperatures above the eye and limiting the vertical accent of air parcels. Hurricanes will not form when the upper level winds are too strong.

5. The fifth ingredient is high relative humidity values from the surface to the mid levels of the atmosphere. Dry air in the mid levels of the atmosphere impedes hurricane development in two ways. First, dry air causes evaporation of liquid water. Since evaporation is a cooling process, it reduces the warm core structure of the hurricane and limits vertical development of convection. Second, dry air in the mid levels can create what is known as a trade wind inversion. This inversion is similar to sinking air in a high pressure system. The trade wind inversion produces a layer of warm temperatures and dryness in the mid levels of the atmosphere due to the sinking and adiabatic warming of the mid level air. This inhibits deep convection and produces a stable lapse rate.

6. The sixth ingredient is that of a tropical wave. Often hurricanes in the Atlantic begin as a thunderstorm complex that moves off the coast of Africa. It becomes what is known as a midtropospheric wave. If this wave encounters favorable conditions such as stated in the first five ingredients, it will amplify and evolve into a tropical storm or hurricane. Hurricanes in the East Pacific can develop by a midtropospheric wave or by what is known as a monsoonal trough.

Explanation:

3 0
3 years ago
Read 2 more answers
What's the answer the number
Mama L [17]

Answer:

Show the picture

Explanation:

3 0
3 years ago
A chemist will use a sample of 30 g of ethanol (ch3ch2oh) in an experiment. in one to two sentences, make and justify a claim ab
pav-90 [236]

The number of mole of ethanol, CH₃CH₂OH the chemist will use in the experiment is 0.65 mole

<h3>Description of mole </h3>

The mole of a substance is related to it's mass and molar mass according to the following equation:

Mole = mass / molar mass

<h3>How to determine the mole of CH₃CH₂OH</h3>

From the question given above, the following data were obtained:

  • Mass of CH₃CH₂OH = 30 g
  • Molar mass of CH₃CH₂OH = 12 + (1×3) + 12 + (1×2) + 16 + 1 = 46 g/mol
  • Mole of CH₃CH₂OH =?

Mole = mass / molar mass

Mole of CH₃CH₂OH = 30 / 46

Mole of CH₃CH₂OH = 0.65 mole

Learn more about mole:

brainly.com/question/13314627

7 0
2 years ago
Find the indicated z score. The graph depicts The standard normal distribution with mean 0 and Standard deviation 1. Shaded area
PtichkaEL [24]

Answer:

0.86

Explanation:

The standard normal probabilities table is used to find z score. The z-score measured by following:

Z = \frac{x-mean}{st. deviation}

The z value calculated will be looked at the table to find p-value. The value 0.0964 is found in the table we get 0.86

6 0
3 years ago
Other questions:
  • Yeah uh what are these called pls
    15·2 answers
  • JOIN MY ZOOM !!!!!1<br><br> id: 881 3769 1522<br> pass: 3t8A9A
    7·2 answers
  • Jon just downloaded several e-books for his e-reader, Jon most likely entered what type of agreement in order to download the bo
    12·2 answers
  • What is typically the best strategy to use when taking a test?
    13·2 answers
  • What is the correct action-reaction pair relationship describing newton's third law?.
    13·1 answer
  • In a​ state's pick 3 lottery​ game, you pay ​$ to select a sequence of three digits​ (from 0 to​ 9), such as. If you select the
    8·1 answer
  • A manufacturing company produces steel housings for electrical equipment. The main component part of the housing is a steel trou
    13·1 answer
  • Consider a fair of six-sided of die is rolled. Let x be a number of uppermost face. What is the variance of x?
    14·1 answer
  • Weegy. Which core capability is NOT common to all five Mission Areas
    10·1 answer
  • Please select the word from the list that best fits the definition the unintended and unrecognized consequence of an element of
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!