Professional Documents
Culture Documents
FPT University 1
Agenda
1.1 Basic Theory of Information
1.2 Information and Logic
1.3 Data Structures
1.4 Algorithms
FPT University 2
FPT University 3
1
Conversion of Decimal Integers to
Binary Numbers
The number is divided by 2 repeatedly until the
quotient becomes 0.
FPT University 4
FPT University 5
Binary to Hexa
group the binary number into blocks of 4 bits,
starting from the lowest bit (rightmost bit), and
then assign the corresponding hexadecimal digit
for each block
FPT University 6
2
Hexa to Binary
Assign the corresponding 4-bit binary number to
each digit of the given hexadecimal number.
FPT University 7
Decimal to Hexa
convert the decimal number to binary first, and
then convert the binary number to hexadecimal
number
FPT University 8
Q->
Hexa to Decimal
convert the hexadecimal number to binary first,
and then convert the binary number to decimal
FPT University 9
3
FAQ
There are many questions mixing multiple radices
(bases) such as Which of the following is the correct
result
(in decimal) of adding the hexadecimal and binary
numbers?
If the final result is to be represented in decimal, it is
better that you convert the original numbers to decimal
first and then calculate it.
If the final result is to be represented in a radix other
than 10 (binary, octal, hexadecimal, etc.), it is better that
you convert the original numbers to binary first and then
carry on the calculation
FPT University 10
Numerical Representations
Decimal numbers are represented in packed or
zoned format.
Binary numbers are represented in fixed-point or
floating-point format.
FPT University 11
Numerical Representations
FPT University 12
4
Decimal Number Representation
Zoned decimal format
Each number is represented by 1 byte (8 bits)
FPT University 13
FPT University 14
FPT University 15
5
Twos complement
FPT University 16
Floating-Point Number
Representation
A real number is represented in exponential
form ( a = +m x r e ) using a fixed-length binary
number
IEEE 754
FPT University 17
FPT University 18
6
Floating point number
Biased notation
IEEE 754 uses a bias of 127 for single precision
(-1)S x (1 + Fraction) x 2 (Exponent - Bias)
S is the signed bit 0 is positive
1 is negative
FPT University 19
Example
Show the IEEE 754 binary representation of the
number -0.7510 in single precision
Exponent part
FPT University 20
FPT University 21
7
Floating point addition example
Add 0.5 and -0.4375
FPT University 22
FPT University 23
FPT University 24
8
Floating point multiplication
FPT University 25
FPT University 26
FPT University 27
9
Floating point multiplication
FPT University 28
FPT University 29
FAQ
There are many questions on converting a given
binary number into the corresponding negative
number and converting a given negative number
into the corresponding positive number.
FPT University 30
10
Non numeric representation
In general, each character is represented by 8
bits.
In multimedia, data associated with still image
data, moving picture data, and sound data is
handled
FPT University 31
Character representation
BCD Code (Binary Coded Decimal Code)
Each digit can be represented by 4 bits
FPT University 32
FPT University 33
11
Standardizations of Character Codes
Code Name Explanation
FPT University 34
FPT University 35
MPEG
Compression format for color moving pictures,
or the name of the joint organization of ISO and
IEC which established this standard
FPT University 36
12
Sound
Sound
FPT University 37
FAQ
There have been many exam questions that
require some knowledge of organizations which
have established functions and standards
regarding JPEG and MPEG. Several keywords,
such as JPEG, ISO, and ITU-T for still images,
MPEG, ISO, and IEC for motion pictures, should
be checked prior to the exam.
FPT University 38
FPT University 39
13
Shift operations
A shift operation is the operation of shifting
(moving) a bit string to the right or to the left.
Arithmetic left shift
Logical left shift
Arithmetic right shift
Logical right shift
FPT University 40
Arithmetic shift
Data is treated as numeric data with a positive
or negative sign
Right shift inserts a value identical to the sign bit
into the leftmost place
FPT University 41
Q->
Logical shift
Data is treated as bit string
0s are inserted in the vacated bits
FPT University 42
14
Errors
Since operations are executed by a computer
register with a limited number of digits,
numerical values that cannot be contained in the
register are be ignored.
FPT University 43
Rounding Error
Since computers cannot handle an infinite (non-
terminating) fraction, bits smaller than a certain
bit are rounded off, rounded down, or rounded
up to the value with the limited number of
significant digits. The difference between the
true value and the result of such rounding is
called the rounding error (or round-off
error).
FPT University 44
FPT University 45
15
Loss of trailing digits
When a very large number and a very small
number are added together, or when one is
subtracted from the other, some information (or
a part thereof) in the lower digits, which cannot
be contained in the mantissa, can be lost due to
the alignment of the numbers.
FPT University 46
FAQ
Understand the different characteristics of the
errors
Questions may be asked about the type of error
that may occur when values are manipulated
FPT University 47
FPT University 48
16
Definitions of Logical Operation
Logical Notation Meaning
operation
Logical A B The result is 1 only when both bits
product (AND) are 1s
FPT University 49
A B = A B+ A B
FPT University 50
De Morgans Theorem
(A B)=A+B
(A +B)=A B
FPT University 51
17
FAQ
Many questions can be easily answered if you
know De Morgan's theorem. There are also
many
questions that can be easily answered if you
know the expanded form of exclusive logical
sum.
FPT University 52
Adder
An adder is a circuit that performs addition of 1-
bit binary numbers, consisting of AND, OR,
and NOT logic circuits.
Half adder
Full adder
FPT University 53
Half adder
A B C S
Truth table 0 0 0 0
0 1 0 1
C=A B
1 0 0 1
S=A B
1 1 1 0
FPT University 54
18
Full adder
There are three input values, one of which is the
carry-over from the lower bit.
X Y Z C S
0 0 0 0 0
0 0 1 0 1
0 1 0 0 1
0 1 1 1 0
1 0 0 0 1
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1
FPT University 55
Karnaugh Maps
Karnaugh Maps
FPT University 56
FPT University 57
19
BNF
Sequence
<x >:: =<a><b>
This gives a definition which means the syntax element x
is a string of the character a and b.
Repetition
<x >:: =<a>
This gives a definition which means the syntax element x
is a repetition of the character a, It also means that the
character a repeats once or more times.
FPT University 58
BNF
Selection
<x >:: =<a | b>
This gives a definition which means the syntax element x
is either the character a or the character b. If one of the
options is missing, the following expression is used:
<x >:: =[<a>]
This gives a definition which means the syntax element x
is either the character a or the null character (blank). The
symbols [ ] means that it can be omitted.
FPT University 59
BNF
Terminal and Non-Terminal Symbols
A syntax element already defined can be used to define
another element or even itself. These
syntax elements are called non-terminal
symbols. Characters that are used directly in
sentences are called terminal symbols.
In the following definitions, the underlined <x> is a non
terminal symbol whereas a, b, and c are terminal symbols.
<y >:: =<a><x >
<x >:: =<b><c >
FPT University 60
20
FAQ
An example of syntactical rules: often, questions
follow the pattern of selecting the sentence that
satisfies given syntactical rules.
FPT University 61
FPT University 62
FPT University 63
21
Polish Notation
Polish Notation places the operator in front of
the variables. The fundamental concept is the
same as that of Reverse Polish Notation
FPT University 64
FAQ
Conversion into Reverse Polish Notation or into
a
mathematical formula is a very frequent theme
on exams. It is best if you learn how to answer
these questions intuitively.
FPT University 65
Data Structures
Arrays can be used in every data structure.
Arrays are referred to by index.
FPT University 66
22
Array
An array is a data structure consisting of
multiple data of the same type.
FPT University 67
FAQ
There are hardly any questions directly on
arrays
themselves. However, any question on a data
structure or an algorithm always uses an array.
Hence, you must understand arrays properly.
More specifically, be sure that you understand
how to use the index.
Questions on algorithms on the exam may
have indexes starting at 0 or 1, so care must be
taken.
FPT University 68
Lists
Lists are characterized by being connected with
pointers.
Operations for a list are controlled by changing
the values of pointers
A list is a set of identical or similar data placed
logically linearly.
FPT University 69
23
Basic operations of list
Insertion
FPT University 70
Deletion
To delete an element from a given list, just as in
insertion, all we have to do is to change pointers.
FPT University 71
FPT University 72
24
FAQ
Many questions involve insertion into and
deletion from a list. You must carefully consider
which element it is whose pointer should be
stored
FPT University 73
Stacks
Stacks are data structures of LIFO (Last-In First-
Out).
Stacks are used to manage the return addresses
of subroutines
A stack is a data structure in which data
insertion and deletion both take place on the
same end of the list.
FPT University 74
Stack
Pop
Deletion is pop-up.
Push
Insertion is called push-down
The stack pointer (SP) is used to keep track of
where the top of the stack currently is
FPT University 75
25
Uses of the stack
When a main program calls a subprogram
(subroutine) or a function, often the return
address of the program being executed is stored
in a stack; when the subprogram is completed,
the return address of the main program is taken
from the stack to return the control.
FPT University 76
Delete
FPT University 77
FAQ
Many questions involve stacks. The pattern is
that frequently there are questions asking what
happens to the contents of a given stack when
push and pop are repeated.
FPT University 78
26
Queues
Queues are data structures of FIFO (First-In
First-Out).
Queues are used for online transaction
processes.
A queue is a data structure in which insertion
takes place at one end while deletion (taking-
out) occurs at the other end
FPT University 79
FPT University 80
FPT University 81
27
Operations of a queue
Insertion
Deletion
FPT University 82
Tree
Trees clearly indicate a hierarchical structure.
Among the various types of trees, binary trees
are to be thoroughly understood.
A tree is a data structure that expresses the
hierarchical structure between elements
FPT University 83
Tree
FPT University 84
28
Binary Tree
A tree in which each node has no more than two
children is called a binary tree.
Complete binary tree
All leaves are at the same depth, or if the
difference of depth between any two
leaves is 1 or less
The leaves are laid out
from the left
FPT University 85
FPT University 86
Heap
A binary tree where the node values are
assigned from the root level and from left
to right on the same level with the following
conditions:
value of a parent element > value of a child
element (max-heap) OR
value of a parent element < value of a child
element (min-heap)
FPT University 87
29
Q -> FAQ
FPT University 88
Hash
Hash is the concept of using the key values
directly as the index.
Two methods to avoid collisions are
the open-address method
the chain method
Hash is the concept of using key values directly
as the storage locations of data.
FPT University 89
Hash
To convert key values to index numbers, a hash
function is used to calculate hash values, which
are then used as index numbers. The array that
stores elements using such a method is called
a hash table.
FPT University 90
30
Collision
When the same hash value is generated in this
way, it is called a collision.
Resolution is by
Chain Method (Open Hash Method)
Open Address Method (Closed Hash
Method)
FPT University 91
FPT University 92
FPT University 93
31
Q FAQ
->
FPT University 94
Algorithms
Search algorithms
There are two types of search algorithms: linear
search and binary search.
In binary search, the elements are be sorted
in ascending or descending order.
FPT University 95
FAQ
To express algorithms, questions on Morning
Exams use flowcharts, while questions on
Afternoon Exams use pseudo-language. Rules
on
the pseudo-language are not released, so it is a
good idea to look through them in advance.
FPT University 96
32
Linear Search
This is the method of searching for the desired
element in the table from the beginning of the
table in order.
Sentinel search
The same data (sentinel) as the data to
retrieve is placed at the end of a table
Decrease no of comparisons
Simplify the search algorithm
FPT University 97
Linear search
FPT University 98
Binary search
This method narrows down the target data while
successively dividing a search area into two
parts.
Number of comparisons reduced compared with
the linear search method
Elements must be in ascending or descending
order
FPT University 99
33
Binary search
Q ->
Search efficiency
Mean number of comparisons = N /2
for linear search
Maximum number of comparisons = N
for linear search
Mean number of comparisons = [log2N]
for binary search
Maximum number of comparisons = [log2N] + 1
for binary search
Q ->
Search efficiency
Slower Faster
Linear Binary
search Search
Average N/2 [log2N]
comparisons
Max no of N [log2N] + 1
comparisons
34
FAQ
The average number of comparisons and the
maximum number of comparisons in binary
search are frequently asked on exams, so it is a
good idea to have these formulas memorized.
Sorting algorithms
Be careful when manipulating index numbers in
bubble sort, selection sort, and insertion sort.
Recursive call is used in quick sort and merge
sort.
Sorting
Sorting the contents of an area in a program,
such as an array, is called internal sorting
sorting data stored in an external device such as
records in a file is called external sorting
35
Sorting algorithms
Bubble sort
Selection sort
Insertion sort
Quick sort
Merge sort
Shell sort
Heap sort
FAQ
Questions involving internal sorting in the
exams are almost always about array
manipulation. Be careful not to switch the
index numbers when data is switched.
Bubble sort
In bubble sort, each adjacent pair of elements is
sequentially compared and exchanged if
necessary.
One of the simplest sort methods
Efficiency is low since data item are
unconditionally compared even if they are sorted
correctly.
If the volume of data is large, the process is
time-consuming.
36
Bubble sort
Bubble sort
Average and worst times
N2
Selection sort
Selection sort finds the maximum value (or the
minimum value) from the array and exchanges
it with the element at the end of the array.
Next, it finds the maximum (or minimum) value
from the array except for the last element and
exchanges it with the second-to-the-last element
of the array.
37
Selection sort
Selection sort
Average and worst times
N2
FAQ
Bubble sort and selection sort very frequently
appear on the exams.
The questions are given in a variety of ways,
such as on the contents of an array at an
intermediate stage and filling in blanks of a
flowchart. Be sure that you understand the
algorithms well.
38
Insertion sort
Insertion sort starts with an already sorted array,
compares the element to be inserted with the
elements in the array, starting from the back,
and inserts the element in the appropriate
location
Insertion sort
Insertion sort
Average and worst times
N2
39
Quick sort
Quick sort selects a random value from the array
and uses its key value as the pivot;
The elements are divided into two groups: the
first group in which all elements are less than
the pivot and the second group in which all
elements are greater than the pivot (equal
values can go either way).
Quick sort
Quick sort
Average time
N log2 N
Worst time
N2
40
Merge sort
In merge sort, two or more arrays, each of
which is already sorted, are merged together to
form one sorted array. In merge sort, splitting is
repeated until each group has only one element.
Merge sort
Merge sort
Average time and worst time
N log2 N
41
FAQ
Quick sort and merge sort differ from each other
in the number of elements involved in splitting
processes, but they use the same method.
In such cases, a method known as recursive
call is used.
Shell sort
This is an improved form of insertion sort; the
sorting is made faster by increasing the moving
distances of the elements.
First, the elements are sorted roughly by using
insertion sort with gaps of a certain size.
Then, insertion sort is used again to complete
the sorting operation.
Shell sort
42
Shell sort
Average time
N log2 N
Worst time
N2
Heap sort
A heap is a binary tree in which every subtree
has the property that a parent has a value larger
than its children.
If the root element is picked, we can obtain the
maximum value while the remaining elements
can be re-structured to form a heap
Heap sort
A "complete" tree is a minimum height tree with all the
nodes on the lowest level in their left-most positions. That
is, the tree is completely filled from the top with any extra
elements strictly on one side (left) of the lowest level.
43
Heap
Heap sort
unordered array of items into a heap
Bubble N2 N2
Selection N2 N2
Insertion N2 N2
Quick N log2 N N2
Shell N log2 N N2
44
FAQ
For quick sort, merge sort, insertion sort, heap
sort, and shell sort, questions generally deal with
the concept of each, so you should understand
how each sort processes the data.
45
Brute force (nave) method
46
Boyer-Moore Method (BM Method)
If a given letter usually doesnt occur in a
string, only need approx N/M character
comparisons (N=length doc, M=length string).
Graph algorithms
A tree is a type of graph.
The order in which tree search is performed can
be breadth-first or depth-first.
Graph
A graph consists of nodes and edges.
A node is a vertex that forms the graph.
An edge is a segment connecting a point to a
point.
47
Breadth-First Order
The search begins at the root and traverses from
lower levels and from left to right.
Depth-First Order
We start with the root and traverse from the left
child and from leaves.
48
Depth First Search
Search Order in which nodes are traversed
method
Pre-order Parent, left child, right child, in this order
FAQ
Depth-first order frequently appears on the
exams.
Understand well how the nodes are
taken out in pre-order, in-order, and post-order.
FAQ
In string search, there needs to be an index for
the string S and another index for the string R.
When answering a question, the crucial point is
to grasp how to use the indexes.
49
Summary
50