Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

8-4 Water jugs Suppose that you are given n red and n blue water jugs, all of different shapes and sizes. All red jugs hold

image text in transcribed

8-4 Water jugs Suppose that you are given n red and n blue water jugs, all of different shapes and sizes. All red jugs hold different amounts of water, as do the blue ones. Moreover for every red jug, there is a blue jug that holds the same amount of water, and vice versa. Problems for Chapter 8 207 Your task is to find a grouping of the jugs into pairs of red and blue jugs that hold the same amount of water. To do so, you may perform the following operation: pick a pair of jugs in which one is red and one is blue, fill the red jug with water, and then pour the water into the blue jug. This operation will tell you whether the red or the blue jug can hold more water, or that they have the same volume. Assume that such a comparison takes one time unit. Your goal is to find an algorithm that makes a minimum number of comparisons to determine the grouping. Remember that you may not directly compare two red jugs or two blue jugs a. Describe a deterministic algorithm that uses (n2) comparisons to group the jugs into pairs. b. Prove a lower bound of (n lg n) for the number of comparisons that an algo- rithm solving this problem must make. c. Give a randomized algorithm whose expected number of comparisons is O(n lg), and prove that this bound is correct. What is the worst-case num- ber of comparisons for your algorithm

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions