Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In PQ, insert(ky) returns the reference to newly inserted entry. Let's say we want to change the key of the entry afterwards. That would be

image text in transcribed

In PQ, insert(ky) returns the reference to newly inserted entry. Let's say we want to change the key of the entry afterwards. That would be a new ADT called Adaptable Priority Queue. How can we implement this key change for an entry in O(logn) in array-based PQ implementation? For example, here is a heap (Note? represents the value associated with the key) 1,7 2.? 3? 7,2 5,2 6,7 Internal data structure is array. It will be 0 1 2 3 4 5 (1,7) (2,7) (3,7) (7.2) (5,?) (6,?) entry reference return by early insert Insert(k,v) returns the reference to newly inserted entry. Say want to change the key in the entry (2,?) to be (20,7). Obviously, the heap order needs to be checked and fixed by calling upheap or downheap. Recall upheap(index) and downheap(index) take index as argument. The question becomes how we can find out the index for the entry in O(logn) time? Hint: add more information to the entry. If we add more information to the entry, will that impact the downheap and upheap algorithm and in what way? In PQ, insert(ky) returns the reference to newly inserted entry. Let's say we want to change the key of the entry afterwards. That would be a new ADT called Adaptable Priority Queue. How can we implement this key change for an entry in O(logn) in array-based PQ implementation? For example, here is a heap (Note? represents the value associated with the key) 1,7 2.? 3? 7,2 5,2 6,7 Internal data structure is array. It will be 0 1 2 3 4 5 (1,7) (2,7) (3,7) (7.2) (5,?) (6,?) entry reference return by early insert Insert(k,v) returns the reference to newly inserted entry. Say want to change the key in the entry (2,?) to be (20,7). Obviously, the heap order needs to be checked and fixed by calling upheap or downheap. Recall upheap(index) and downheap(index) take index as argument. The question becomes how we can find out the index for the entry in O(logn) time? Hint: add more information to the entry. If we add more information to the entry, will that impact the downheap and upheap algorithm and in what way

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions

Question

2. Why has the conflict escalated?

Answered: 1 week ago

Question

1. How will you, as city manager, handle these requests?

Answered: 1 week ago