write a function swap(x, y) which does: reverse(y) reverse(1) reverse(y) so 1 8 3 4 5, swap (2, 3) // swap 3 and 4 reverse(3) gives: 4 3 8 1 5 reverse(2) : 3 4 8 1 5 reverse(3): 1 8 3 4 5 //thus we have swapped 3, 4 using the reverse(x) function.
Use any sorting algorithm and you'll need 3k * n(log n) assuming reverse(x) takes O(k) I guess there is a way to optimize the number of reverse(x) calls On Sep 16, 8:41 am, Srinivas <lavudyasrinivas0...@gmail.com> wrote: > You have been given a function rev(x) which works as follows: > It reverses a[0] to a[x] elements of a. > e.g. Given array is > a : 1 8 3 4 5 > rev(3) will convert the array to > a : 4 3 8 1 5 > Use this function only (and comparison, of course) to sort given array > 'a'. The only criterion is > that the number of times this function is called should be minimum. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.