Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For each problem below, do not write pseudocode. Explain with words why your algorithm is correct and analyse its running time. Problem 1 (K th

For each problem below, do not write pseudocode. Explain with words why your algorithm is correct and analyse its running time.

Problem 1 (K th quantiles)

Let S = {s1, s2, . . . , sn} be a set of distinct real numbers. The K th quantiles of S is a subset of exactly K 1 numbers s 0 1 < s0 2 , . . . , s0 K1 such that the cardinality of

Sj = {s S | sj1 < s sj}

are the same. Design a divide and conquer algorithm to find the K th quantiles of a given set S of N numbers. You may assume that K is a power of 2 and that it is possible to partition S into K equal sets. Your input is the set S, and the value K. S is not sorted.

Examples:

For S = {2, 4, 1, 6, 0, 9}, K = 3 your design should output {1, 4}.

For S = {1, 2, 4, 1, 3, 0, 18, 2}, K = 2 your design should output {1} ((i.e.: the 2 th quantile is the median)).

Problem 2 (Election winner)

Certain country in the Caribbean Sea recently held an election to choose its president. Every vote cast was electronic, but unfortunately, a recent power surge caused a malfunction in the system just before votes were counted. The only information saved consists of the following facts:

All the N citizens casted their vote.

Exactly one candidate received more than N/2 votes.

We dont know how many candidates there were.

You are hired to help using your expertise in algorithms. But you can only work with the local resources. As a result, you have access to a function Agree(X, Y ) which returns True if X and Y cast a vote for the same candidate, and returns False otherwise. You are not told the identity of the candidate!

Design a Divide and Conquer algorithm that finds a single ballot that voted for the winning candidate. You may assume that every call of Agree(X, Y ) runs in constant time.

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

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions