Three animals stand next to each other by size, as follows: An Elephant, followed by a Hippo, followed by a Panda bear, [E, H, P]. Your goal is to re-arrange them so that they are sorted in the opposite size-based order. You are only allowed to switch positions of neighboring animals. Do not use Insertion or Merge sort. Try to use your own strategy to re-arrange the array. (a) How many operations do you need to reverse the order of the three animals? (b) Let’s generalize the above. You have an array of n elements whose ordering you want to revers. Write pseudo code to do this. (c) How many operations do you need to reverse the ordering of an array of n? Your answer should be a function of n.
Subj:- Design & Anal
Please compelete all the three questions since it has to be answereda once. Thank you in advance.
Three animals stand next to each other by size, as follows: An Elephant, followed by a Hippo, followed by a Panda bear, [E, H, P]. Your goal is to re-arrange them so that they are sorted in the opposite size-based order. You are only allowed to switch positions of neighboring animals. Do not use Insertion or Merge sort. Try to use your own strategy to re-arrange the array.
(a) How many operations do you need to reverse the order of the three animals?
(b) Let’s generalize the above. You have an array of n elements whose ordering you want to revers. Write pseudo code to do this.
(c) How many operations do you need to reverse the ordering of an array of n? Your answer should be a function of n.

Trending now
This is a popular solution!
Step by step
Solved in 2 steps









