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

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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