Confused by proof of correctness of Majority

I have been studying a streaming algorithm to determine if there is a majority element in a stream. But am confused by a proof for it.

The algorithm works as follows. You keep one counter $ c$ and a store for one item called $ a^*$ . When a new item arrives, first you check if $ c == 0$ . If so you set $ c=1$ and $ a^*$ stores the arriving item. Otherwise, if $ c>0$ and the arriving item is the same as $ a^*$ you increment $ c$ or decrement $ c$ if not.

If there is a majority element then it will be stored in $ a^*$ at the end.

In the notes from there is a proof of this fact (called simpler proof).

enter image description here

I can see that if there is a majority item then $ c’$ will be positive at the end of the stream. But:

  • How do we know that $ a^*$ will hold the majority item at the end?
  • Does $ c’$ being positive imply that $ c$ will be positive too?

Boyer-Moore majority vote algorithm second iteration

There’s a problem in one of my textbooks that goes as follows.

You are given the results of a presidential election. Each ballot is presented one by one, and on each ballot the name of a candindate is written(Let’s assume candidates name’s are represented by numbers). Before announcement of the result, the total number of candidates and the number of people who voted, are unknown.All valid ballots are presented on by one as input, and this process repeats 2 times total. We only have 2 simple varibles we can use for the whole process. You have to design an algorithm which can decide if there is a candidate that has gathered the majority of the votes(meaning more than 50%) of the people who voted, or not. If such a candidate exists, print the candidates name otherwise print "blah blah blah"

Now what first got into my mind, is to use the Boyer-Moore majority algorithm and keep updating the majority and the counter variables as soon as the next result comes in. In case i haven’t made that clear, the results aren’t stored in an array or anywhere else. You get informed of one ballot, then you calculate(and this goes on until all the ballots have been used, meaning i don’t have access to any previous information). Whether this information is stored in array or not, i know i can still run the first iteration of this algorithm to get a "possible" majority result, since the algorithm always produces one. My problem lies in the second iteration.I see the results one more time one by one. How am i supposed to verify if my original result is indeed the majority or not? Is there any other way i can get around it with only 2 variables?

Consensus without majority

I am new to distributed computing but after a quick look at Paxos and Raft it is clear that for those algorithms to work majority of the servers should be up and running.

So is it fundamental to this type of consensus problems (non Byzantine, fail stop) to have half of the servers running all the time? Is it proven or does there exist an algorithm which works for fewer running machines?

The majority of guys are facing this hassle in recent times

The majority of guys are facing this hassle in recent times. These issues include the erectile dysfunctioning, reduced libido, and weak erection. This complement is helpful in boosting your ѕeхual electricity and stamina. Alpha Genix XL Reviews Most of these supplements utilize chemical compounds in their production. These chemical substances offer you with brief outcomes but additionally reason many types…

The majority of guys are facing this hassle in recent times

Majority attack against a new blockchain with few miners?

My friend wants to create a new blockchain to verify a type of transaction (details unimportant). His computer would probably be the only one doing mining / verifying the transactions, at least for the first few weeks. My understanding is that someone could come in and change months worth of blocks pretty easily if they brought enough computing power.

Am I correct in this understanding, and are there ways to prevent this from happening when creating a new blockchain with few miners?

Explaination for Variation of Boyer-Moore Majority voting algorithm

Boyer-Moore’s majority vote algorithms can be used to determine the majority element in a linear time and constant space.

The intuition behind finding the majority element is understandable as it has to be greater than the count of other elements in the input sequence if a majority element exists.

However, there is a variation of this algorithm to find the elements occurring more than [n / 3] where n is the length of the sequence.

The algorithm goes like this.

  • Start with two empty candidate slots and two counters set to 0.
  • for each item:
    • if it is equal to either candidate, increment the corresponding count
    • else if there is an empty slot (i.e. a slot with count 0), put it in that slot and set the count to 1
    • else reduce both counters by 1

I can understand there will be at most (n /3) - 1 entries so we keep two containers and their counts.

But I’m not sure why the last reduce both by 1 is pivotal to this algorithm. I would be very helpful if you explain the intuition behind this.

Code of the above algorithm

vector<int> majorityElement(vector<int>& nums) {     int cnt1=0, cnt2=0;     int a,b;     for(int n: nums){         if (cnt1 == 0 || n == a){             cnt1++;             a = n;         }         else if (cnt2 == 0 || n==b){             cnt2++;             b = n;         }         else{ // This part             cnt1--;             cnt2--;         }     }     cnt1=cnt2=0;     for(int n: nums){         if (n==a) cnt1++;         else if (n==b) cnt2++;     }     vector<int> result;     if (cnt1 > nums.size()/3) result.push_back(a);     if (cnt2 > nums.size()/3) result.push_back(b);     return result; } 

Algorithm and code source