Develop a heap data structure using a linked structure

Assignment Help Computer Engineering
Reference no: EM132667243

Question: You have been provided a Python file, heap.py, which constructs a heap structure with a list. Using that code as a guide:

Develop a heap data structure using a linked structure (Nodes and Pointers)

The heap must support add and remove from the heap

All operations most abide by the rules that govern a heap (see lecture slides for reference)

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

Develop a priority queue data structure that is backed by a heap (linked structure NOT A LIST)

Implement the normal methods that accompany a priority queue structure

Enqueue, dequeue, and peek by priority not position

Also length and whether or not the structure is empty (is_empty)

Perform the following operations to showcase your working structure

Enqueue the following items: 4, 7, 5, 11, 8, 6, 9

Dequeue 3 items by priority, they should be 4, 5, & 6.

related heap.py file code is below

class Heap:

def __init__(self):

self.heap = [0]

self.size = 0

def float(self, k):

while k // 2 > 0:

if self.heap[k] < self.heap[k//2]:

self.heap[k], self.heap[k//2] = self.heap[k//2], self.heap[k]

k //= 2

def insert(self, item):

self.heap.append(item)

self.size += 1

self.float(self.size)

def sink(self, k):

while k * 2 <= self.size:

mc = self.minchild(k)

if self.heap[k] > self.heap[mc]:

self.heap[k], self.heap[mc] = self.heap[mc], self.heap[k]

k = mc

def minchild(self, k):

if k * 2 + 1 > self.size:

return k * 2

elif self.heap[k*2] < self.heap[k*2+1]:

return k * 2

else:

return k * 2 + 1

def pop(self):

item = self.heap[1]

self.heap[1] = self.heap[self.size]

self.size -= 1

self.heap.pop()

self.sink(1)

return item

h = Heap()

for i in (4, 8, 7, 2, 9, 10, 5, 1, 3, 6):

h.insert(i)

print(h.heap)

for i in range(10):

n = h.pop()

print(n)

print(h.heap)

Reference no: EM132667243

Questions Cloud

Health education : Describe how you could use information technology to access, evaluate, and interpret this public health data in intervention program.
Understanding of cultural sensitivity : Using your knowledge understanding of cultural sensitivity, stakeholder affiliations, ethical considerations and the policies applicable to emergency situation
What is the purpose of the general ledger : What is the purpose of the General Ledger? To give investors a snapshot of the financial status of a company. / To itemize account balances for each customer
Summarize a current news item on an economic topic : Summarize a current news item on an economic topic using Word. Provide a copy of the article or a link to the article.
Develop a heap data structure using a linked structure : You have been provided a Python file, heap.py, which constructs a heap structure with a list. Using that code as a guide: Develop a heap data structure using.
Management of covid-19 : Has the Australian government adopted a system engineering approach in its management of COVID-19? Explain your answer
Address political risk signals that bring about terrorist : Address the political risk signals that bring about terrorist actions and What are the changes to the international organization''s marketing mix as a result
Safety critical recalls on cars being particularly newsworth : Safety critical recalls on cars being particularly newsworthy. Such recall of products due to safety concerns are costly to the organisation responsible
Main and alternative communication channels : Propose the main and alternative communication channels; Be specific and practical.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Express what makes one algorithm better than another

A non-technical friend has asked whether some algorithms are better than others. express what makes one algorithm better than another.

  Discuss specific activities that the given roles may perform

Select a data analytics of your choice and discuss how the following roles add value to this initiative: Business User, Project Sponsor, Project Manager.

  Find out where html injection is possible

Find out where HTML injection is possible within the service APIs. Write down an HTTP request that inserts an arbitrary image into the UI you constructed

  Count how many lines total are in the files

Write a script that will count how many lines total are in the files. Note that you do not have to process the data in the files in any way;

  How would the program react if the user input something

How would the program react if the user input something other than addition, subtraction, multiplication or division when prompted?

  What openings are on the front of the computer

What openings are on the front of the computer? What kinds of storage media can be used with this computer? Are there any openings for inserting new hard drives?

  Define the objects and their functions

The Launcher will fire a projectile at a target the Launcher is static, the projectile follows a linear path. The projectile has a known velocity.

  Create an inquiry which will be valid for one month

BCO6603 - Enterprise Resource Planning Systems - Workshop Reports - Create an inquiry which will be valid for one month from today

  Define the three levels of management hierarchy

Discuss how the three levels of management hierarchy: strategic, management, and operational relates to the mission of a business.

  Determine which version of the software should be used

Microsoft has released Windows Server 2008. As with Windows 2003, there are several versions of the server software. What are these versions, and what are the criteria that determine which version of the software should be used

  How will you get to the train depot or the air or seaport

How will you prepare for an uneventful encounter with the Transportation Security Administration or other Customs checks?

  Draw the flowchart for the program on the back of this paper

Write a program to prompt for inputting 5 numbers (a loop is needed) and find the maximum number.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd