retagged by
1,558 views
5 5 votes

Consider a new sorting algorithm similar to the BubbleSort algorithm, called RumbleSort. Given an array as input, RumbleSort attempts to sort the array and produces a sorted array as output. Here’s the pseudo-code for RumbleSort.

 

With regards to the above RumbleSort algorithm, consider the following statements.

S1:  RumbleSort works correctly for all inputs.

S2:  The time complexity of determining if the RumbleSort algorithm will work correctly for a given input is $\mathcal Ο(n^2)$

 

Which of the above statements is/are true?

1 Answer

Best answer
3 3 votes

S1 is False, S2 is True

Notice that:

  1. Any element initially at an even index, will always remain at an even index. Similarly, any element initally at an odd index will remain at an odd index.
  2. An even indexed element is not compared with any element at an odd numbered index in one iteration of rumblesort.
  3. Using A and B we have a stronger claim that any element initially at an even index can "never" be compared to an element initially at any odd index.

 

S1: C is sufficient to tells us that Rumble sort is incorrect, that is, it doesn't work correctly for all inputs.

example input where Rumblesort fails: [2, 1, 3]

 

S2: To verify whether Rumblesort will work correctly for a given input I, we can sort all even indexed elements of I and all odd elements of I separately. Let these sorted lists be $\rm{EVEN}$ and $\rm{ODD}$. Then, Rumblesort fails if $\exists i: \exists j < i: \rm{ODD}[j] > \rm{EVEN}[i]$, or if $\exists j: \exists i < j: \rm{EVEN}[i] > \rm{ODD}[j]$

This verification takes $\Theta (n \log n)$ time for the two sorts, and $\mathcal O(n^2)$ time for each of those checks, totaling $\mathcal O (n^2)$ time.

Note: The checks can be done in $\mathcal O(n \log n)$ by using binary search, so the most efficient checking algorithm can do it in $\Theta (n \log n)$ time.

selected by
Position:
Show:

Related questions

1 1 vote
1 answers 1 answer
863
863 views
1 1 vote
1 1 answer
1.7k
1.7k views
eyeamgj asked Jan 29, 2018
1,701 views
Given two unsorted singly-linked lists each with n distinct elements. There exists an efficient intersection algorithm, that computes and returns a new list with common e...
3 3 votes
1 answers 1 answer
1.2k
1.2k views
mohitbawankar asked Nov 2, 2017
1,184 views
Consider two arrays A[] and B[],if arrays A is in increasing order and array B is in decreasing order is input to join a algorithm. the output is an array C[1......2n] wh...
8 8 votes
6 6 answers
3.9k
3.9k views
Arjun asked Feb 27, 2025
3,856 views
Suppose that insertion sort is applied to the array $[1,3,5,7,9,11, x, 15,13]$ and it takes exactly two swaps to sort the array. Select all possible values of $x$.$10$$12...