classical encryption techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · an...

34
Chapter 1:- Basics of an Algorithm and Mathematics Compiled By:- Sanjay Patel Assistant Professor, SVBIT.

Upload: others

Post on 11-Jul-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

Chapter 1:-

Basics of an Algorithm and

Mathematics

Compiled By:- Sanjay Patel

Assistant Professor,

SVBIT.

Page 2: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

Outline

What is an algorithm?

Mathematics for Algorithmic Sets

Functions and Relations

Vectors and Matrices

Linear Inequalities and Linear Equations.

Sanjay Patel

Page 3: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

An algorithm is a set of rules for carrying out calculation either

by hand or on a machine.

An algorithm is a finite step-by-step procedure to achieve a

required result.

An algorithm is a sequence of computational steps that

transform the input into the output.

An algorithm is a sequence of operations performed on data

that have to be organized in data structures.

An algorithm is an abstraction of a program to be executed on

a physical machine (model of Computation).

What is an algorithm?

Sanjay Patel

Page 4: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

Non-ambiguity:- Each instruction should be clear

and precise.

Range of input:- Range should be specified.

Multiplicity:- sequence of instruction (sequential

search method)

Speed:- should be efficient and produce fast speed.

Finiteness:- performing required operation.

Properties of Algorithm

Sanjay Patel

Page 5: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

Brute force:- Straightforward technique

Divide-and-conquer:- The problem is divided into

smaller instances

Dynamic programming:-The result of smaller,

reoccurring instances are obtained to solve the problem

Greedy technique:- Optimal solution

Back tracking:- This method is based on the trial and

error. If we want to solve the problem then desired

solution is choosen from the finite set S.

Algorithm Design techniques

Sanjay Patel

Page 6: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

Time complexity

Space complexity

Simplicity

Generality

Range of inputs

Analysis of Algorithm

Sanjay Patel

Page 7: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

1. Multiplication, the American way:

Multiply the multiplicand one after another by

each digit of the multiplier taken from right to left.

The Classic Multiplication Algorithm

Sanjay Patel

Page 8: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

2. Multiplication, the English way:

Multiply the multiplicand one after another by each

digit of the multiplier taken from left to right.

Cont’d…

Sanjay Patel

Page 9: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

Algorithmic is a branch of computer science that

consists of designing and analyzing computer

algorithms

1. The “design” pertain to

i. The description of algorithm at an abstract level

by means of a pseudo language, and

ii. Proof of correctness that is, the algorithm solves

the given problem in all cases.

2. The “analysis” deals with performance evaluation

(complexity analysis).

Cont’d…

Sanjay Patel

Page 10: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

Two important ways to characterize the effectiveness

of an algorithm are its space complexity and time

complexity.

Time complexity of an algorithm concerns determining

an expression of the number of steps needed as a

function of the problem size.

Asymptotic analysis makes use of the

O (Big Oh) notation. (Worst-Case)

Θ (Big Theta) notation and (Average Case)

Ω (Big Omega) notation. (Best Case)

Algorithm's Performance

Sanjay Patel

Page 11: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

A set is a collection of different things

(distinguishable objects or distinct objects)

represented as a unit. The objects in a set are

called its elements or members. If an object x is a

member of a set S, we write x є S.

On the the hand, if x is not a member of S, we write

xS.

Mathematics for Algorithmic (Sets)

Sanjay Patel

Page 12: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

Function can be defined as the relationship between

two sets. That means using function we can may one

element of one set to some other element of

another set.

A function is an relation but relation is not

necessarily a function.

f(x) = x3

F(2) = 8

F(5) = 125

Functions & Relations

Sanjay Patel

Page 13: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

If D is a set then we can define function as,

f(D) = { f(x) | x € D }

if we map some element to some other element then it can be denoted as.

f: D —> R i.e. X —> x3

if set D consists of all the real number then

D= {1,2,……….} is domain.

example :- D={1,2,3,4} and f(x)= x3

Then the range of f will be R={f(1),f(2),f(3),f(4)}= (1,8,27,64)

If we take Cartesian product of D and R then we obtain.

F= {(1,1),(2,8),(3,27),(4,64)}

Basic terminologies of function

Sanjay Patel

Page 14: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

Example: The domain and range of a relation.

Relation {(2,9),(3,14),(4,21)}

In the relation above the domain is { 2,3,4 }

And the range is { 9,14,21} .

Function F(x)=x2 +5.

Cont’d…

Sanjay Patel

Page 15: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

