Professional Documents
Culture Documents
Introduction To Algorithm: Unit-1 Basics of Algorithms and
Introduction To Algorithm: Unit-1 Basics of Algorithms and
Introduction To Algorithm: Unit-1 Basics of Algorithms and
GTU # 3150703
✓ Outline
Looping
▪ Introduction to Algorithm
Unit-1 • Definition
Basics of Algorithms and • Characteristics
Mathematics • Types
• Simple Multiplication Methods
▪ Mathematics for Algorithmic Sets
• Set Theory
• Functions and Relations
• Vectors and Matrices
Rupesh Vaishnav
Computer Engineering Department • Linear Inequalities and Linear Equations
Darshan Institute of Engineering & Technology, Rajkot
rupesh.vaishnav@darshan.ac.in
• Logic and Quantifiers
9428037452
What is an Algorithm?
A step-by-step procedure, to solve the different kinds of problems.
Suppose, we want to make a Chocolate Cake.
An unambiguous sequence of computational steps that transform the input into the output.
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 #3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and
Rupesh Vaishnav 5 Rupesh Vaishnav 6
Mathematics Mathematics
1210554 1210554
#3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and #3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and
Rupesh Vaishnav 7 Rupesh Vaishnav 8
Mathematics Mathematics
Simple Multiplication Methods Simple Multiplication Methods
3. à 𝒍𝒂 𝒓𝒖𝒔𝒔𝒆 multiplication 4. Multiplication by divide and conquer
i. Write the multiplicand and multiplier side by side. 981 1234 1234
Both the multiplicand and the multiplier must have the same number of digits and this
ii. Make two columns, one under each operand. 490 2468 number be a power of 2. If not then it can be done by adding zeros on the left if
iii. Repeat step iv and v until the number in the left column is 1.
iv. Divide the number in the left hand column by 2, ignoring any
245 4936 4936 necessary.
Multiplicand 0981
fractions. 122 9872 i. Multiply left half of the multiplicand by left half of multiplier and
v. Double the number in the right hand column by adding it to shift the result by no. of digits of multiplier i.e. 4. Multiplier 1234
61 19744 19744
itself.
vi. Next cross out each row where the number in the left hand 30 39488 ii. Multiply left half of the multiplicand by right half of the multiplier, Multiply Shift Result
column is even. shift the result by half the number of digits of multiplier i.e. 2.
15 78976 78976 (09) * (12) 4 10 8 . . . .
vii. Finally add up the numbers that remain in the right hand
column. iii. Multiply right half of the multiplicand by left half of the multiplier, (09) * (34) 2 3 0 6 . .
7 157952 157952 shift the result by half the number of digits of multiplier i.e. 2.
3 315904 315904 (81) * (12) 2 9 7 2 . .
iv. Multiply right half of the multiplicand by right half of the multiplier
1 631808 631808 the result is not shifted at all. (81) * (34) 0 2 7 5 4
1210554 1210554
#3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and #3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and
Rupesh Vaishnav 9 Rupesh Vaishnav 10
Mathematics Mathematics
Exercises
Multiply following values using divide and conquer method. Multiply Shift Result
1. 4567×6543
2. 31415975×8182818
Example 1 Example 2
Roster Notation Set-builder Notation
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 𝐴.
#3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and #3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and
Rupesh Vaishnav 15 Rupesh Vaishnav 16
Mathematics Mathematics
Set Theory Set Theory
Example 1 Example 2
A
B A=C
#3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and #3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and
Rupesh Vaishnav 17 Rupesh Vaishnav 18
Mathematics Mathematics
𝐴′ = {𝑥 | 𝑥 ∈𝑈 𝑎𝑛𝑑 𝑥∉𝐴}
A’
A •A
•B
U
#3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and #3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and
Rupesh Vaishnav 19 Rupesh Vaishnav 20
Mathematics Mathematics
Set Operations Set Operations
A B A B
#3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and #3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and
Rupesh Vaishnav 21 Rupesh Vaishnav 22
Mathematics Mathematics
A B
#3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and #3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and
Rupesh Vaishnav 23 Rupesh Vaishnav 24
Mathematics Mathematics
Set Operations Relation
#3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and #3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and
Rupesh Vaishnav 25 Rupesh Vaishnav 26
Mathematics Mathematics
Example 1 Example 2
Symmetric Asymmetric
Example 1 Example 2
Reflexive
#3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and #3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and
Rupesh Vaishnav 27 Rupesh Vaishnav 28
Mathematics Mathematics
Properties of the Relation Equivalence Relation
#3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and #3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and
Rupesh Vaishnav 29 Rupesh Vaishnav 30
Mathematics Mathematics
Codomain
Domain
Domain Codomain
#3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and #3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and
Rupesh Vaishnav 31 Rupesh Vaishnav 32
Mathematics Mathematics
Relation & Function Functions Types
Relation 1 Relation 2
Is not a function since elements of Is a function since elements of domain
domain point to multiple elements of point to only one element of codomain. Codomain
codomain.
Ana
Mit
Sam
CX Yug Ana CX
CY Jen Yug CY
CZ Tom Ram CZ
Ram Mit
Neel
1 1
2 4
3 9
4 16
#3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and #3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and
Rupesh Vaishnav 35 Rupesh Vaishnav 36
Mathematics Mathematics
Vectors and Matrices Linear Inequalities
#3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and #3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and
Rupesh Vaishnav 37 Rupesh Vaishnav 38
Mathematics Mathematics
Solution
#3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and #3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and
Rupesh Vaishnav 39 Rupesh Vaishnav 40
Mathematics Mathematics
Logical Connectives Logical Quantifiers
#3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and #3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and
Rupesh Vaishnav 41 Rupesh Vaishnav 42
Mathematics Mathematics
#3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and #3150703 (ADA) ⬥ Unit 1 – Basics of Algorithms and
Rupesh Vaishnav 43 Rupesh Vaishnav 44
Mathematics Mathematics