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]
1 year 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]1 year 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
Two lines that have different slopes i tersect at ecaxtly one point
dusya [7]

Answer: If a linear system has no solution, the two lines are parallel. If it has one solution, the lines will intersect at exactly one point because they have different slopes.

4 0
2 years ago
which event motivated the opposing parties of china to fight together? in 1931, the invasion of manchuria persuaded the chinese
madam [21]

In 1931, the Japan invasion of Manchuria persuaded the Chinese Communist Party and the warlords to unite with the Kuomintang.

<h3>What was the effect of Communism?</h3>

In the year 1931, Japan invaded Manchuria immediately after the Mukeden incident and then installed Manchuko state.

This invasion by the Japanese army on Manchuria was because they felt that a Chinese lieutenant destroyed the South Manchuria Railway by a detonating dynamite.

The imperial Japanese army responded with a full invasion which caused a truce between the Kuomintang and communist party of china,  they cooperated against the Japan.

Read more baout Communism at; brainly.com/question/11981920

#SPJ1

3 0
2 years ago
Read 2 more answers
While trees are not the largest level in the pyramid of numbers, they are still the base for both the pyramids of biomass and py
eimsori [14]

Answer:

TRUE

Explanation:

The trees are the primary producers that produces the food on which the consumers are dependent. This forms the base of the ecological pyramid for both energy as well as biomass.

In any biological condition, it can be observed that during its ecological succession from one trophic level to the next, almost 90% of its total energy is lost, and only 10% of its energy is transferred to the successive trophic level.

Similarly, biomass is also comparatively higher in producers like plants and trees than in any other trophic levels.

Thus, the given statement is True.

7 0
3 years ago
Read 2 more answers
What happens if you do really well on the SAT exam?
ANEK [815]
The maximum score<span> on the </span>SAT<span> is 1600. Out of the 1.7 million students who take the test every year, only about 300 get the </span>highest<span> possible </span>SAT score<span>. This elusive </span>perfect score<span> catapults you to the top of high school academic achievement and can be a big boost to your college applications.</span>
7 0
3 years ago
Read 2 more answers
when iron rusts and forms iron oxide, the iron oxide has more mass than the iron. which statement correctly explains this observ
GarryVolchara [31]

The reason why iron oxide has more mass than the iron is because Iron oxide has oxygen atoms, and pure iron does not.

When iron rusts and forms iron oxide, the iron oxide has more mass than the iron. Which statement correctly explains this

observation?

(A)Iron oxide has oxygen atoms, and pure iron does not.

(B)The oxygen atoms in iron oxide have more mass than the iron atoms in pure iron.

(C)The iron atoms in iron oxide have more mass than pure iron.

(D)There are more iron atoms in iron oxide than in pure iron.

When a chemical reaction takes place, other atoms are combined with pure elements to form compounds. This addition of another atom (oxygen) after reaction makes iron oxide formed heavier than pure iron.

Iron oxide is a chemical substance formed when pure iron rusts. The formation of iron oxide is a chemical reaction.

Hence, the correct answer to the question is;  the iron is heavier  because Iron oxide has oxygen atoms, and pure iron does not.

Learn more: brainly.com/question/6284546

8 0
2 years ago
Other questions:
  • What is the measure of ∠M? 81° 65° 53° 98° answer plz
    11·2 answers
  • Which of the following sections on the SAT presents the questions in order of difficulty, from easiest to hardest, within each q
    13·1 answer
  • Write a short note on Doraemon.​
    14·1 answer
  • FREEEEEEEEEEEEEEEEE POINTTTTTSsssssssssssssssssssssssssssssss
    7·2 answers
  • Witch planet has the most largest an most complex ring
    6·1 answer
  • What did the pottery look like during the archaic period? (site 1)
    7·1 answer
  • Quis:
    11·1 answer
  • Keisha is making a diagram of a simple machine in the body.
    12·1 answer
  • Another name for interpersonal communication is : *.
    6·1 answer
  • A programmer intended to compute (a AND b) OR c, and wrote the following code, which sometimes yields incorrect output. Why
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!