Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started