Unit-1: Basics of Algorithms: and Mathematics
Unit-1: Basics of Algorithms: and Mathematics
Unit-1: Basics of Algorithms: and Mathematics
GTU # 3150703
Unit-1:
Basics of Algorithms
and Mathematics
Input
An algorithm is any well-defined computational procedure that takes some value, or a set of
values as input and produces some value, or a set of values as output.
#3150703 (ADA) Unit 1 – Basics of Algorithms and
Dr. Gopi Sanghani 5
Characteristics of An Algorithm
Finiteness: An algorithm must always terminate after a finite number of steps.
Definiteness: Each step of an algorithm must be precisely defined.
Input: An algorithm has zero or more inputs.
Output: An algorithm must have at least one desirable output.
Effectiveness: All the operations to be performed in the algorithm must be sufficiently basic so
that they can, in principle be done exactly and in a finite length of time.
981 981
1 23 4 1 23 4
3924 981
2943 1962
1962 2943
981 3924
1210554 1210554
1210554
#3150703 (ADA) Unit 1 – Basics of Algorithms and
Dr. Gopi Sanghani 9
Simple Multiplication Methods
4. Multiplication by divide and conquer
Both the multiplicand and the multiplier must have the same number of digits and this
number be a power of 2. If not then it can be done by adding zeros on the left if
necessary.
Multiplicand 0981
i. Multiply left half of the multiplicand by left half of multiplier and shift the
result by no. of digits of multiplier i.e. 4. Multiplier 1234
ii. Multiply left half of the multiplicand by right half of the multiplier, shift the Multiply Shift Result
result by half the number of digits of multiplier i.e. 2.
(09) * (12) 4 10 8 . . . .
iii. Multiply right half of the multiplicand by left half of the multiplier, shift the (09) * (34) 2 3 0 6 . .
result by half the number of digits of multiplier i.e. 2.
(81) * (12) 2 9 7 2 . .
iv. Multiply right half of the multiplicand by right half of the multiplier the result (81) * (34) 0 2 7 5 4
is not shifted at all.
1210554
#3150703 (ADA) Unit 1 – Basics of Algorithms and
Dr. Gopi Sanghani 10
Mathematics for Algorithmic Sets
Set Theory
A set is an unordered collection of distinct objects.
The objects in a set are called elements or members of the set.
Example 1 Example 2
Subset: For two sets 𝐴 and 𝐶, we say that 𝐶 is a subset of 𝐴, written as 𝐶⊆𝐴, if each member of
set 𝐶 is also a member of set 𝐴.
Example 1 Example 2
If and If
and
Then set is a proper subset of . Then set C is a subset of , but it is not a
proper subset of since .
A
A=C
𝑩 ⊂ 𝑨 ⊆𝑨
𝑪
Cardinality of set: The cardinality of a set denotes the number of elements in a set. The
cardinality of a set is denoted by or .
Examples:
1. If is a set of English alphabets the
2. The cardinality of infinite set denoted as
3. The empty set denoted as is the unique set whose cardinality is .
𝐴′ = {𝑥 | 𝑥 ∈𝑈 𝑎𝑛𝑑 𝑥∉𝐴}
Example:
Consider and
Then
A’
A
U
#3150703 (ADA) Unit 1 – Basics of Algorithms and
Dr. Gopi Sanghani 16
Set Operations
Union: The union of two different sets and is the set of all distinct elements of sets and .
𝑨∪𝑩={𝒙∨𝒙∈ 𝑨 𝒐𝒓 𝒙∈𝑩}
Example:
Consider and
Then
A B
Example:
Consider and
Then
A B
Example:
Consider and
Then
A B
𝑨⊖ 𝑩=( 𝑨−𝑩)∪(𝑩− 𝑨)
Example:
Consider, and
Then
A B
Example:
(1, 𝑥)
(1, 𝑦)
, 𝑥)
(2
(2, 𝑦)
, 𝑥)
(3
(3, 𝑦)
𝐴×𝐵
#3150703 (ADA) Unit 1 – Basics of Algorithms and
Dr. Gopi Sanghani 22
Relation
Let and be two sets. Any subset of their Cartesian product is a relation.
A relation defines the relationship between values of sets.
It is defined between the x-values and y-values of the ordered pairs.
The set of all x-values is called the domain, and the set of all y-values is called the range.
∀ 𝒙:[(𝒙∈ 𝑨)→((𝒙,𝒙)∈𝑹)]
Example 1 Example 2
and and
so,
Symmetric Asymmetric
Example 1 Example 2
and and
So,
∀ 𝒙: ∀ 𝒚: ∀ 𝒛 ¿
Transitive Not Transitive
Example 1 Example 2
and and
So,
So,
Codomain
Example:
2
Domain 1 3
4
2 5
6
3
7
4 8
9
10
The Range of the function
Domain Codomain
- 𝟏
𝟏 𝟒
𝟐
𝟗
Range of function 𝟑
𝟒 𝟏𝟔
𝟏 𝟐
𝟐 𝟑
𝟑 𝟒
𝟒 𝟓
𝑨 𝑩
3
𝑨 𝐁
4
5 1 2
6 2 3
3 4
4 5
5 6
𝒃
𝒂𝒙= 𝒃 Solution 𝒙=
𝒂
The solution of above can be obtained by the elimination process, whereby reduce the system to a single
equation in only one unknown.
In order to prove that a universal quantification is false, it must be shown to be false for only
ONE case.
In order to prove that a universal quantification is true, it must be shown true for ALL cases.