0% found this document useful (0 votes)
14 views14 pages

Ada Unit 1 Handbook

The document outlines the syllabus for the Analysis and Design of Algorithms course at SAL Engineering & Technical Institute for the academic year 2024-2025. It covers fundamental concepts of algorithms, mathematical sets, functions, relations, vectors, and matrices, detailing properties and operations associated with each topic. The content is structured for 5th semester students in the CE, IT, CSE, and ICT departments.

Uploaded by

Prachi Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views14 pages

Ada Unit 1 Handbook

The document outlines the syllabus for the Analysis and Design of Algorithms course at SAL Engineering & Technical Institute for the academic year 2024-2025. It covers fundamental concepts of algorithms, mathematical sets, functions, relations, vectors, and matrices, detailing properties and operations associated with each topic. The content is structured for 5th semester students in the CE, IT, CSE, and ICT departments.

Uploaded by

Prachi Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

SAL Engineering & Technical Institute

CE, IT, CSE & ICT Department

Analysis and Design of Algorithms (3150703)

Analysis and Design of Algorithms (3150703)


Year: 2024-2025

Prepared By: Prof. Parth Wadhwa, Prof. Ruchit Shah, IT, CE


Dept, SETI
5th Semester CE/IT

Unit-1

Basics of Algorithms and Mathematics

1. Algorithm and Properties of Algorithm

1.1. Algorithm

 An algorithm is any well-defined computational procedure that takes some values or set
of values as input and produces some values or set of values as output.

 An algorithm is a sequence of computational 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 (model


of Computation).

1.2. Properties of Algorithm

 All the algorithms should satisfy following five properties,

1. Input: There is zero or more quantities supplied as input to the algorithm.

2. Output: By using inputs which are externally supplied the algorithm produces at
least one quantity as output.

3. Definiteness: The instructions used in the algorithm specify one or more operations.
These operations must be clear and unambiguous. This implies that each of these
operations must be definite; clearly specifying what is to be done.

4. Finiteness: Algorithm must terminate after some finite number of steps for all cases.

5. Effectiveness: The instructions which are used to accomplish the task must be basic
i.e., the human being can trace the instructions by using paper and pencil in every
way.
2. Mathematics for Algorithmic Set

2.1. Set

 Unordered collection of distinct elements. Can be represented either by property or by


value.

2.2. Set Cardinality

 The number of elements in a set is called cardinality or size of the set, denoted |S| or
sometimes n(S).

 The two sets have same cardinality if their elements can be put into a one-to-one
correspondence. It is easy to see that the cardinality of an empty set is zero i.e., |ø|.

2.3. Multiset

 If we do want to take the number of occurrences of members into account, we call the
group a multiset.

 For example, {7} and {7, 7} are identical as set but {7} and {7, 7} are different as
multiset.

2.4. Infinite Set

 A set contains infinite elements. For example, set of negative integers, set of integers,
etc. …

2.5. Empty Set

 Set contain no member, denoted as { } or ø.

2.6. Subset

 For two sets A and B, we say that A is a subset of B, written A B, if every member of set
A is also a member of set B.
 Formally, A⊆B if x ϵ A implies x ϵ B
2.7. Proper Subset

 Set A is a proper subset of B, written A⊂B, if A is a subset of B and not equal to B. That
is, a set A is proper subset of B if A⊆B but A≠B.
2.8. Equal Sets

 The sets A and B are equal, written A = B, if each is a subset of the other.

 Let A and B be sets. A = B if A⊆B and B⊆A.

2.9. 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: B⊆A}.

 For example, consider A= {0, 1}.

 The power set of A is {{}, {0}, {1}, {0, 1}}.

2.10. Union of sets

 The union of A and B, written A∪B, is the set we get by combining all elements in A and
B into a single set.

 That is A∪B = {x: x ϵ A or x ϵ B}.

2.11. Disjoint sets

 Let A and B be sets. A and B are disjoint if A ∩ B = Φ.


