CODING THEORY the unit most computers use to
represent a character such as a
letter, number or typographic symbol.
CODING THEORY
Coding theory is the study of the properties of codes and EXAMPLE:
their respective fitness for specific applications. Codes are Consider the source encoding of four directions as follows:
used for data compression, cryptography, error detection NORTH – 00
and correction, data transmission and data storage. SOUTH – 01
EAST – 10
CODES WEST – 11
Codes are studied by various scientific disciplines, such as
information theory, electrical engineering, mathematics, Suppose the message “NORTH”, which is encoded as 00,
linguistics, and computer science—for the is transmitted over a noisy channel. The message may
purpose of designing efficient and reliable data encounter errors and may be received as 01. The
transmission methods. receiver will get the message 01 and decode it as
This typically involves the removal of redundancy and the “SOUTH” without realizing that the message is
correction or detection of errors in the transmitted data. corrupted
EXAMPLE:
Consider the source encoding of four directions as follows:
NORTH – 00
COMMUNICATION SYSTEM SOUTH – 01
The communication system composed of sender (or EAST – 10
message source), communication channel, and the WEST – 11
receiver.
With this problem at hand, additional process of encoding is
required known as Channel Coding.
Communication Channel
Is the physical medium through which information is
transmitted.
Ex: telephone lines, internet cables, fiber-optic lines, and
air. Some storage data can be considered channels (CD-
ROMS, hard drives).
Noises
It alters the message in the channel that will cause CHANNEL CODING
disruption and error in the messages. Is defined as adding some form of redundancy to the
source encoded message so that the errors can be
Source Coding and detected or even corrected.
Channel Coding PARITY CHECK
In transmitting messages, coding is defined as source Parity check is also called as “Vertical Redundancy Check
coding and channel coding. (VRC)”
Where in single bit is added to the message as redundancy
Two Processes in Coding bit.
ENCODING A bit string is said to have an odd parity if there is
Encoding is transforming messaged into bits of message an odd number of 1s.
that is cuitable in communication. Even parity if there is an even number of 1s. We
add redundancy bit to message such that it will
DECODING become an even parity.
Decoding is the opposite process of encoding.
Odd Parity
DATA COMPRESSION OR If the data has even number of 1’s, the parity bit is 0.
SOURCE ENCODING Odd number of 1’s, the parity bit is 1.
Is defined as converting the message from the Example:
sender into bits suitable to the communication channel. - Data is 10010001 parity bit 1
Bit (short for “binary digit”) is the Even Parity
smallest unit of measurement used to quantify If the data has odd number of 1’s, the parity bit is 0.
computer data. It contains a single binary value of 0 or 1. Even number of 1’s, the parity bit is 1.
Example:
An example of this is the ASCII (AMERICAN - Data is 10010101 parity bit 1
STANDARD CODE) that converts each
character in the message to a byte of 8 bits. REPETITION CODE
ENCODING
In most computer systems, a byte is a unit of data that is
In coding theory, the repetition code is one of the most
eight binary digits long. A byte is
basic error-correcting codes.
In order to transmit a message over a noisy channel Modulo addition is defined as (a*b)mod m
that may corrupt the Modulo addition is defined as (a/b)mod m
transmission in a few places, the idea of the repetition CRYPTOGRAPHY
code is to just repeat the
message several times.
Suppose that the source encoding is already done and that CRYPTOGRAPHY
the encoded message is It is a science of protecting information by encoding it into
of fix length k. The channel encoding by repetition is unreadable format.
performed by taking the k bits Originated from two Greek words such as “KRYPTO”
then repeating it 2r + 1, where r is greater than or equal to 1 which means hidden and “GRAPHENE” which means
is a fixed integer. writing.
Example: It is a method of making and breaking of secret codes.
Suppose that the source encoded message is 110 It is a science of encrypting and decrypting written
where k=3. If you choose r=2, the communication.
message must be repeated 2r +1 = 2(2) + 1 or 5 times.
This will result to 110110110110110.
REPETITION CODE
DECODING
Example:
Assume that the message transmitted through a noisy
channel and ENCRYPTION
distorted. The received message is 111001101110010. The It is the process of transforming plain text into codes form
channel encoding using a certain algorithm.
uses repetition code where k= 3. Decode the received
message. DECRYPTION
It is a process of returning/converting back the coded
Solution: 111 001 101 110 010 message into plain text.
First Bit - Consider the most frequent bit in positions 1, 4,7,10, PLAIN TEXT
and 13. Refers to the original text.
Second Bit - Consider the most frequent bit in positions 2, 5,
8, 11, and 14.
CIPHER TEXT
Third Bit - Consider the most frequents bit in positions 3, 6, 9,
12, and 15. Refers to the coded text.
111/001/101/110/010 KEY
1 2 3 / 4 5 6 / 7 8 9 / 10 11 12 / 13 14 15 / Refers to the strings of information that is used to reveal
Decoded Message: 111 the encrypted message into readable form.
SHIFT CIPHER (CEASAR CIPHER)
MODULAR ARITHMETIC It is a simple type of substitution cipher.
It uses shift in forming the key of cryptography.
MODULAR ARITHMETIC
Is a system of arithmetic for
MODULO OPERATOR
integers, which considers the The sender uses the key K to encrypt and to decrypt the
remainder. secret message.
In modular arithmetic, numbers "wrap around" upon
reaching a given fixed quantity (this given quantity is known TO ENCRYPT
as the modulus) to leave a remainder. 1. Express the letters of the alphabet from 0 – 25.
2. Calculate Y=(C+K)mod 26
CONGRUENCE 3. Convert the number Y into a letter following the order of the
Let a and b are integers and m is a natural counting letter of the alphabet.
number.
a IS CONGRUENT TO b MODULO m” a≡b (mod m), IF m TO DECRYPT
DIVIDES a-b OR b-a. 4. Express the letters of the alphabet from 0 – 25.
5. Calculate C=(Y-K)mod 26
LEAST RESIDUE 6. Convert the number C into a letter following the order of the
To determine the least residue is to simply get the letter of the alphabet.
remainder when b is divided by m.
b(mod m) means b divided by m. m is referred to as the
modulus (divisor) CHECK CODES AND CHECK DIGITS
OPERATIONS IN MODULAR CHECK CODES AND CHECK DIGITS
ARITHMETIC There are several methods in producing identification
Modulo addition is defined as (a+b)mod m numbers which are unique.
Modulo addition is defined as (a-b)mod m
In the following methods, modular arithmetic is used to It means that the numbers of representative (the seat) is
produce and verify identification numbers. proportion to the population size being represented.
The Examples are: THE HAMILTON PLAN
- The Universal Product Code (UPC), United States Standard Divisor (D)
Postal Services (USPS), the Credit Card, and the The number of voters represented by each representative.
International Standard Book Number (ISBN).
- Each example uses their last digit as the check digits Formula:
to verify the identification number. D = total population =N
no. of representatives R
UNIVERSAL PRODUCT CODE (UPC) Standard Quota (Q)
Universal Product Code (UPC) is mainly used in products
The whole part of the quotient when the population of the
sold in department stores and groceries. The UPC consists
sub- group is divided by the standard divisor.
of barcodes with 12 digits where the last one is the check
digit.
Formula:
D = sub- group population =N
FORMULA (UPC) Standard Divisor R
CHECK DIGIT : d12
d12= 10 – (3d1 +d2 + 3d3 + d4 +3d5 +d6 + 3d7 + d8 + 3d9 + Note for the Hamilton Plan:
d10 + 3d11)(mod10) 1. Standard quota, Q must be an integer. In case of decimals,
just drop the decimal values.
INTERNATIONAL STANDARD 2. When the total standard quota is not equal to given total
BOOK NUMER (ISBN) apportioned or the number of representative, place an
The International Standard Book Number (ISBN) is used on additional representative to the next the sub – group
books where usually found at the last page of the book. representative with the highest decimal value until the
ISBN can be ISBN-10 or ISBN-13 where they used 10 representatives are complete.
digits or 13 digits string of number respectively with the last
digit as the check digit. THE JEFFERSON PLAN
This method uses a modified standard divisor that
FORMULA (ISBN-10) arrives at the correct or exact numbers of representative
CHECK DIGIT : d10 using trial and error.
d10 = 11- (10d1 + 9d2 + 8d3 + 7d4 + 6d5 + 5d6 + 4d7 +3d8 The modified uses an assume value always smaller than
+2d9)(mod 11) the standard divisor.
FORMULA (ISBN-13) APPORTIONMENT PRINCIPLE
CHECK DIGIT : d13 A new representative is added to a sub – group due to an
d13= 10 – (d1 + 3d2 + d3 + 3d4 + d5 + 3d6 + d7 +3d8 + d9 + increase in population.
3d10 + d11 + 3d12)(mod10) The representative is assigned to the group in such a way it
gives the smallest relative unfairness of apportionment.
UNITED STATES POSTEL This principle is applied when making a decision
SERVICES (USPS) regarding to which subgroup shall receive an
Lastly, the United States Postal Services (USPS) is addition representative.
consisting of 11 digits, while the Credit Card uses 16 digits
where both of them use their last digits as the check digits.
FORMULA (UPS)
CHECK DIGIT : d11
d11 = 9 – (d1 +d2 + d3 + d4 + d5 + d6 + d7 + d8 + d9 + d10)
(mod 9)
CREDIT CARD
FORMULA (CREDIT CARD)
CHECK DIGIT : d16
d16 = 10 – (2d1 +d2 +2d3 +d4 +2d5 +d6 +2d7 +d8 +2d9 +d10
+2d11 +d12 +2d13 +d14 +2d15 )(mod10)
NOTE: ADD ALL THE DIGITS, TREATING THE TWO-DIGIT
NUMBERS AS TWO SINGLE
DIGITS.
APPORTIONMENT
APPORTIONMENT
“The equal proportion”
Is a method of dividing a whole into various parts.
Some other sub-group loss or gain a representative even
when a number of representatives were added to account
for the new sub-group’s population.
HUNTINGTON-HILL APPORTIONED
METHOD VOTING
The method that make use of equal proportion.
The new additional representative to a sub – group must VOTING
have the highest Huntington number. Voting is a powerful tool in decision making.
It is a method that uses votes to determine the winner.
Preference Schedule
It is the matrix of summary of votes casted by the voters.
Preference Ballot
It is a ballot in which the voters rank the choices in
order of preference.
MAJORITY VOTING
Majority Vote: over 50 % of the people voting must vote for
the candidate
PLURALITY METHOD
Each voter votes for one candidate, and the candidate with
the most votes wins. The winning candidate does not have
to have a majority of the votes.
Majority Vote: Over 50% of the people voting must vote for
the candidate.
Limitation of the Plurality Method: Alternative choices
are not considered.
In-case of ties, voting should be done using the run-off
election.
BORDA COUNT METHOD
If there are n candidates or issues in an election, each
voter ranks the candidates or issues by giving n points to
CRITERIA OF FAIRNESS FOR AN the voter’s first choice, n-1 points to the voter’s second
choice and so on, with the voter’s least favorite choice
APPORTIONMENT receiving 1 point. The candidate or issue that receives the
Quota Rule most total points is the winner.
The number of representative apportioned to a state is the Award points to candidates based on preference schedule,
standard quota or one more than the standard quota. and then declare the winner to be the candidate with the
most points.
Hamilton ALWAYS satisfies this rule. In general, if Nis the number of candidates...
Jefferson Plan sometimes satisfies this rule. Each first-place vote is worth N points.
Each second-place vote is worth N –1points.
Average Constituency Each third-place vote is worth N –2points.
The average constituency of the sub-group is Each Nth-place (i.e., last place) vote is worth 1 point.
approximately the same. CANDIDATE CANDIDATE CANDIDATE
A B C
C = Sub – group Population 1ST PLACE 10 20 40
Number of representatives from the sub – group (3 POINTS)
2ND PLACE 20 40 10
(2 POINTS)
C should be rounded to the nearest whole.
3RD PLACE 40 10 20
(1 POINT)
APPORTIONMENT PARADOXES Candidate A: (3x10) + (2x20) + (1x40) = 110 points
Albama Paradox Candidate B: (3x20) + (2x40) + (1x10) = 150 points
Even when population of sub-groups does not change, one Candidate C: (3x40) + (2x110) + (1x20) = 160 points
sub-group loses a representative.
Number of
Voters 35 30 20 15
Population Paradox
A sub-group loses a representative even when its 1st Place
(4 Points) B D C D
population is increasing faster than that of the other sub-
groups. 2nd Place
(3 Points) C A A C
New States Paradox 3rd Place
(2 Points) A B B A
4th Place If a candidates who wins an election, the winner should
(1 Point) D C D B remain winner in any recount in which the losing candidates
withdraw from the race.
Ayala (A): 70 + 90 + 60 + 30 = 250
Bonifacio (B): 140 + 60 + 40 + 15 = 255 Violated by: Borda Count
Calixto (C): 105 + 30 + 80 + 45 = 260
Dancel (D): 35 + 90 + 20 + 60 = 235
PLURALITY BY ELIMINATION
The plurality with elimination voting method is also known
as an instant run-off voting and sequential run-off voting.
It is a preferential voting method and candidates that have
the least first place votes get eliminated until one candidate
has majority of first place votes.
First, eliminate the candidate with the fewest
number of first-place votes
If two or more of these alternatives have the same
number of first-place votes, all are eliminated unless
that would eliminate all alternatives. In that case, a
different method of voting will be used.
Adjust the voter’s ranking at the remaining
candidates.
Repeat the same process of elimination and
adjustment until two candidates are left.
PAIRWISE COMPARISON VOTING
Compare each two each two candidates head-to-
candidates head-to-head.
Award each candidate each candidate one point for each
one point for each head-to-head victory.
The candidate with the most points wins.
The “head-to-head method”
Each candidate is compared one-on-one with each of the
other candidates
A candidate receives 1 point for a win, 0.5 points for a tie
and 0 points for a loss.
The candidate with the greatest number of points wins the
election.
FAIRNESS OF VOTING CRITERIA
Majority Criterion
The candidates who receive a majority of the 1st –place
votes are the winner.
Violated by: Borda Count and Pairwise
Monotonicity Criterion
If candidate A wins an election, then candidate A will also
win the election if the only change in the voters’ preference
is that supporters of a different candidate changes their
votes to support candidate A.
Violated by: Plurality by Elimination (has the greatest chance)
and Pairwise
Condercet Criterion
A candidate who wins all possible head to head matchups
should win an election when all candidates appear on the
ballot.
Violated by: Plurality by Elimination and Borda Count
Independence of Irrelevant Alternatives