Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 2: Suppose we have implemented a standard (FIFO) queue class using a circular array, as illustrated below. To enqueue (insert) a new item means
Question 2: Suppose we have implemented a standard (FIFO) queue class using a circular array, as illustrated below. To enqueue (insert) a new item means to push it to the back of the queue array. To dequeue (remove and return) the next item means to pop the front of the queue array and return that front value. Now we want to modify the class to make it a priority queue, where the order in which items are dequeued is determined by their priority (highest value first) 118 24 173 size-1 front back Compare the two approaches below in term of the worst time complexity of enqueue and dequeue operations. Justify your results. Which is better? (4 marks) i) Enqueue remains the same. Dequeue now searches for the item of highest priority (which will be returned at the end) and replaces it by the last item ii) Items are sorted in descending order of values, so the highest priority is always at the front. Dequeue remains the same. Enqueue searches for the appropriate position (so that items remain sorted) and inserts the new item there
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