Have you ever been in a situation where you had to vote for class president, and you have to choose between your two best friends. Your best friends gets 15 votes each, including the votes from other class members. However, a bully gets 16 votes and becomes class president. You consider and believed that if only one of your best friends were running, then that one would have gotten a sum of 30 votes (15+15) and win by a landslide. This is a problem with the algorithm used in voting.

What doesBinarySearch andBinarySort have in common. They are all based ontwovalues being compared.

Binary Search

If you have a list of 1000 words in alphabetic order, and within it, there is the word "house". You are tasked to search for the exact index of that word. You could use a binary search. The algorithm compares at the middle of the list. Eg the middle has "dog" thus "house" must be in the second half of the list. The second half of the list has 500 words and that is now the new sub list the algo is interested in. Then the algo compares the middle of that sub list and finds "roof" so it knows which half of the sub list to look at. A smaller list of 250 words.

The algo will logically divide the list of interest intotwosub list, and so on until it ends when it finds the word. As you can see it does not look at all the words, just a few words and the sub list of interest get exponentially smaller.

Rough Index is also a powerful algo. It is not memory feasible to have a perfect index stored for every word given the size of the initial list. (You have to strike a balance between the amount of rough indices and the list size) However you can have a rough index for where B words start, and C words, D words and so on. This gives a total of 26 rough indices. (Rough indices of AA, AB, AC, AD words would give 26x26 index size so a optimal balance is suggested or else you can have an indices size greater than the initial list size).

The binary search can be combined with rough index to provide an even more powerful and quicker search because only the sub list from the H index to the I index would be of interest to the binary search input.

Binary Sort

Please see this wonderful video. The idea is to sort a list of numbers from smallest to largest. The list is logically broken down to element components. A sub list of element one. Also that element 1 sub list is also a sorted list.Twosmaller sorted list are then combined to form a bigger sorted list. This is relatively easy to do. In your head, think of the steps to combine in order 4,9,11,20 and 2,6,31. It is basically the reverse of binary search. You start with 1000 numbers which means 1000 small sorted list. The algo runs and you have 500 two element sorted lists, then 250 four element sorted list and so on, until 1 1000 element sorted list.

P vs. NP - The Biggest Unsolved Problem in Computer Science - by Up and Atom

(video starts at 8:30 with sorting algos but an interesting watch from beginning)

For the problem at the top and the video below, I proposeRelative Choice Votingand it uses the input ofRank Choice Voting. Rel CV is my upgrade to Rank CV. I believe it to be better in selecting what people really want. I will try to run an app and demonstrate some examples and put in any binary search or sort optimizations if encountered.

Rank Choice Voting

More vids:

What Is Rank Choice Voting? | NBC News Now

Can Ranked-Choice Voting Change U.S. Elections?

Relative Choice Voting

Let's say that there are 6 candidates (1-6). Voters indicate a prioritized list. Eg

1,4,2

6,5,1,4,3,2

4

3,6,2,1

5,4, , ,3

1,1,1,1,1,1 (it does not matter as it is the same as just 1)

5,4,6

This is all the voter has to do.(It is even simpler if there are 4 candidates) The algorithm does all the work.

One vote, one increment..Foundation

If you don't have a vote then you don't have a chance..Foundation

The algo compares all 6 candidates, but two at a time in all combinations, and registers the relative votes.

The algo comparestwocandidates. Let's say, candidates 1 and 2. The algo uses the priority vote lists.

In the above when a "1" is present (first occurrence) and there is no "2" in front it, then a vote is counted towards candidate 1. Also when there is a 2 present and no 1 is present before it, then a vote is counted for candidate 2. Then the relative weight of "1" to "2" is the simple difference of their votes.

Thus {1,4,2} {6,5,1,4,3,2} {1,1,1,1,1,1} count as three votes for candidate 1

And {3,6,2,1} counts as a vote for candidate 2. Thus candidate 1 is more commonly desired relative to candidate 2

