Answered! A priority queue stores a collection of entries of the form (k,v) where k is a key and v a value. i) What are the two fundamental methods of the priority queue ADT?…

A priority queue stores a collection of entries of the form (k,v) where k is a key and v a value.

i) What are the two fundamental methods of the priority queue ADT?
[5 marks]

ii) Suppose that keys are English words ordered alphabetically (i.e. in dictionary order). Is this ordering suitable for determining the priority of entries in a priority queue? Give reasons for your answer. [10 marks]

Expert Answer

 a) The Priority Queue supports these fundamental methods:

i) insertItem(k, e): Inserts element e by comparing the key k as the priority

ii) removeMinElement(): Remove the element with minimum/maximum priority from the queue and return that

b) The String keys can be suitable if we are aiming for the strings to be kept in sorted order. In that case, we pass the key as the string itself, and priority queue will sort the list as per value of Strings in alphabetic order(Default sorting). So String “ABCD” will come before “BCD”, as A comes before B in alphabet.

While, if we want the strings to be fetched in order of most used strings, we may want to pass a differnt key value along with string element which denotes the priority of the string. If a particular string is used very much, its priority will be high, while a low used string will be less priority.

Still stressed from student homework?
Get quality assistance from academic writers!