2.12. 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}.

2.13. Difference of Sets

 Let A and B be sets. The difference of A and B is A - B = {x : x ϵ A and x ∉ B}.


 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}.

2.14. Complement of a set

 All set under consideration are subset of some large set U called universal set.
 Given a universal set U, 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}.

2.15. Symmetric difference

 Let A and B be sets. The symmetric difference of A and B is,

A⊕B = {x: x ϵ A or x ϵ B but not in both}


 As an example, consider the following two sets A = {1, 2, 3} and B = {2, 4, 6, 8}. The
symmetric difference, A⊕B = {1, 3, 4, 6, 8}.

2.16. Sequences

 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}.

3. Functions & Relations

3.1. Relation

 Let X and Y be two sets. Any subset ρ of their Cartesian product X x Y is a relation.

 When x Є X and y Є Y, we say that x is in relation with y according to ρ denoted as x ρ y


if and only if (x, y) Є ρ.

 Relationship between two sets of numbers is known as function. Function is special kind
of relation.

 A number in one set is mapped to number in another set by the function.

But note that function maps values to one value only. Two values in one set could map to one
value but one value must never map to two values.

3.2. Function

 Consider any relation f between x and y.


 The relation is called a function if for each x Є X, there exists one and only one y Є Y
such that (x, y) Є f.

 This is denoted as f: x → y, which is read as f is a function from x to y denoted as f(x).

 The set X is called domain of function, set Y is its image and the set f(D)={f(x)|xЄD} is
its range.

 For example, if we write function as follows,

f(x) = x3

 Then we can say that f(x) equals to x cube.

 For following values, it gives result as,

f (-1) = (-1)3 = -1

f (2) = (2)3 = 8

f (3) = (3)3 = 27

f (5) = (5)3 = 125

This function f(x) maps number to their cube.

 In general, we can say that a relation is any subset of the Cartesian product of its domain
and co-domain.

 The function maps only one value from domain to its co domain while relation maps one
value from domain to more than one values of its co domain.

 So that by using this concept we can say all functions are considered as relation also but
not vice versa.

3.3. Properties of the Relation

 Different relations can observe some special properties namely reflexive, symmetric,
transitive and Anti symmetric.

 Reflexive:

 When for all values x: x R x is true then relation R is said to be reflexive.

 E.g., the equality (=) relation is reflexive.


 Symmetric:

 When for all values of x and y, x R y → y R x is true. Then we can say that relation
R is symmetric. Equality (=) relation is also symmetric.
 Transitive:

 When for all values of x, y and z, x R y and y R z then we can say that x R z, which
is known as transitive property of the relation.

 E.g., the relation grater then > is transitive relation.

 If x>y and y>z then we can say that x>z i.e. x is greater than y and y is greater than z
then x is also greater than z.

 Anti-symmetric:

 When for all values of x and y if x R y and y R x implies x=y then relation R is Anti
- symmetric.

 Anti-symmetric property and symmetric properties are lookalike same but they are
different.

 E.g., consider the relation greater than or equal to ≥ if x ≥ y and y ≥ x then we can
say that y = x.
 A relation is Anti-symmetric if and only if x X and (x, x) R.

 Equivalence Relation:

 Equivalence Relation plays an important role in discrete mathematics.

 Equivalent relation declares or shows some kind of equality or say equivalence.

 The relation is equivalent only when it satisfies all following property i.e. relation
must be reflexive, symmetric and transitive then it is called Equivalence Relation.

 E.g., Equality ‘=’ relation is equivalence relation because equality proves above
condition i.e., it is reflexive, symmetric and transitive.

 Reflexive: x=x is true for all values of x. so we can say that’=’ is reflexive.

 Symmetric: x=y and y=x is true for all values of x and y then we can say that
‘=’ is symmetric.
 Transitive: if x=y and y=z is true for all values then we can say that x=z. thus’
