Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the problem of nding the largest and second largest elements from a set of n elements. c) Show how you can nd both these

Consider the problem of nding the largest and second largest elements from a set of n elements.

c) Show how you can nd both these elements in n + logn2 comparisons in the worst case (assume n is a power of 2). (Hint: See hint in problem 2.7.)

Here is 2.7:

Show that the celebrity problem can be solved by using 3n logn 3 questions (assume that n is a power of 2). (Hint: Group people into pairs similar to a knockout tournament, e.g., Wimbledon tennis tournament.)

Here is the answer to this 2.7:

As in the hint, rst group the n people in pairs of two i.e., we will have n/2 pairs. This will be the rst round. For each pair, say (x,y), ask one question if x knows y. This question will eliminate one person i.e., he/she cant be a celebrity. The winner from this pair will be one who is not eliminated. All the winners from this round there will be n/2 of them will advance to the next round. In the next round, again repeat the process group into n/4 pairs and question n/4 will advance to the next round. This is exactly how a knockout tournament is organized. Finally, there will be one champion (the winner in the nal round) after logn rounds; because each round eliminates half the number of persons. How many questions were asked before the champion is found ? This can 2 be computed by summing up the questions asked in each round: n/2 + n/4 + n/8 ++ 1 = n(1/2 + 1/22 + 1/23 ++ 1/2logn) The series inside the parantheses is a geometric sum: Hence that can be evaluated as 1/2 + 1/22 + 1/23 ++ 1/2logn = (1/2)(11/2log n) 1/2 = 11/n. Hence, n/2+n/4+n/8++1 = n(1/2+1/22+1/23++1/2logn) = n(11/n) = n1. If there is a celebrity he /she has to be the champion. This has to be checked by asking whether all others know the champion and whether the champion knows anybody else. This takes no more than 2n2 questions. However, note that we dont have to ask the same question (in one way) with the person who lost to the winner. This saves logn questions. Hence, the total number of questions is n1 + 2n2logn = 3nlogn3.

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

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions

Question

5. List the forces that shape a groups decisions

Answered: 1 week ago

Question

4. Identify how culture affects appropriate leadership behavior

Answered: 1 week ago