Answered step by step
Verified Expert Solution
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started