0% found this document useful (0 votes)
5 views

Basics of Algorithms and Mathematics

Uploaded by

smtptesting021
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Basics of Algorithms and Mathematics

Uploaded by

smtptesting021
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Basics of Algorithms and

Mathematics

Prof. Sushma Prajapati


CO Dept
CKPCET
Surat
Email:[email protected]
Outline
● What is an algorithm?
● Mathematics of Algorithmic Sets
● Functions & Relations
● Vector
● Matrices
● Linear Inequalities
● Linear Equations
What is an algorithm?

● An Algorithm is the finite unambiguous sequence of computation steps that


transform the input into the output.
● An algorithm is a set of rules for carrying out calculation either by hand or on a
machine.
● An algorithm is an abstraction of a program to be executed on a physical machine.
Properties of Algorithm
● Input:
○ There is zero or more quantities supplied as input to the algorithm.
● Output:
○ Output is produced using several externally supplied inputs.
● Definiteness:
○ Each operation specified must be clear & definite.
● Finiteness
○ Algorithm must terminate after some finite number of steps for all cases.
● Effectiveness:
○ The instructions which are used to accomplish the task must be basic i.e. traceable.
Mathematics for Algorithmic Sets
● Set:
○ Unordered collection of distinct elements can be represented either by property or by value.
○ All the elements are enclosed within ‘{‘ and ‘}’ and every element is separated by comma .
Set Representation
● Denoted by capital letter.
● Can be represented using 3 methods :

● Listing method :
○ The elements are listed in a set .
○ Eg. Set of elements greater than 5 & less than 10.
○ A = { 6,7,8,9}
Set Representation(Contd…)
● Describing method:
○ This method defines the properties of the set.
○ Eg. Set of shapes.
○ A = { circle , square, rectangle, triangle , polygon}
● Recursion method:
○ The recursion occurs to define the elements of the set.
○ Eg. Set of squares of a no. Less than 5.
○ A = {x | x is a square of n } where n<5
○ A = { 0,1,4,9,16 }
Types of set
● Subset
○ If all the elements of a set A are contained in a set B, that is, if x ϵ A implies x ϵ B, then we write A ⊆ B
and say that A is a subset of B.
○ The empty set is a subset of every set and every set is a subset of itself: Φ ⊆ A, A ⊆ A
● Equal set:
○ Two sets A and B are equal, written A = B, if they contain the same elements. For example,
{1,2,3}={3,2,1}={2,1,3}.
● Power set:
○ Let A be the set. The power of A, written P(A) or 2A, is the set of all subsets of A. That is, P (A) = {B: BA}.
○ For example, consider A= {0, 1}.
○ The power set of A is {{}, {0}, {1}, {0, 1}}.
Operations in Sets
● Union of sets:
○ The union of A and B, written , is the set we get by combining all elements in A and B into a single
set. That is, = {x: x ε A or x ε B}.

● Intersection sets :
○ The intersection of set A and B, written A ∩ B, is the set of elements that are both in A and in B. That
is, A ∩ B = { x : x ε A and x ε B}.
Operations in Sets(Contd…)
● Difference of Sets:
○ Let A and B be sets. The difference of A and B is A - B = {x : x A and }.
○ For example, let A = {1, 2, 3} and B = {2, 4, 6, 8}.
○ The set difference A - B = {1, 3} while B-A = {4, 6, 8}.

● Complement of a set :
○ The complement of A, written A', is the set of all elements under consideration that are not in A.
Formally, let A be a subset of universal set U.
○ The complement of A in U is A' = A - U OR A' = {x: x ε U and x A}.
Cardinality of Sets
● The number of elements in a set is called cardinality or size of the set, denoted |S|
or sometimes n(S).
● Different cardinalities of set can be as follows:
○ One-to-One
○ One-to-Many
○ Many-to-One
○ Many-to-Many
● It is easy to see that the cardinality of an empty set is zero i.e., | ø |.
Sequence
● A sequence of objects is a list of objects in some order.

● For example, the sequence 7, 21, 57 would be written as (7, 21, 57). In a set the
order does not matter but in a sequence it does.

● Repetition is not permitted in a set but repetition is permitted in a sequence. So, (7,
7, 21, 57) is different from {7, 21, 57}.
RELATIONS
● A binary relation R on two sets A and B is a subset of the Cartesian product AXB.
● When we say that R is a binary relation on a set A, we mean that R is a subset of
AXA.
● For example:
● the “less than” relation on the natural numbers is the set

{(a, b) : a, b ϵ N and a < b}.


Types Of Relations
● Reflexive: “x related to x”, that is, the relation R on the set S is reflexive is for all
x ∈ S, (x, x) ∈ R.
● Symmetric: “x related to y implies y related to x”, that is, the relation R on the set S
is symmetric is for all x, y ∈ S, (x, y) ∈ R implies (y, x) ∈ R.
● Transitive: “x related to y and y related to z implies x is related to z”, that is, the
relation R on the set S is symmetric is for all x, y, z ∈ S, (x, y) ∈ R and (y, z) ∈ R
implies (x, z) ∈ R
● Equivalence: A relation that is reflexive, symmetric, and transitive is an
equivalence relation.
● Antisymmetric: A binary relation R on a set A is antisymmetric if

a R b and b R a imply a = b :
FUNCTIONS
● Given two sets A and B, a function f is a binary relation on A and B such that for all a
ϵ A, there exists precisely one b ϵ B such that (a , b) ϵ f.
● The set A is called the domain of f , and the set B is called the codomain of f .
● We sometimes write f : A B; and if (a, b) ϵ f , we write b = f(a), since b is uniquely
determined by the choice of a.
● Example:
○ f(x) = 3x
○ f(2) = 6
○ f(9) = 27

You might also like