Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Suppose that the votes of npeople for different candidates (where there can be more than two candidates) for a particular office are the elements of a sequence. A person wins the election if this person receives a majority of the votes.

a) Devise a divide-and-conquer algorithm that determines whether a candidate received a majority and, if so, determine who this candidate is. [Hint: Assume that nis even and split the sequence of votes into two sequences, each with n/2elements. Note that a candidate could not have received a majority of votes without receiving a majority of votes in at least one of the two halves.]

b) Use the master theorem to give a big-Oestimate for the number of comparisons needed by the algorithm you devised in part (a).

Short Answer

Expert verified

a) Our recursive calculation will take a grouping of names and decide if one name happens as additional than half of the components of the grouping, and assuming this is the case, which name that is. On the off chance that the succession has only one component, at that point the one individual on the rundown is the champ.

b)O(nlogn)

Step by step solution

01

Master Theorem definition

In MASTER THEOREM, let fbe an increasing function that satisfies the recurrence relationf(n)=af(n/b)+cndwhenevern=8t, wherekis a positive integer,a1,bis an integer greater than1, andcanddare real numbers withcpositive anddnonnegative. Thenf(n)isO(nd)ifa<bdO(ndlogn)ifa=bdandO(nlogba)ifa>bd .

02

Apply Master Theorem

a) Our recursive calculation will take a grouping of names and decide if one name happens as additional than half of the components of the grouping, and assuming this is the case, which name that is.

On the off chance that the succession has only one component, at that point the one individual on the rundown is the champ.

For the recursive stride, isolate the rundown into two sections the first half and the second half-as similarly as could reasonably be expected.

As is brought up in the clue, nobody could have gotten a dominant part of the votes on this rundown without having a lion's share in one half or the other, since if a hopeful got not exactly or equivalent to a large portion of the votes in every half, then he got not exatctly or equivlent to a large portion of the votes taking all things together.

Apply the calculation recursively to every half to think of at most two names.

At that point go through the whole rundown the check the of names to choose which, assuming either, is the champ.

This requires at most 2nextra examinations for a rundown of length n.

b) We apply the ace hypothesis with a=2,b=2,c=2, and d=1. Sincea=bd , we realize that the number of correlations is O(ndlogn)=O(nlogn).

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Study anywhere. Anytime. Across all devices.

Sign-up for free