Coder Social home page Coder Social logo

moore-voting's Introduction

Moore-Voting

Q- Array is given to you. You have to find that element that occurs more then size/2 times.

example --> 3 2 1 1 1 3 3 3 3
Answer - 3
Here size of array is 9 and 9/2 is 4. Here 3 occurs more than 4 times.

Working

  • As the algorithm include a word VOTING in it's name so it is simply related to voting.
  • In this Algorithm the first element has a count(vote) = 1.
  • If There are similar people (elements) with similar agenda than the counter(vote) will increment by 1.
  • If not then counter(vote) will be decremented by 1.
  • If counter(vote) becomes 0 then
    • counter(vote) value becomes 1.
    • now comparision will be started from the point where the counter(vote) value becomes 0.
    • [To understand this point read the program and solve it on paper.]

COMPLEXITY

  • Moore Voting - n
  • Brute Force - n^2.

moore-voting's People

Contributors

zatinmohan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.