Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 3 We have p houseplants in planters of various sizes $1, 52,..., Sp. The plants are getting too big and each plant has
Problem 3 We have p houseplants in planters of various sizes $1, 52,..., Sp. The plants are getting too big and each plant has to be replanted to a larger planter than the one it currently has. The good news is that we have r extra planters of sizes t, t,..., tr. Is it possible to replant the plants, one at a time, always putting the plant to a larger currently empty planter? Let n = p+r. Design an O(n log n) algorithm which decides whether such replanting is possible. 2 For example, for p = 4 and r = 2 and planters $,..., 84 = 1, 4, 3, 2 and t, t2 = 5,1 we can first move the plant in the planter of size 4 to the empty planter of size 5, then move the plant in the planter of size 3 to the now-empty planter of size 4, then move the plant in the planter of size 2 to the now-empty planter of size 3, and finally move the plant in the planter of size 1 to the now-empty planter of size 2. (We will be left with two empty planters of size 1 each.) Thus, for the input, the answer is YES. On the other hand, for input p = 3 and r = 1 and planters 81, 82, 83 = 2, 2, 2 and t = 3 the answer is NO.
Step by Step Solution
★★★★★
3.36 Rating (159 Votes )
There are 3 Steps involved in it
Step: 1
Given p plants and r extra planters the problem is equivalent to finding the smallest size of plante...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