Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3 . Water Jug Problem ( Problem 8 - 4 : page 2 0 6 of CLRS 3 rd edition ) Suppose that you are

3. Water Jug Problem (Problem 8-4: page 206 of CLRS 3rd edition)
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.
It is your task to find a grouping of the jugs into pairs of red and blue jugs that hold the same volume of water. To do so, you may perform the following operation: pick a pair of jugs, one red, one blue, fill the red jug with water, and then pour the water into the blue jug. This operation will tell you if the two jugs hold the same amount of water, and if not, which one holds more water. Assume that such a comparison takes one unit of time. Your goal is to find an algorithm that solves this problem. Remember that you may not directly compare two red jugs or two blue jugs. a. Find an algorithm that uses \Theta (n2) comparisons (in worst case) to group the jugs into pairs.
b. Prove a lower bound of log3(!) for the worst case, and log3(!) for the average case number
of comparisons to be performed by any algorithm that solves this problem.
c. Find an algorithm for this problem that runs in (average case) time \Theta ( log ).(Hint: modify the algorithms Partition() and Quicksort().)

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

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions