Question: Please provide full answers, no need for written code just PSEUDOCODE or plain english. Will give thumbs up if satisfactory answer Given n cards on

Please provide full answers, no need for written code just PSEUDOCODE orPlease provide full answers, no need for written code just PSEUDOCODE or plain english. Will give thumbs up if satisfactory answer

Given n cards on the table, each with an integer on it, devise an algorithm to sort them using only one kind of operation flip(i, j) on the cards. The operation flips the order from i-th card all through j-th card for 1 > (a) Assume that each call of flip(i, j) costs $1. Now suppose all numbers on the cards are either 1 or 2, describe an algorithm which costs O(n) amount of money. Justify your answer. (b) Assume that the operation of flip (i, j) takes linear time (i.e., Olj-i) of time). Now suppose the numbers on the cards can take arbitrary integer value, describe an algorithm which takes (expected) O(nlog?n) time. Justify your answer. (Hint: even if you failed to solve part (a), you can take it as a black-box algorithm to use in this part.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!