Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 1 ( Least - k Elements Datastructure ) We saw how min - heaps can efficiently allow us to query the least element in
Problem Leastk Elements Datastructure
We saw how minheaps can efficiently allow us to query the least element in a heap array We would like to modify minheaps
in this exercise to design a data structure to maintain the least elements for a given with
being the minheap datastructure.
Our design is to hold two arrays:
a a sorted array A of elements that forms our least elements; and
b a minheap with the remaining elements.
Our data structure will itself be a pair of arrays with the following property:
H must be a minheap
A must be sorted of size
Every element of A must be smaller than every element of
The key operations to implement in this assignment include:
insert a new element into the datastructure
delete an existing element from the datastructure.
We will first ask you to design the data structure and them implement it
A Design Insertion AlgorithmSuppose we wish to insert a new element with key into this data structure. Describe the pseudocode. Your pseudocode must
deal with two cases: when the inserted element would be one of the least elements ie it belongs to the array ; or
when the inserted element belongs to the heap How would you distinguish between the two cases?
You can assume that heap operations such as insert key and delete index are defined.
Assume that the heap is indexed as dots, with being unused.
Assume ie there are already more than elements in the data structure.
What is the complexity of the insertion operation in the worst case in terms of
Unfortunately, we cannot grade your answer. We hope you will use this to design your datastructure on paper before
attempting to code it up
YOUR ANSWER HERE
B Design Deletion Algorithm
Suppose we wish to delete an index from the topk array Design an algorithm to perform this deletion. Assume that the
heap is not empty, in which case you can assume that the deletion fails.
You can assume that heap operations such as insert key and delete index are defined.
Assume that the heap is indexed as dots, with being unused.
Assume ie there are already more than elements in the data structure.
What is the complexity of the insertion operation in the worst case in terms of
Unfortunately, we cannot grade your answer. We hope you will use this to design your datastructure on paper before
attempting to code it up
YOUR ANSWER HEREC Program your solution by completing the code below
Note that although your algorithm design above assume that your are inserting and deleting from cases where the data
structure implementation below must handle well. have provided implementations for that portion help you
out.
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