Relationship is major aspect between two objects,

even this is true in our real life.

A relation is any association between elements of

one set, called the domain or (less formally) the set

of inputs, and another set, called the range or set of

outputs.

Relation

Sanjay Patel

Page 16: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

Reflexive:- a R a

Irreflexive:- a R b

Symmetric :- a R b implies b R a

Asymmetric:- a R b and b R a implies that a=b

Transitive :- a R b and b R c implies a R c

Properties of Relation

Sanjay Patel

Page 17: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

Given the above information, determine which relations are reflexive, transitive,

symmetric, or antisymmetric on the following - there may be more than one

characteristic. (Answers follow.) x R y if

1. x = y

2. x < y

3. x2 = y2

4. x ≤ y

Answers

1. Symmetric, Reflexive and Antisymmetric

2. Transitive

3. Symmetric, Reflexive, Transitive and Antisymmetric (x2 = y2 is just a special case of

equality, so all properties that apply to x = y also apply to this case)

4. Reflexive, Transitive and Antisymmetric

Problem Set

Sanjay Patel

Page 18: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

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

Vectors and Matrices

Sanjay Patel

Page 19: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

Cont’d…

Sanjay Patel

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)

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

Here, we define -u = (-1)u and u-v = u +(-v)

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

vectors

Page 20: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

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

Cont’d…

Sanjay Patel

Page 21: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

Let A, B, and C be matrices of same size and let k and l be

scalars. Then

(A + B) + C = A + (B + C)

A + B = B + A

A + 0 = 0 + A = A

A + (-A) = (-A) + A = 0

k(A + B) = kA + kB

(k + l)A = kA + lA

(kl)A = k(lA)

lA = A

Properties of Matrix under Addition and

Multiplication

Sanjay Patel

Page 22: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

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

Then

(AB)C = A(BC)

A(B+C) = AB + AC

(B+C)A = BA + CA

k(AB) = (kA)B = A(kB)

Properties of Matrix Multiplication

Sanjay Patel

Page 23: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

The term inequality is applied to any statement

involving one of the symbols <, >, ≤ , ≥ .

Example of inequalities are:

i. x ≥1

ii. x + y + 2z > 16

iii. p2 + q2 ≤ 1/2

iv. a2 + ab > 1

Linear Inequalities and Linear Equations

Sanjay Patel

Page 24: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

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.

Fundamental Properties of Inequalities

Sanjay Patel

Page 25: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

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 inequality 2x - y + z ≥ 3 we

means 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.

Solution of Inequality

Sanjay Patel

Page 26: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

An inequality in two variable x and y describes a region in

the x-y plane (called its graph), namely, the set of all points

whose coordinates satisfy the inequality.

The y-axis divide, the xy-plane into two regions, called half-

planes.

Right half-plane The region of points whose coordinates satisfy

inequality x > 0.

Left half-plane The region of points whose coordinates satisfy

inequality x < 0.

Similarly, the x-axis divides the xy-plane into two half-planes.

Upper half-plane In which inequality y > 0 is true.

Lower half-plane In which inequality y < 0 is true.

Geometric Interpretation of Inequalities

Sanjay Patel

Page 27: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

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.

Linear Equations

Sanjay Patel

Page 28: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

3x + 2y = 8 ------------ (1)

2x - 5y = -1 ------------ (2)

Two Equations in the Two Unknowns

Sanjay Patel

Page 29: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

x - 3y - 2z = 6 --- (1)

2x - 4y + 2z = 18 --- (2)

-3x + 8y + 9z = -9 --- (3)

x = 1, y = -3, z = 2

Three Equations in the three Unknowns

Sanjay Patel

Page 30: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

Gaussian elimination is a method of solving a linear

system ax=b (consisting of equations in unknowns)

by bringing the augmented matrix, to an upper

triangular form and then obtaining a solution by

backward substitution method.

Gauss Elimination

Sanjay Patel

Page 31: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

Solve the linear system by Gauss

elimination method.

Sanjay Patel

Page 32: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

Sanjay Patel

Page 33: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

Sanjay Patel

Page 34: Classical Encryption Techniquessvbitce2010.weebly.com/uploads/8/4/4/5/8445046/ch01.pdf · An algorithm is a set of rules for carrying out calculation either by hand or on a machine

Solve the linear system by Gauss

elimination method.

Sanjay Patel

http://nptel.iitm.ac.in/courses/Webcourse-contents/IIT-KANPUR/mathematics-

2/node18.html