Purchase Solution

Algorithm to find majority element

Not what you're looking for?

Ask Custom Question

Let A be an array of n elements. An element x is said to be a majority element in A if it occurs in A more than n/2 times. Assume that the only comparisons allowed between elements are tests of equality. Give an algorithm that uses no more than 2n comparisons to determine whether the array A contains a majority element and, if so, find it.

Purchase this Solution

Solution Summary

An Algorithm to find majority element is featured.

Solution Preview

Soln 1.

If there is a majority element, it must be the median. So use the average-time RANDOMIZED-SELECT algorithm (RANDOMIZED-SELECT finds any ith order statistic in linear time, and the median is simply the "middle" order statistic) to find a candidate majority ...

Purchase this Solution


Free BrainMass Quizzes
Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Basic Networking Questions

This quiz consists of some basic networking questions.

Javscript Basics

Quiz on basics of javascript programming language.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.