Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

TRUE and FALSE

Example:
"Greece is in Asia" = FALSE
"The Nile is the longest river in the world" = TRUE

AND and OR statements


IF age >= 18 AND nationality = Egyptian THEN You can vote in Egypt IF
today = Saturday OR today = Friday THEN No School
IF Health < 20 AND Character is touching enemy THEN Game Over

NOT statement
IF NOT(today = Holiday) THEN You have work to do
IF NOT(want food on menu AND have enough money) THEN Find another
restaurant

Boolean operators
Boolean operators are used to connect and compare the relationship between
arguments. The result will be either TRUE or FALSE.
Logic Gates
Logic gates are the building blocks of a digital circuit.
Every terminal in a logic gate will always be in one of the two binary states (0)
or (1).
These binary states represent the presence (1), or absence (0), of an electrical
voltage. Binary (1) can be referred to as positive or ON, whilst binary (0) can be
called negative or OFF.
There are many types of logic gates:
Logical gate Truth Table

NOT

AND

OR

NAND
NOR

Real Life Application


OR gate is used in many of our real-life applications. One of its applications,
“Alarm circuit for car door system” is explained below.
We design this alarm by connecting four circuits to the 4 doors of the car (or
any vehicle) when the door is open, the circuit generates high output (Logic 1)
and similarly when the door is closed, the circuit generates 0 (Logic 0). The 4
outputs of four doors are connected to a 4 –input OR gate, which output is
connected to an alarm.

When any one or more doors are opened, then the output of the 4- input OR
gate is 1, then the alarm rings. So that we can know the condition of doors,
whether they are properly closed or not.
The logic AND gate is used in some sort of security devices like garden flood-
lights and security lights etc. They have a heat- radiation sensitive device called
“Passive Infra- Red device (PIR)”. So when a hot object such as intruder
(unauthorized entries like neighbor’s pets) is detected by the device, the heat
sensor produces a high voltage making it to set in logic 1.
As the light of flood- light did not clearly visible in day time these devises
comes in use, when the surroundings /atmosphere is dark. It comes to ON state
when the heat sensor is triggered. The block diagram this security system with
AND gate is shown below.

The mono -stable device produce only a single pulse when it is triggered. When
the output of AND gate becomes high, then the output of the mono –stable
device also goes high and hold for some interval of time. Transducer is used to
provide enough current for the flood light.
As the flood light is a high voltage device, the output produced by the mono-
stable device is not enough to drive the light. So we use a transducer to boost
the current.
In commercial security devices, we use a Relay as a switch to ON and OFF the
flood light.
Example: Complete the truth table for the give logic circuit
A logic circuits is shown
D

Complete the truth table for the give logic circuit


A B C D E F G H Y
(A NAND A) (A NANAD B) (B NAND C) (C NAND C) (E OR F) (D OR H OR G)

0 0 0 1 1 1 1 1 1
0 0 1 1 1 1 0 1 1
0 1 0 1 1 1 1 1 1
0 1 1 1 1 0 0 1 1
1 0 0 0 1 1 1 1 1
1 0 1 0 1 1 0 1 1
1 1 0 0 0 1 1 1 1
1 1 1 0 0 0 0 0 0
Q: Build logic gates to test the following logical statement
1. (A AND B) OR C

2. A OR B OR C

another answer
Difference between Stack and Queue
Stack A stack is a linear data structure in which elements can be inserted and deleted
only from one side of the list, called the top. A stack follows the LIFO (Last In First
Out) principle, i.e., the element inserted at the last is the first element to come out.
The insertion of an element into the stack is called push operation, and the deletion of
an element from the stack is called pop operation. In stack, we always keep track of
the last element present in the list with a pointer called top.
The diagrammatic representation of the stack is given below:

Example:
• stack of books, you take a book from the top and add books to the top. It is a
‘first in, last out’ data structure.
• ‘undo’ function of a word processor – undoing each past action from top to
bottom.

Queue is a linear data structure in which elements can be inserted only from one side
of the list called rear, and the elements can be deleted only from the other side called
the front. The queue data structure follows the FIFO (First In First Out) principle, i.e.
the element inserted at first in the list, is the first element to be removed from the list.
The insertion of an element in a queue is called an enqueue operation and the deletion
of an element is called a dequeue operation. In queue, we always maintain two
pointers, one pointing to the element which was inserted at the first and still present in
the list with the front pointer and the second pointer pointing to the element inserted
at the last with the rear pointer.
The diagrammatic representation of the queue is given below:

Example:
• printers
• keyboards
• buffers playing sound and video (e.g.
YouTube)
Sets
A set is a well-defined collection of distinct objects. The objects that make up a set
(also known as the elements or members of a set) can be anything: numbers, people,
letters of the alphabet, other sets, and so on. Georg Cantor is the founder of set theory.
Sets are conventionally denoted with capital letters. Sets A and B are equal if and only
if they have precisely the same elements.
The following notation is commonly used to specify a set:
A={2,3,5,7,9}

Basic Set Operations


Unions:
Two sets can be "added" together. The union of A and B, denoted by A ∪ B, is the set
of all things that are members of either A or B.
Examples:
• {1, 2} ∪ {1, 2} = {1, 2}.
• {1, 2} ∪ {2, 3} = {1, 2, 3}.

Intersections:
A new set can also be constructed by determining which members two sets have "in
common". The intersection of A and B, denoted by A ∩ B, is the set of all things that
are members of both A and B. If A ∩ B = ∅, then A and B are said to be disjoint.
Examples:
• {1, 2} ∩ {1, 2} = {1, 2}.
• {1, 2} ∩ {2, 3} = {2}.
Difference:
Two sets can also be "subtracted". The relative complement of B in A (also called the
set-theoretic difference of A and B), denoted by A \ B (or A − B), is the set of all
elements that are members of A but not members of B. Note that it is valid to
"subtract" members of a set that are not in the set, such as removing the element green
from the set {1, 2, 3}; doing so has no effect. In certain settings all sets under
discussion are considered to be subsets of a given universal set U. In such cases, U \ A
is called the absolute complement or simply complement of A, and is denoted by A′.
Examples:
{1, 2} − {1, 2} = ∅.
{1, 2, 3, 4} − {1, 3} = {2, 4}.
a. Draw a diagram to show how these two sets intersect
x1 = {'foo', 'bar', 'baz'}
x2 = {'baz', 'qux', 'quux'}

X1
X2
foo qux
baz

quux
bar

b. X1UX2={foo, bar, baz, qux, quux}

c. X1 ∩ X2= {baz}

d. X1 - X2={foo, bar}

You might also like