=’ is transitive.

4. Vectors and Matrices

 A vector, u, means a list (or n-tuple) of numbers:

 u = (u1, u2, . . . , un)

 Where ui are called the components of u. If all the ui are zero i.e., ui = 0, then u is called
the zero vector.

 Given vectors u and v are equal i.e., u = v, if they have the same number of components
and if corresponding components are equal.

4.1. Addition of Two Vectors

 If two vectors, u and v, have the number of components, their sum, u + v, is the vector
obtained by adding corresponding components from u and v.

 u + v = (u1, u2, . . . , un) + (v1, v2, . . . , vn) = (u1 + v1 + u2 + v2, . . . , un + vn)

4.2. Multiplication of a vector by a Scalar

 The product of a scalar k and a vector u i.e., ku, is the vector obtained by multiplying
each component of u by k:

ku = k(u1, u2, . . . , un) = ku1, ku2, . . . , kun

 It is not difficult to see k (u + v) = ku + kv where k is a scalar and u and v are vectors

4.3. Dot Product and Norm

 The dot product or inner product of vectors u = (u1, u2, . . ., un) and v = (v1, v2, . . ., vn) is
denoted by u.v and defined by

u.v = u1v1 + u2v2 + . . . + unvn

The norm or length of a vector, u, is denoted by ||u|| and defined by

√𝑢. 𝑢
||u|| =
𝑢 + 𝑢 +. . . . . . +𝑢

4.4. Matrices
Matrix, A, means a rectangular array of numbers

 The m horizontal n-tuples are called the rows of A, and the n vertical m-tuples, its
columns. Note that the element aij, called the ij-entry, appear in the ith row and the jth
column.

4.5. Column Vector

 A matrix with only one column is called a column vector.

4.6. Zero Matrix

 A matrix whose entries are all zero is called a zero matrix and denoted by 0.

4.7. Matrix Addition

Let A and B be two matrices of the same size. The sum of A and B is written as A + B and
obtained by adding corresponding elements from A and B.

4.8. Properties of Matrix under Addition and Multiplication

Let A, B, and C is matrices of same size and let k and I two scalars. Then

i. (A + B) + C = A + (B + C)

ii. A+B =B +A

iii. A+0= 0+A= A


iv. A + (-A) = (-A) + A = 0

v. k(A + B) = kA + kB

vi. (k + I)A = kA + I A

vii. (k I)A = k(I A)

viii. IA=A

4.9. Matrix Multiplication

 Suppose A and B are two matrices such that the number of columns of A is equal to
number of rows of B. Say matrix A is an m×p matrix and matrix B is a p×n matrix. Then
the product of A and B is the m×n matrix whose ij-entry is obtained by multiplying the
elements of the ith row of A by the corresponding elements of the j th column of B and
then adding them.

 It is important to note that if the number of columns of A is not equal to the number of
rows of B, then the product AB is not defined.

4.10. Properties of Matrix Multiplication

Let A, B, and C be matrices and let k be a scalar. Then

i. (AB)C = A(BC)

ii. A(B+C) = AB + AC

iii. (B+C) A = BA + CA

iv. k(AB) = (kB)B = A(kB)

4.11. Transpose

 The transpose of a matrix A is obtained by writing the row of A, in order, as columns and
denoted by AT. In other words, if A - (Aij), then B = (bij) is the transpose of A if bij - aji
for all i and j.

 It is not hard to see that if A is an m × n matrix, then AT is an n × m matrix.

For example, if
A= then AT =

4.12. Square Matrix

 If the number of rows and the number of columns of any matrix are same, we say matrix
is a square matrix, i.e., a square matrix has same number of rows and columns. A square
matrix with n rows and n columns is said to be order n and is called an n-square matrix.

 The main diagonal, or simply diagonal, of an n-square matrix A = (aij) consists of the
elements a(11), a(22), a(33) . . . a(mn).

