Question

In: Computer Science

There are n marble balls, one of which is made of a different material. You have...

There are n marble balls, one of which is made of a different material. You have access to a Comparator that can compare two inputs (of an arbitrary number of marble balls) and determine if the two inputs are the same or not. The problem is to find the single marble ball that is different from the others while minimizing the number of times you access the Comparator. Design an efficient algorithm based on prune-and-search to solve the problem. Derive the time complexity of your algorithm

Solutions

Expert Solution

Algorithm:

1. Divide n in three equal groups if n is divisible by 3.

1.1 If n gives remainder 1 on dividing by 3, compare this extra marble with any other marble and if they are same, remove this extra marble, if not take any other marble and compare this extra marble with this. If both are same, the marble that we used for previous comparison is the answer else the extra marble is the answer.

1.2 If n gives remainder 2 on dividing by 3, check if this two extra marbles are same by comparator. If they are same remove them else chose any one marble from the group and compare any of the extra marble. If they are same the other extra marble is the answer else the chosen extra marble to compare is the answer..

2. Take group 1 marbles and group 2 marbles and compare using a comparator. If both groups are same, consider third group. If both groups are not same, compare first and third group. If both are same then consider group 2 else consider group 1.

3. Recursively follow steps 1 and 2 till different marble is found.

Here, a group (or extra marble(s)) are prune and search is done on rest.

Time complexity can be given by:

T(n) = T(n/3) + 1

This is because in the worst case, we perform the recursive action on 1/3 of the marbles everytime and comparator takes a constant time.

Applying master theorem to get time complexity. a = 1, b = 3 and f(n) = 1

It satisfies If f(n) = Θ(n logb a ), then T(n) = Θ(n logb a log n) . So,

T(n) = Θ (n log3(1) log n) = Θ (log n)

Hence, time complexity of this algorithm is Θ(log n)


Related Solutions

We have a bag that contains n red balls and n blue balls. At each of...
We have a bag that contains n red balls and n blue balls. At each of 2n rounds we remove one of the balls from the bag randomly, and place it in one of available n bins. At each round, each one of the balls that remain in the bag is equally likely to be picked, as is each of the bins, independent of the results of previous rounds. Let Nk be the number of balls in the k-th bin...
: Consider two bags in which we have balls of three different colors. Details are in...
: Consider two bags in which we have balls of three different colors. Details are in the following table. Red Yellow Green Bag A 3 5 4 Bag B 2 4 x A bag is chosen at random and then a ball is chosen. A. If the probability of green ball is 21 5, find x. B. Find the probability of Bag A and it is given that the ball chosen is green.
You have a drawing happen Monday were you pull out one out of four marble out...
You have a drawing happen Monday were you pull out one out of four marble out of a bag with out replacement. You then have another drawing on tuesday were you pull out one of 3 marbles without replacement. You do this every day until Thursday were you only have 1 marble left in the bag. In the bag you have 1 red marble and 3 blue marbles. Summary: you have a drawing monday - thursday were you pull out...
You have a drawing happen Monday were you pull out one out of four marble out...
You have a drawing happen Monday were you pull out one out of four marble out of a bag with out replacement. You then have another drawing on tuesday were you pull out one of 3 marbles without replacement. You do this every day until Thursday were you only have 1 marble left in the bag. In the bag you have 1 red marble and 3 blue marbles. Summary: you have a drawing monday - thursday were you pull out...
You have an opaque urn with eight balls in it. Of these eight balls, there are...
You have an opaque urn with eight balls in it. Of these eight balls, there are two balls with a 4 on them, there are four balls with a 5 on them, there is one ball with a 6 on it, and one ball with a 10 on it. Let X denote the random variable that takes on the values X = 4,5,6,10. Find the: a. mean b. variance c. standard deviation d. skewness e. kurtosis f. median g. mode...
After you have completed the Unit 1 material and have considered the many different definitions of...
After you have completed the Unit 1 material and have considered the many different definitions of Pop Culture posed within the unit, consider the differences between high culture and popular culture. Answer the following questions: When someone is said to be “cultured”, does this refer to high culture, popular culture, or both? How would you define, in your own words, “high culture” and “popular culture”? What characteristics of high culture are also present in popular culture? What makes something “high”...
A bag contains n blue and m red marbles. You randomly pick a marble from the...
A bag contains n blue and m red marbles. You randomly pick a marble from the bag, write down its color, and then put the marble back in the bag. This process is repeated until you pick either two consecutive blue or two consecutive red marbles. Given that the process stopped because you picked two consecutive blue marbles, what is the probability that the first marble you picked was blue? Please note that the question asks you to derive the...
Exercise 1.2. You have a pile of balls consisting of 4 red balls, 5 blue balls,...
Exercise 1.2. You have a pile of balls consisting of 4 red balls, 5 blue balls, 3 green balls, and 8 orange balls. Suppose you randomly choose a ball, one at a time, from this pile until you have pulled out a collection 4 balls. Assume repeats are allowed in all parts of this problem. 1. In how many ways could you make a selection that has exactly one green ball? 2. In how many ways could you make a...
sphere with radius "a" which is made of paramagnetic material (with permeability μ) is placed in...
sphere with radius "a" which is made of paramagnetic material (with permeability μ) is placed in uniform magnetic field B. Find: a) magnetic scalar potential inside and outside of  sphere. b) magnetization density c) surface curent density on sphere
Suppose you have a bar with two balls (masses) attached to it. These balls can be...
Suppose you have a bar with two balls (masses) attached to it. These balls can be positioned and secured at any location along the length of the bar. If the axis of rotation is through the middle of the bar (and perpendicular to its long axis), which of the following makes for the smallest moment of inertia? Suppose you have a bar with two balls (masses) attached to it. These balls can be positioned and secured at any location along...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT