×
Push yourself because, no one else is going to do it for you.

# Note for Algorithms - ALG By Nirmal Patel

• Algorithms - ALG
• Note
• 11 Topics
• 2540 Views
Nirmal Patel
0 User(s)

#### Text from page-1

Unit-1 –Basics of Algorithms and Mathematics (1) Algorithm and Properties of Algorithm 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). 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 Set Unordered collection of distinct elements. Can be represented either by property or by value. 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., | ø |. 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. Infinite Set A set contains infinite elements. For example, set of negative integers, set of integers, etc … Empty Set Set contain no member, denoted as { } or ø. Prof. Rupesh G. Vaishnav, CE Department | 2150703 – Analysis and Design of Algorithms 1

#### Text from page-2

Unit-1 –Basics of Algorithms and Mathematics 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 Proper Subset Set A is a proper subset of B, written A proper subset of B if A B, if A is a subset of B and not equal to B. That is, a set A is B but A B. 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. Power Set  Let A be the set. The power of A, written P(A) or 2 A, 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}}. Union of sets  The union of A and B, written A single set.  That is, A B, is the set we get by combining all elements in A and B into a B = {x: x ϵ A or x ϵ B}. Disjoint sets  Let A and B be sets. A and B are disjoint if A ∩ 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}. Difference of Sets  Let A and B be sets. The difference of A and B is A - B = {x : x ϵ A and x  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}. B}. 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}. Prof. Rupesh G. Vaishnav, CE Department | 2150703 – Analysis and Design of Algorithms 2

#### Text from page-3

Unit-1 –Basics of Algorithms and Mathematics 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}. 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 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. 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 ( ) = * ( ) | + is its range. For example, if we write function as follows, ( )   Then we can say that ( ) equals to cube. For following values it gives result as, ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) This function ( ) 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. Prof. Rupesh G. Vaishnav, CE Department | 2150703 – Analysis and Design of Algorithms 3

#### Text from page-4

Unit-1 –Basics of Algorithms and Mathematics  So that by using this concept we can say all functions are considered as relation also but not vice versa. Properties of the Relation  Different relations can observe some special properties namely reflexive, symmetric , transitive and Anti symmetric. Reflexive:   When for all values 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, Equality (=) relation is also symmetric. is true. Then we can say that relation R is 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. o Reflexive: x=x is true for all values of x. so we can say that ’=’ is reflexive. o Symmetric: x=y and y=x is true for all values of x and y then we can say that ‘=’ is symmetric. o Transitive: if x=y and y=z is true for all values then we can say that x=z. thus’ =’ is transitive. Prof. Rupesh G. Vaishnav, CE Department | 2150703 – Analysis and Design of Algorithms 4