boolean algebra - Coding Ninjas
boolean algebra - Coding Ninjas
Saloni Singhal
Introduction
Boolean algebra is a division in mathematics that deals with logical operations and incorporates
binary variables. The distinguishing factor of Boolean algebra is that it deals with the study of
binary variables. Boolean variables are represented with the possible values of 0 (false) or 1 (true).
The variables can also have more complex interpretations, such as set theory. The modern use of
Boolean algebra is in computer programming languages.
This blog will discuss Boolean Algebra, its function, laws, and its complement, along with the truth
table and logical diagram.
Boolean Algebra
Boolean algebra is a category of algebra that deals with the truth values of the variables. i.e., Truth
or false, ideally represented in the form of 1 and 0, respectively. Elementary algebra deals with
numeric operations, whereas Boolean algebra deals with logistic operations. Boolean algebra is
also known as Binary Algebra. It uses conjunction, disjunction, and negation, instead of addition,
subtraction, multiplication, and division.
The three basic algebraic operations in the order of their precedence are as follows:
Negation (NOT operation): The negation of two variables is represented by the given Venn
diagram. Here, the region except for the negated variable is included in the result. It is also
represented by the ‘ or ¬ symbol.
Source: Link
Disjunction (OR operation): The given Venn diagram represents a disjunction of two
variables. Here, the entire region covered by A and B represents the disjunction. (A ∨ B) It is also
represented by + or ∨ symbol.
Source: Link
The table used to represent the Boolean expression is commonly known as Truth Table. A logic
gate truth table represents every possible input combination to the gate with the resultant output
depending upon the combination of these inputs. The number of rows in a Truth Table is equal to
2n, where n equals the number of literals in the given function.
A Boolean function is formed with binary variables, operators (AND, OR, and NOT), and
parenthesis. The value of a Boolean function can either be 0 or 1. A Boolean function can be
represented in a truth table or an algebraic expression.
Y = X + (W)’ ^ Z
Here, variable Y is a function of X, W, and Z that can also be written as Y= f(X, W, Z).
The RHS of the equation is known as expression, and the variables X, W, and Z are known as the
literals of the expression. A Boolean function can have more than one algebraic expression.
Y = X + (W)’ ^ Z
Truth Table for the given expression will look like this:
Laws in Boolean Algebra
Commutative Law: This law states that changing the order of operands in a Boolean equation
doesn’t affect the output of the equation.
Example: A + B = B + A
Associative Law: This law states that the output of the Boolean equation does not depend on the
order of the logical operands.
Example: (A*B)*C = A*(B*C)
Inversion Law: This law states that the double inversion of the variable results in the original
variable. i.e., A = (A’)’.
The most important theorem used in Boolean Algebra is known as De Morgan’s Law/ Theorem
depending on the concept of duality. Duality states the interchanging of operators such as AND to
OR and vice-versa, or the variables 0 to 1 and 1 to 0.
De Morgan's First Law: This law states that the negation of a conjunction is the disjunction of
the negation, which implies that the complement of the variable’s product is equal to the sum of
their complements.
( A . B)’ = A’ + B’
We can verify the above expression by the given truth table:
De Morgan’s Second Law: This law states that the negation of a disjunction is the conjunction
of the negation, which implies that the complement of the variable’s sum is equal to the product of
their complements.
( A + B )’ = A’. B’
We can verify the above expression by the given truth table:
Let’s try to understand the concept of a logic diagram through some examples. Consider the
following examples:
The logic diagram for the Boolean expression can be represented as:
The given Boolean expression is converted into a logic diagram consisting of AND, OR, inverter
gates with the help of the truth table. The inverter at B generated B’. Similarly, there is an AND
gate attached for the expression B’C, and at last, the OR gate is used to combine the complete
expression A + B’C.
The truth table for the given expression will look like this:
What is the easiest way to determine the cache location to store the memory blocks?
Direct mapping is one of the easiest ways to define the cache locations to store memory blocks. It
maps each block of the main memory into one possible cache line. The cache in a direct-mapped
structure is organized into several sets, a single line per set. Based on the memory block's address,
it can only use a single cache line. The cache can also be framed as a column matrix.
What do you understand by the term wait-state?
A wait-state is when a computer processor experiences a delay while accessing a device or an
external memory. We try to minimize or eliminate wait-states as they are considered wasteful in a
processor's performance. These include pipelines, caches, instruction prefetch, branch prediction,
and simultaneous multithreading. These techniques can't eliminate wait-states, but they can
significantly minimize the problem when implemented simultaneously.
Key Takeaways
This blog discussed Boolean Algebra, its complement, functions, laws, along with the truth table
and logic expressions. Boolean Algebra is very useful when dealing with complex expressions. Such
expressions can be simplified using Boolean logic diagrams and truth tables.
If you are a beginner and are interested in learning other fields related to computer subjects such
as web development, or competitive programming, you can follow our guided path to get a good
grip on such concepts.