boris86
April 25th, 2010, 03:48 PM
a.Given n integers, describe an algorithm (in pseudo-code or in clear
words), that performs a partial sort: the algorithm should divide the input
into groups of 5, such that the numbers within each group are not
necessarily sorted, but the groups are sorted between them (that is, all of
the numbers in a group are larger than the numbers in the previous group,
and smaller than the numbers in the next group). Formally, let 1 /5 ,..., n S S
be the resulting sets of elements, each consisting of 5 elements, then:
For example:
Input: 1, 22, 5, 23, 7, 12, 4, 16, 8, 24, 15, 2, 11, 3, 9
Output: 3, 4, 2, 5, 1, 9, 7, 12, 8, 11, 15, 22, 23, 24, 16
What is the complexity of your algorithm?
b. Assuming that we have no prior knowledge on the input numbers, is it
possible to solve the above problem in O(n·log log n)? Describe an
algorithm, or prove that one does not exist.
thanks for the help
words), that performs a partial sort: the algorithm should divide the input
into groups of 5, such that the numbers within each group are not
necessarily sorted, but the groups are sorted between them (that is, all of
the numbers in a group are larger than the numbers in the previous group,
and smaller than the numbers in the next group). Formally, let 1 /5 ,..., n S S
be the resulting sets of elements, each consisting of 5 elements, then:
For example:
Input: 1, 22, 5, 23, 7, 12, 4, 16, 8, 24, 15, 2, 11, 3, 9
Output: 3, 4, 2, 5, 1, 9, 7, 12, 8, 11, 15, 22, 23, 24, 16
What is the complexity of your algorithm?
b. Assuming that we have no prior knowledge on the input numbers, is it
possible to solve the above problem in O(n·log log n)? Describe an
algorithm, or prove that one does not exist.
thanks for the help