4.13. Unit Matrix

 The n-square matrix with 1's along the main diagonal and 0's elsewhere is called the unit
matrix and usually denoted by I.

 The unit matrix plays the same role in matrix multiplication as the number 1 does in the
usual multiplication of numbers.

A I = I A = A for any square matrix A.

5. Linear Inequalities and Linear Equations.

5.1. Inequalities

The term inequality is applied to any statement involving one of the symbols <, >, ≤, ≥.

Examples of inequalities are:

i. x≥1

ii. x + y + 2z > 16

iii. p2 + q2 ≤1/2

iv. a2 + ab > 1

5.2. Fundamental Properties of Inequalities

1. If a ≤ b and c is any real number, then a + c ≤ b + c.

For example, -3≤-1 implies -3+4≤-1 + 4.


2. If a ≤ b and c is positive, then ac ≤ bc.

For example, 2≤3 implies 2(4) ≤3(4).

3. If a ≤ b and c is negative, then ac ≥ bc.

For example, 3≤9 implies 3(-2) ≥9(-2).

4. If a ≤ b and b ≤ c, then a ≤ c.

For example, -1/2 ≤ 2 and 2 ≤ 8/3 imply -1/2 ≤ 8/3.

5.3. Solution of Inequality

 By solution of the one variable inequality 2x + 3 ≤ 7 we mean any number which


substituted for x yields a true statement.

 For example, 1 is a solution of 2x + 3 ≤ 7 since 2(1) + 3 = 5 and 5 is less than and equal
to 7.

 By a solution of the two variable inequality x – y ≤ 5 we mean any ordered pair of


numbers which when substituted for x and y, respectively, yields a true statement.

 For example, (2, 1) is a solution of x – y ≤ 5 because 2-1 = 1 and 1 ≤ 5.

 By a solution of the three variable inequalities 2x - y + z ≥ 3 we mean an ordered triple


of number which when substituted for x, y and z respectively, yields a true statement.

 For example, (2, 0, 1) is a solution of 2x - y + z ≤ 3.

 A solution of an inequality is said to satisfy the inequality. For example, (2, 1) is satisfy x
– y ≤ 5.

5.4. Linear Equations

 One Unknown

A linear equation in one unknown can always be stated into the standard form

ax = b

Where x is an unknown and a and b are constants. If a is not equal to zero, this
equation has a unique solution

x = b/a
 Two Unknowns

A linear equation in two unknown, x and y, can be put into the form

ax + by = c

Where x and y are two unknowns and a, b, c are real numbers. Also, we assume that a
and b are no zero.

5.5. Solution of Linear Equation

 A solution of the equation consists of a pair of number, u = (k1, k2), which satisfies the
equation ax + by = c.

 Mathematically speaking, a solution consists of u = (k1, k2) such that ak1 + bk2 = c.

 Solution of the equation can be found by assigning arbitrary values to x and solving for y
or assigning arbitrary values to y and solving for x.

5.6. Two Equations in the Two Unknowns

 A system of two linear equations in the two unknowns x and y is

 a1 x + b1 x = c 1

 a2 x + b2 x = c 2

 Where a1, a2, b1, b2 are not zero. A pair of numbers which satisfies both equations is
called a simultaneous solution of the given equations or a solution of the system of
equations.

 Geometrically, there are three cases of a simultaneous solution

1. If the system has exactly one solution, the graph of the linear equations intersects in
one point.

2. If the system has no solutions, the graphs of the linear equations are parallel.

3. If the system has an infinite number of solutions, the graphs of the linear equations
coincide.

 The special cases (2) and (3) can only occur when the coefficient of x and y in the two
linear equations are proportional.
OR => a1b2 - a2b1 = 0 => =0

The system has no solution when

 The solution to the following system can be obtained by the elimination process,
whereby reduce the system to a single equation in only one unknown.

a1x + b1x = c1

a2x + b2x = c2

You might also like