2. INTRODUCTION (9 Hrs)
Computational Thinking - Information and
Data - Converting Information into Data –
Data Capacity – Data Types and Encoding –
Logic-Solving Problems – Limits of
Computation – Pseudo code and Flow Chart.
2
Department of IT, SMVEC
3. It represents a universally applicable attitude
and skill set everyone, not just computer
scientists, should be eager to learn and use.
3
Computational Thinking
Department of IT, SMVEC
4. Data
“The quantities, characters, or symbols on
which operations are performed by
computers and other automatic equipment,
and which may be stored or transmitted in
the form of electrical signals, records on
magnetic tape or punched cards, etc.”
4
Information and Data
Department of IT, SMVEC
5. Information:
“Knowledge communicated concerning some
particular fact, subject, or event; that of
which one is apprised or told; intelligence,
news” and adds that information is “that
which is obtained by the processing of data.”
Example:
Your credit card number is information that is
turned into data when it is stored on the back of your
card.
5
Department of IT, SMVEC
6. There are two different types of data
1. Continuous
2. Discrete
Data is continuous if there are an infinite
number of possible values for an individual
datum.
Data is discrete if there are a finite
number of possible values.
6
Converting Information into Data
Department of IT, SMVEC
7. Consider measuring the weight of an orange.
Although the orange could weigh exactly 200
grams, it might also weigh 229.3 grams or
229.31533 grams or even
229.31533480185993 grams.
7
Department of IT, SMVEC
8. Consider asking your friends how many
biological parents they have who are still
living. They may respond with the numbers 0
or 1 or 2. Since no person has more than 2
biological parents, numbers larger than 2 are
not possible and it should be obvious that it
is not possible to have a fractional number of
living parents.
8
Department of IT, SMVEC
9. In electronics, a signal may be either analog
or digital.
An analog signal is an encoding of
continuous data, whereas a digital signal is
an encoding of discrete data.
In digital systems, the smallest unit of data is
known as a binary digit, or bit.
A bit can only take on one of two possible
values:
ON(1) or OFF(0)
9
Department of IT, SMVEC
10. Computing systems encode all information as
a sequence of bits. Pictures, sound,
textbooks, and video are encoded as long
sequences of bits.
A sequence of bits is commonly referred to as
a bit string.
10
Department of IT, SMVEC
11. 00, 01, 10, 11
FIGURE 1.2: The four patterns that a string of two bits can exhibit are 00, 01,
10, and 11.
11
Department of IT, SMVEC
12. 000, 001, 010, 011, 100, 101, 110, 111
FIGURE 1.3: There are eight patterns that a string of three bits
can exhibit.
12
Department of IT, SMVEC
14. Data encoding requires us to know how many
bits are required to store a piece of
information.
When storing the symbols on a keyboard, for
example, we must know how many bits would
be required to store any one of the symbols.
Would it be possible to encode a keyboard
symbol as a 3 bit string or a 4 bit string
rather than an 8 bit string?
14
Data Capacity
Department of IT, SMVEC
15. You are given a list of all keyboard symbols and you
are also given a bit string of length three.
Your task is to generate a unique bit pattern for each
of the symbols in your list.
You begin with the symbol “A” and decide to encode
this symbol as 000.
As you move through the alphabet, you choose to
encode “B” as 001, “C” as 010, “D” as 011, “E” as 100,
“F” as 101, “G” as 110, and “H” as 111.
At this point you realize that there are no patterns
left to encode the remaining symbols of the keyboard
and hence a bit string of length three is not sufficient
to encode one keyboard symbol
15
Department of IT, SMVEC
16. A byte is a bit string of length eight.
A single byte, therefore, is able to store 28 or
256 unique patterns.
One other measure of data capacity is known
as a word (based on the hardware of a
computing system, multiples of 8).
A word is a fixed-length sequence of bits that
are processed as a single item by the
processor.
16
Department of IT, SMVEC
20. Numbers (Numeral Systems, Positional
Numeral System, Integers as Binary Bit
Strings, Real Numbers as Binary Bit Strings,
Precision as a Source of Error, Underflow and
Overflow as Sources of Error)
Text
Colors
Pictures
Sound
20
Data Types and Encoding
Department of IT, SMVEC
21. A numeral system is a way of representing
numbers in written form.
Consider, for example, the three numbers
shown in Figure
21
Department of IT, SMVEC
23. A positional numeral system must first
specify a base, also known as the radix that
describes how many digits exist in that
particular system.
Any positive integer greater than one can be
used as a base in a positional numeral
system.
23
Department of IT, SMVEC
25. Consider the example of Figure 1.11 that shows
how to interpret the decimal number 925. For this
number we see that the digit 5 is at position 0, the
digit 2 is at position 1 and the digit 9 is at position
2. The radix is assumed to be 10 and hence the
positional terms will be integral powers of 10. We
then understand that the digit 5 is a multiplier for
100, the digit 2 is a multiplier for the 101, and the
digit 9 is a multiplier for 102. In other words, the
number 925 is understood as (9 × 102) + (2 ×
101) + (5 × 100) and since any positive integer
that is raised to the 0th power is equal to 1 this
reduces to (9 × 100) + (2 × 10) + (5 × 1).
25
Department of IT, SMVEC
27. Computing systems represent integer
numbers as binary bit strings.
27
Department of IT, SMVEC
28. Although we can represent an integer as a
sequence of bits, is it possible to represent a
real number such as 2.31 or 2.125 or even
3.1415926?
For example, in base 10 the value 1.625
means (1 × 100) + (6 × 10–1) + (2 × 10–2) +
(5 × 10–3).
We can then represent real numbers as binary
bit strings assuming that we can determine
the decimal location.
28
Department of IT, SMVEC
29. Consider, for example, the meaning of
1.1012.
29
Department of IT, SMVEC
30. One difficulty that arises when encoding real
numbers is that there may be an arbitrary
number of digits on the right side of the decimal
value to represent even small numbers.
1/3 = 0.33333333333333333333333333
but soon realize that we will never be able to
write as many digits as are required for a
completely accurate representation
If a computer uses 16 bits to store real numbers,
we say that the computer is precise up to 16 bits,
or that the computer uses 16 bit precision.
30
Department of IT, SMVEC
31. Recall that an 8 bit binary string can only
hold values between 0 and 255.
Add 1 to the value 255 and store the result as
an 8 bit binary string. Of course the result
should be 256 but since 256 cannot be
encoded as an 8 bit binary string the result
will either be an error of some sort or, on
many computing systems
31
Department of IT, SMVEC
32. Underflow occurs when a computer
instruction produces a value that is too small
in magnitude (i.e., very close to zero) to be
encoded by the number of bits available.
32
Department of IT, SMVEC
33. All data that is stored in a computing system
is encoded as bit strings.
First, it is important to understand that a
textual character, when drawn on either a
page of text or on a computer screen, is
really just a picture.
Textual characters are usually encoded as
integer values using the encoding schemes
discussed earlier in this chapter.
33
Department of IT, SMVEC
35. The human eye perceives color through three
types of biological photo sensors known as
cones.
Each cone is attuned to one of three
wavelengths that correspond roughly to red,
green, and blue light.
The individual responses of all cones
combine to form the perception of a single
color at a single point within the field of view.
The design of this biological system suggests
that color is a three-dimensional entity.
35
Department of IT, SMVEC
36. The RGB color model is the most common
way of representing color in image-
processing systems. The RGB model uses red
(R), green (G), and blue (B) as the primary
colors such that any color can be created by
combining different amounts of these three
primaries.
36
Department of IT, SMVEC
37. The most common encoding of a digital
image is that of a two-dimensional grid of
colors.
Each element of the grid is known as a pixel
and represents a very small rectangular
region of the image that is comprised of a
single color.
When the grid of pixels is viewed at an
appropriate distance, the individual pixels
recede from view while collectively appearing
as a naturally colored and smooth image.
37
Department of IT, SMVEC
38. High-definition video uses individual images that
have up to 1920 columns and 1080 rows of pixels for
a total of 1920 × 1080 or 2,073,000 pixels. Since
each of these pixels is encoded as a bit string of
length 24, the image can be encoded as a bit string
of length 1920 × 1080 × 24 or 49,766,400 bits.
Alternatively, using a byte as a measure of data
capacity, the image can be encoded using 1920 ×
1080 × 3 or 6,220,800 bytes or approximately 6
megabytes.
Digital cameras take images that use on the order of
10 megapixels and images of this resolution can be
encoded as a string of 30 megabytes.
38
Department of IT, SMVEC
40. Digital audio is used almost exclusively today when
recording, processing, and distributing sound.
Online music stores contain hundreds of thousands
of hours of digital sound.
Sound is a physical phenomenon caused by
waveforms that propagate through the air.
A microphone is used to transform the waveform into
an analog electric signal after which the analog signal
is sampled to produce a digital encoding.
Sampling is a process where the strength of a
changing signal is measured at regular time intervals
and those measurements are then recorded.
In this way, the sound wave is converted into a
sequence of numeric values.
40
Department of IT, SMVEC
41. Frequency is the rate at which sound waves
change and is measured in terms of the
hertz.
The hertz is denoted as Hz and is defined as
the number of cycles (or changes) per
second.
Sound waves that change at a slow rate are
perceived as a low pitch while sound waves
that change at a high rate are perceived as
higher in pitch.
The average person can hear sound waves 20
Hz up through about 20,000 Hz or 20 kHz.
41
Department of IT, SMVEC
42. Logic, in its broadest sense, deals with
correct and incorrect ways to reason.
Logic provides a way to tell the difference
between incorrect and correct thinking, and
can therefore be defined as the science of
correct thinking.
Categories of logic :
Inductive logic and deductive logic.
42
Logic
Department of IT, SMVEC
43. Inductive logic is a type of reasoning that
begins with a set of observations or
experiences from which conclusions can be
derived with some degree of certainty.
43
Department of IT, SMVEC
44. Consider a scenario where you have eaten
brussels sprouts only twice in your life.
Unfortunately, you became physically ill
within hours of eating them and therefore
conclude you are allergic to brussels sprouts.
Although the conclusion that “I am allergic
to brussels sprouts” is reasonable,
It is not the only conclusion that could be
reasonably reached and is therefore not certain.
44
Department of IT, SMVEC
45. Perhaps you were coincidently exposed to a
contagious virus shortly before eating the
brussels sprouts and this virus was the actual
cause of your illness.
Conclusions reached in an inductive system
are necessarily uncertain and are directly
related to the number of experiences on
which the conclusion is based.
45
Department of IT, SMVEC
46. For example, the certainty of the conclusion
that “I am allergic to brussels sprouts” would
be increased if you ate them three more
times and became physically ill in each case.
46
Department of IT, SMVEC
47. By contrast, begins by assuming that certain
things are absolutely true from which other
facts must also be absolutely true. Any
conclusions that are reached under deductive
logic are absolutely, irrefutably, and certainly
true if the assumptions are true.
A conclusion is a statement of truth that must
logically flow from the premises.
47
Department of IT, SMVEC
48. syllogism as a logical argument that
contained two premises and a true conclusion
that must logically follow if the two premises
are actually true.
48
Department of IT, SMVEC
49. Premise: Computational thinking is beneficial
for all students.
Premise: Jemimah Farnsworth is a student.
Conclusion: Computational thinking is
beneficial for Jemimah Farnsworth.
49
Department of IT, SMVEC
50. Symbolic logic is a modern extension of
Aristotelian logic where symbols, rather than
phrases drawn from human language, are
used to represent statements of truth.
Logical operators, also known as logical
connectives, are used to express logical
thought.
Boolean logic is a symbolic logic system that
was created by a mathematician named
George Boole around 1850.
Modern computing systems rely heavily on
the rules of Boolean logic for generating
correct and reliable results.
50
Department of IT, SMVEC
51. Propositions form the basic units of Boolean
logic.
A proposition is a statement that can be
either true or false.
Stated another way, a proposition is a
statement that has a value of either true or
false.
51
Department of IT, SMVEC
52. True statement:
“Mount Everest is the tallest mountain in
the world.”
Answer: True
False statement:
“The Mississippi is the longest river in the
world.”
Answer: False
Note: Nile is the longest river in the world
52
Department of IT, SMVEC
53. “How tall is Mount Everest?”
No True or False
53
Department of IT, SMVEC
54. Propositions can be either simple or
compound.
A simple proposition is one that cannot be
broken into parts.
A compound proposition is formed by
combining simple propositions with logical
connectives, also known as logical operators.
There are four fundamental logical operators
that are best described by the words and, or,
implies, and not.
54
Department of IT, SMVEC
55. Simple: “I am hungry.”
Simple: “I am cold.”
Compound: “I am hungry and I am cold.”
Abbreviated:
P = “I am hungry.”
Q = “I am cold.”
S = “Mount Everest is the tallest mountain in
the world.”
“I am hungry and I am cold” as P and Q
55
Department of IT, SMVEC
56. Propositions must be well formed (i.e.,
properly written) to have meaning.
When writing a proposition, certain rules
must be exactly followed in order to
construct a meaningful proposition.
If these rules are not followed you may write
something that appears to be a proposition
but is actually just a meaningless jumble of
labels and operators.
Department of IT, SMVEC 56
57. Rule 1 - Each of the following is a simple
proposition.
a. Any single letter
b. True
c. False
Department of IT, SMVEC 57
58. Rule 2—Let a box (□) stand for a proposition
(either simple or compound).
Assuming that each box is some proposition,
then each of
the following are also propositions.
a. □ and □
b. □ or □
c. □ implies □
d. □ ≡ □
e. not □
f. (□)
Department of IT, SMVEC 58
60. When we evaluate a proposition, the goal is
not to make sure that it is well written but
rather to determine the truth value of the
proposition.
Consider, for example, the following simple
propositions.
P = “I am hungry.”
Q = “I am cold.”
evaluate the truth value of the compound
proposition.
P and Q
Department of IT, SMVEC 60
61. The truth value of the compound proposition
“P and Q” depends upon the truth values of
both P and Q.
Scenario 1: I have just finished eating
P and Q – False
“I am hungry and I am cold” – False
Scenario 2 : I am resting on the beach during a
sizzling summer afternoon
P and Q – False
Department of IT, SMVEC 61
63. For the binary operators there are only two inputs
and since each of these two inputs has only two
possible values there are only four situations that the
operator must handle.
for example, the following definition of logical
conjunction.
1. The logical conjunction of false with false is false.
2. The logical conjunction of false with true is false.
3. The logical conjunction of true with false is false.
4. The logical conjunction of true with true is true.
Department of IT, SMVEC 63
65. Logical disjunction, however, is not as
intuitive since our informal use of the word or
is not as closely connected to the way it is
formally defined.
Department of IT, SMVEC 65
66. Logical implication is perhaps the most
challenging operator to master.
This operator captures the idea that if one
thing is true, then some other thing must
also, by logical necessity, be true.
Department of IT, SMVEC 66
67. If the proposition “my car battery is dead”
has a value of True,
this implies that
the proposition “my car won’t start”
must also be true.
In Boolean logic we would say that “My car
battery is dead implies my car won’t start.” We
might phrase this informally as “whenever my
car battery is dead, my car won’t start.”
Department of IT, SMVEC 67
68. In the proposition “P implies Q” we refer to P
as the antecedent and Q as the consequent.
Consider the following two simple
propositions and their abbreviations.
P = “My car battery is dead.”
Q = “My car won’t start.”
Department of IT, SMVEC 68
69. 1. P is True and Q is True.
Consider the situation where we observe that “my car
battery is dead” and we also observe that “my car won’t
start.”
In this scenario, we understand that “True implies
True”
2. P is True and Q is False
We now observe that the car will start (since Q is False)
and that the car battery is dead.
The proposition that “P implies Q” must therefore be
false since this proposition is claiming that the car
won’t start whenever the car battery is dead.
In this scenario we understand that “P implies Q” is
logically inconsistent with the observed facts.
Therefore, “True implies False” has a value of False
Department of IT, SMVEC 69
70. 3.P is False and Q is True.
When the antecedent is false, there is no conclusion
that can logically be drawn with respect to the
consequent.
In this case, the statement that “P implies Q” has not
been disproven and therefore has a value of True.
For example, the observation that “my car battery is
not dead” and that “my car won’t start” does not
contradict the statement that “whenever my car
battery is dead my car won’t start.”
Perhaps the car won’t start for some reason unrelated
to the car battery.
Since there is no logical contradiction between the
observed situation and the statement that “My car
battery is dead implies my car won’t start” we
understand that “False implies True” is true.
Department of IT, SMVEC 70
71. 4.P is False and Q is False.
Again, since the antecedent is False, we
understand that “False implies False” is True.
In this situation, we observe that “my car
battery is not dead” and we also observe that
“my car will start.”
Department of IT, SMVEC 71
72. Variables P and Q are said to be equivalent if
they have the same truth value.
Truth table for logical equivalence
Department of IT, SMVEC 72
73. Logical negation is the only unary operator.
This operator expresses the obvious thought
that if something is not true then it must be
False, and if something is not False then it
must be True.
Department of IT, SMVEC 73
74. To evaluate propositions that involve more
than one operator, we can apply the same
process, but it must be applied once for every
operator in the proposition.
Department of IT, SMVEC 74
75. For the situation where
P = True, Q = False, and R = True.
1. Parentheses are used to group the sub
proposition “(Q or R).”
For this reason, we first use the disjunction table
to evaluate “(Q or R)”
where Q = False and R = True.
Q or R - True
Once we have evaluated “(Q or R)” to True we can
replace that sub proposition by its value and
continue our process of evaluation. We now have
the proposition
P and True
Department of IT, SMVEC 75
76. for this situation
where P = True,
Q = True and
R = False.
There are two operators in this proposition and
they should be evaluated from left to right.
P and Q – True
True implies R - False
Department of IT, SMVEC 76
77. Q implies R (Parenthesis first)
P and False
Final Answer = False
Department of IT, SMVEC 77
78. 1. Make a list of each logical variable (abbreviation)
that appears in the proposition. If one variable occurs
more than once in the proposition, it should be
included only once in your list.
2. Place a column in the truth table for every variable
list your list. The column heading should be the
variable itself.
3. For the heading of the last column you should
write the entire proposition.
4. If there are N variables in your list, you must create
2N rows. Each row represents a unique combination
of values for the N variables.
5. For each row, determine the value of the
proposition and place that value in the last column.
Department of IT, SMVEC 78
79. P and not (Q or R)
Department of IT, SMVEC 79
82. Two propositions are said to be equivalent if they
have the same truth table. Consider, for example,
the two propositions
not (P and Q)
(not P) or (not Q)
When two propositions are equivalent, they have
the same meaning and are therefore
interchangeable.
Department of IT, SMVEC 82
83. Any proposition that has a value of True
regardless of the inputs is said to be a
tautology.
Since a tautology is always True
Any proposition that has a value of False for
all inputs is said to be a contradiction.
Contradiction can be understood as a
statement that is always logically invalid no
matter how you look at it.
Department of IT, SMVEC 83
84. Tautologies and contradictions should be
avoided when writing propositions and they
should also be avoided in the normal course
of human conversations since such
statements do not express any sort of
productive line of reasoning. The following
propositions give examples of a tautology
and a contradiction.
Tautology: P or not P
Contradiction: P and not P
Department of IT, SMVEC 84
87. 87
SYMBOLS NAME
Flowline symbol
USE
Sequence of operations
and direction of data flow
Decision symbol Decision-making operations
Predefined-process
symbol
Operations specified elsewhere
(not in the current algorithm)
88. 88
SYMBOLS NAME
Connector symbol
USE
Exit to, or entry from,
another part of the
Flowchart
Preparation symbol Control operations: Set
limit on loop-control
variables, Initialize
accumulators, etc.