Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6683649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:50:46+00:00 2026-05-26T04:50:46+00:00

A majority voting algorithm decides which element of a sequence is in the majority,

  • 0

A majority voting algorithm decides which element of a sequence is in the majority, provided there is such an element. Here is the most frequently-cited link that I found when I was trying to understand it.

http://www.cs.utexas.edu/~moore/best-ideas/mjrty/index.html

Besides, we have here a link that discusses the problem:

How to find the element of an array that is repeated at least N/2 times?

The problem is that the answer marked as correct is WRONG. Note that the question actually allows the input to have exactly N / 2 copies of a single element (not necessarily more than N / 2 as usually assumed in majority element detection algorithms).

I copied the code and tried it with inputs like [1, 2, 3, 2] and [1, 2, 3, 2, 6, 2] (producing results of 3 and 6). This actually applies as well to the algorithm cited above (which returns “No Majority Element!”). The problem is this: Whenever there’s an alternation between the majority element and anything else, the last element in the array that’s not the majority element is chosen. Please correct my wrong thoughts if any, and tell me about how to avoid it in the implementation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:50:46+00:00Added an answer on May 26, 2026 at 4:50 am

    The algorithm is correct: there is no majority element in your examples. An element is in the majority only if it is more than 50% of the values.

    If you wish to detect the case where the most frequent element has a count of N/2, then I don’t see any way to do it in one pass and O(1) space. My best attempt is:

    • Run the same algorithm as before, but remember the previous candidate as well.
    • If you switched at the last element, then the correct answer is either your current or your previous candidate.
    • Run another pass, counting the number of each, and compare them.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Majority voting combination rule in weka. There are 4 classifiers in
I have written the majority of my project in C++. However there are several
The majority of my questions I've asked here so far on StackOverflow have been
Especially for the majority of browsers that don't support it, is there anything aside
I'm working on an ASP.NET project in which the vast majority of the forms
Traditionally I've written the majority of my server maintenance scripts in bash like most
I see the majority of WPF Ribbon examples out there use some code like
There seems to be significant issues with Tomcat6/Comet/NIO ( example ). Are the majority
I have an existing database in which the majority of the tables have int
The overwhelming majority of people support my own view that there is no difference

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.