Home /
Expert Answers /
Computer Science /
15-points-consider-the-following-sorting-algorithm-that-takes-a-list-of-integers-as-an-input-and-pa379
(Solved): (15 points) Consider the following sorting algorithm that takes a list of integers as an input and ...
(15 points) Consider the following sorting algorithm that takes a list of integers as an input and outputs a sorted list of those elements. (note, the MERGE subroutine is an algorithm we will talk about on Tuesday. You can find it in the slides. All you need to know about MERGE is that it takes two sorted lists of integers and returns a sorted list of all the integers combined. If the size of the lists are j and k, then the runtime of MERGE is O(k+j).) QueueSort (a1,…,an) 1. Initialize a queue Q of lists so that each element of the input is in a list all by itself. 2. Q=([a1],[a2],…,[an]) 3. while ∣Q∣⩾2 : 4. dequeue the first two lists from Q and MERGE the two lists together. 5. enqueue the result into Q.
It appears that you're describing a variant of a merge sort algorithm that uses a queue data structure. Here's a brief overview of the algorithm:In the first step, each element in the input array is placed in a list by itself and all these lists are placed in a queue. The queue now has n lists, each containing one element.