(3 votes take away 1 vote gives a relative weight of +2 for candidate "1" vs "2")

The algo then goes to the next possible selection, "1" and "3" using the same criteria above.

{1,4,2} {6,5,1,4,3,2} {1,1,1,1,1,1} counts as three votes for candidate 1

and

{3,6,2,1} {5,4, , ,3} counts as two votes for candidate 3

(3 votes take away 2 votes gives a relative weight of +1 for candidate "1" vs "3")

The algo then goes to the next possible selection, "1" and "4" using the same criteria above.

(4 votes take away 3 votes gives a relative weight of +1 for candidate "1" vs "4")

After each selection of two candidates are compared to give relative weights, then each candidate's total weight is the sum from all selections that include that candidate.

For example,

the total relative weights for candidate "1" is the sum of the relative weights of "1" vs "2", "1" vs "3", "1" vs "4", "1" vs "5" and "1" vs "6".

For example,

the total relative weights for candidate "2" is the sum of the relative weights of "2" vs "1", "2" vs "3", "2" vs "4", "2" vs "5" and "2" vs "6".

(Note: the relative weight of "2" vs "1" is just minus of "1" vs "2")

The candidate with the greatest sum would be the victor.

Relative Choice Voting - Another Example

Please take a look at the video above. (Remember that Relative Choice Voting is an upgrade to Ranked Choice Voting)

Candidates are N, W, E, and S

Ranked votes are:

26 x N,S,E,W (ie 26 people choose N as 1st choice, S as 2nd choice, E as 3rd choice, and W as last choice)

15 x S,E,N,W

17 x E,S,N,W

42 x W,N,S,E

All possible selection of two candidates are:

N vs W

N vs E

N vs S

W vs E

W vs S

E vs S

Relative weights are:

N vs W = 26 + 15 + 17 - 42 = 16

N vs E = 26 - 15 - 17 + 42 = 36

N vs S = 26 - 15 - 17 + 42 = 36

W vs E = -26 - 15 - 17 + 42 = -16

W vs S = -26 - 15 - 17 + 42 = -16

E vs S = -26 - 15 + 17 - 42 = - 66

Total relative weights for each candidates:

N = 16 + 36 + 36 = 88

W = -16 - 16 - 16 = -48

E = -36 + 16 - 66 = -86

S = -36 + 16 + 66 = 46

N wins, followed by S, followed by W, and the least favorite to the whole is E

Judge for yourself if that should be the correct output

Relative Choice Voting - A Simple Explanation

Imagine four candidates A, B, C, and D. Visualize them as vertices on a shape such as a pyramid.

Relative weights were calculated and let them be, for example:

AB = 6

AC = 4

AD = -2

BC = 3

BD = -5

CD = 1

Since A, B, C, D are points of a pyramid, we can create a rule that AB means that B is displaced by the amount relative to A, and B's displacement relative to C and D is not affected. If AB was negative then A would be displaced while B remains.

Moving the loosing point is just half the pictures.

The above would give total displacement (losses) as:

A=2

B=11

C=7

D=1

If smaller is better, then D wins (This is half of the picture)

We can say that D wins because it was barely moved

Consider the pyramid again. Let's us say that AB gives it amount to a safe position of A relative to B. C and D not affected. A is displaced if the amount is positive, and B remains.

Moving the winning point is the other half of the picture.

The same relative weights above now would give a total displacement (wins) as

A=10

B=3

C=1

D=7

If larger is better, then A wins (This is other half of the picture)

We can say that A wins because it moved the most

The correct algorithm is to add both halves of the picture (losses and wins)

A = 10-2 = 8

B = 3-11 = -8

C = 1-7 = -6

D = 7-1 = 6

A seems to be the real victor given the relative weights at the beginning.

This is the simple sum of all the relative weights of AB AC and AD = 6 + 4 -2 = 8