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

Discrete Maths Assignment

Uploaded by

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

Discrete Maths Assignment

Uploaded by

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

Induction, Recursion and Algorithms

An Insight into concepts….

DECEMBER 6, 2022
By rohan (CO21351)
3rd semester, CSE
Table of Contents
Mathematical Induction 2
History 2
Types of Induction 3
Motivation 4
Examples 5

Algorithms 8
Introduction 8
Properties of an algorithm 8
Complexity of an algorithm 9
A few more examples on algorithms 11

Recursion 16
Introduction 16
Recurrence Relations 16
Non-Homogeneous Equations 18

1
CHAPTER -1: MATHEMATICAL INDUCTION
. Mathematical induction is a method of proof in which a statement is proven to be
true for a base case, and then it is proven that if the statement is true for a particular
case, it must also be true for the next case. This process is repeated until the statement
has been proven to be true for all
cases.
Mathematical induction is often
used to prove statements that
involve an infinite number of
cases, or statements that involve
a variable that can take on an
infinite number of values. For
example, it can be used to prove
that a formula is true for all
positive integers, or to prove that a given property holds for all elements in a set.
To prove a statement using mathematical induction, we must follow a specific set of
steps:
 Show that the statement is true for the base case. This is the starting point for
the induction, and it is usually the smallest or simplest possible case.
 Assume that the statement is true for a particular case, and use this assumption
to prove that it is also true for the next case. This step is known as the induction
step.
 Assume that the statement is true for a particular case, and use this assumption
to prove that it is also true for the next case. This step is known as the induction
step.
By following these steps, we can use mathematical induction to prove the
statements.

1.1. HISTORY
The concept of mathematical induction has a long history dating back to
ancient Greece. The Greek mathematician Euclid is credited with introducing
the idea of proving statements by induction in his work "Elements," which was
written around 300 BCE.
In "Elements," Euclid used induction to prove a number of geometric theorems,
including the famous theorem that there are an infinite number of prime
numbers. Euclid's method of induction involved showing that a statement was
true for a particular case, and then using this to prove that it was also true for
the next case. Over the centuries, the concept of induction was further
developed and refined by a number of mathematicians, including Archimedes,

2
who used induction to prove a number of mathematical results in his work "The
Sand Reckoner."
In the 19th century, the mathematician Augustin-Louis Cauchy formalized the
concept of mathematical induction in a way that is similar to the way it is used
today. Cauchy defined induction as a method of proof in which a statement is
proven to be true for a base case, and then it is proven that if the statement is
true for a particular case, it must also be true for the next case. This process is
repeated until the statement has been proven to be true for all cases.
Today, mathematical induction is an important tool in mathematics, and it is
used to prove a wide variety of mathematical statements, including formulas,
theorems, and properties of sets and functions. It is a key concept in many areas
of mathematics, including algebra, analysis, and combinatorics.

1.2. TYPES OF MATHEMATICAL INDUCTION


Mathematical Induction is broadly classified into 2 types: Strong and Weak
Induction.

The method discussed above, forms the basis of the weak induction. For
example, consider this below example: where we have to proof the statement.

The statement for Sum of consecutive natural numbers:


The method can be used to prove the statement P(n) for all natural numbers.
P(n): 1+2+3+4+………..+n= n(n+1)/2
Step 1: (the Base step)
Since natural numbers start from 1. Therefore, we will check X(n) for n=1.
LHS: 1
RHS: 1*(1+1)/2 = 1*(2)/2
=1
Since LHS = RHS, therefore, step-1 is true. Now that step 1 holds, we’ll move
to the next step.

Step 2: (the generalised assumption)


Let us assume that P(n) is true for some integer=k, i.e., X(k) is true.
P(k): 1+2+3+4+………..+ k= k(k+1)/2  (1)
Now, we have to show that P(k+1) is true as well.
Step 3:

3
To prove: - X(k+1): 1+2+3+4+………..+ k + (k+1) = (k+2)(k+1)/2
Proof: -
LHS: P(k+1): 1+2+3+4+………..+ k + (k+1)
using (1), the above statement changes to k(k+1)/2 + (k+1)
P(k+1): (k+1) {1+ k/2}
= (k+1) {2+k}/2
= (k+1) (k+2) /2
= RHS
Therefore, LHS=RHS. Hence, by PMI, we have proved that the statement X(n)
is valid for all n∊N.

Strong Induction: Strong induction is a method of proof in mathematics that is


similar to mathematical induction, but it involves proving a statement for all
integers rather than just for positive integers.

To prove a statement using strong induction, we must first show that the
statement is true for the base case n=0. Then, we must assume that the
statement is true for all integers up to a particular value of n, say n=k. Using
this assumption, we must then prove that the statement is also true for the next
integer, n=k+1.
Other types of methods of proof under induction are:

Here, we will discuss only about the first principle to prove P(n).

1.3. MOTIVATION
The motivation behind this principle is to provide a way to prove statements
that involve an infinite number of cases, or statements that involve a variable
that can take on an infinite number of values. By using mathematical induction,
it is possible to prove these types of statements in a logical and systematic way.

For example, suppose we want to prove that the sum of the first n positive
integers is equal to n(n+1)/2 for all positive integers n. We can use
mathematical induction to prove this statement as follows:

4
 Show that the statement is true for the base case n=1. In this case, the sum
of the first n positive integers is 1, which is equal to 1(1+1)/2.
 Assume that the statement is true for a particular value of n, say n=k. This
means that the sum of the first k positive integers is equal to k(k+1)/2.
 Use the assumption that the statement is true for n=k to prove that it is also
true for n=k+1. In this case, the sum of the first k+1 positive integers is
equal to the sum of the first k positive integers plus the next integer, which
is k+1. Using the assumption that the statement is true for n=k, we can
write this as (k(k+1)/2) + (k+1) = (k+1)(k+2)/2.
 Repeat this process until the statement has been proven to be true for all
positive integers n.
By following this process, we can prove that the sum of the first n positive
integers is equal to n(n+1)/2 for all positive integers n, using mathematical
induction.
1.4. EXAMPLES TO UNDERSTAND THE PRINCIPLE BETTER
Consider these examples:

2 2 2 2 n ( n+1 )( 2 n+1 )
Example 1: For all n≥1, prove that 1 +2 +3 +… …+n = .
6
Solution: Let the given statement be P(n), i.e.,
2 2 2 2 n ( n+1 )( 2 n+1 )
P(n): 1 +2 +3 +… …+n =
6
For n=1: - P(1): - LHS: 12 = 1
RHS: 1(1+1)[2(1)+1]/6
= 1(2)(3)/6
=1
Since LHS=RHS, we’ve proven the statement P(1) to be true and now we’ll
proceed to step 2.

Let us say that the statement P(n) is true for some integer=k.
2 2 2 2 k ( k +1 ) ( 2 k +1 )
P(k): 1 +2 +3 +… …+ k = is true.
6

Now we have to prove that P(k+1) is true as well, using the above statement
P(k), i.e.,
2 (k +1) ( k + 2 )( 2 k +3 )
P(k+1): 12 +22 +32 +… …+ k 2+ ( k +1 ) =
6
Proof:
LHS: - 12 +22 +32 +… …+ k 2+ ( k +1 )2
Using the statement P(k), our LHS becomes

5
And RHS:

Since LHS= RHS, therefore, using the principle of mathematical induction,


2 2 2 2 n ( n+1 )( 2 n+1 )
we have proved that the statement P(n): 1 +2 +3 +… …+n =
6
holds for all n≥ 1.

Example 2: Prove that 2n >n for all positive integers n.


Solution: When n=1: 21 >1holds. Therefore, P(1) is true.
Now, let us consider that P(n) is true for some positive integer=k as well, i.e.,
P(k): 2k > k is true as well. ……………... (1)
Now all we have to do is to prove that P(k+1) is true using the above results.
P(k+1): 2k +1> k +1 is true.
LHS: - Multiply both the sides of (1) by 2. We’ll get:

Therefore, 2k +1> k +1 is true, whenever P(k+1) is true. Hence, by the principle of


mathematical induction, we have proved that P(k+1) is true, whenever P(k) is
true.

Example 3: Derive the following rule : ( ab )n=a n b n by using PMI for every n ∊
N.
Solution: Let P(n) be the given statement i.e. P(n) : ( ab )n=a n b n
We note that P(n) is true for n = 1
since( ab )1=a1 b1.

6
As a result, anytime P(k) is true, P(k + 1) is also true. Therefore, P(n) is true for
every n∈N as per the concept of induction.

7
CHAPTER-2: ALGORITHMS
1.1. INTRODUCTION
Let us consider the following situation:
You have to get some fruits from the market. So what are the steps in sequence
that one has to follow to get this done??
1. Get out of the house and look for a transport option.
2. Follow the route to the market.
3. Buy the desired fruits from the fruit shop.
4. Take the fruits and follow the same route to come back home.
Now consider this as a task, and one has to complete it within a finite number
of steps such that the task is completed efficiently. Those steps are called the
algorithm for that particular task. Therefore, we are in a state to define what an
algorithm is!!
“An algorithm is a set of steps or instructions that are followed in a specific
order to solve a problem or accomplish a task.”

Examples of algorithms include:


 A sorting algorithm, which is used to rearrange a list of items in a
specific order (such as alphabetical or numerical order),
 A search algorithm, which is used to find a specific item in a list or
database,
 A compression algorithm, which is used to reduce the size of a file or
data set,
 An encryption algorithm, which is used to secure data by encoding it in
a way that can only be decrypted with a special key.

1.2. PROPERTIES OF AN ALGORITHM:

 Precision: An algorithm must be precise and specific in its instructions, so that


it can be followed accurately and consistently.

8
 Unambiguity: An algorithm must be clear and unambiguous in its instructions,
so that it can be understood and followed easily.
 Completeness: An algorithm must include all the necessary steps to solve the
problem or accomplish the task.
 Finiteness: An algorithm must terminate in a finite amount of time, meaning
that it must have a defined end point and not run indefinitely.
 Correctness: An algorithm must produce a correct output for a given input.
 Generality: An algorithm should be general enough to be applicable to a wide
range of problems or tasks, rather than being specific to a single problem or
task.
 Efficiency: An algorithm should be efficient in terms of its time and space
complexity, meaning that it should use a reasonable amount of resources (such
as time and memory) to solve the problem or accomplish the task.
Once again, consider the same example of binary search, but this time for a given set
of integers:
Example: consider a Binary Search where we have to find the target 19 in the list:
1 2 3 5 6 7 8 10 12 13 15 16 18 19 20 22
1. The middle point on the list, which comprises 16 items, is 8. 10 is the figure in the
eighth position. Search is limited to slots 9–16 because 19>10
1 2 3 5 6 7 8 10 12 13 15 16 18 19 20 22
2. The 12th position, which now has a value of 16, marks the middle of the list
(positions 9 through 16). Further search is limited to the 13th place and above because
19 > 16  1 2 3 5 6 7 8 10 12 13 15 16 18 19 20 22
The 14th position, which has a value of 19, serves as the list's midway at this time.
Further search is limited to the portion from the 13th through 19th since 19- 6> 19.
1 2 3 5 6 7 8 10 12 13 15 16 18 19 20 22
The 13th position, which has a value of 18, is now the halfway point of the current
list. The search is limited to position 14 because 19 > 18
1 2 3 5 6 7 8 10 12 13 15 16 18 19 20 22
The loop is over and the list has one element at this point. The location 14 is
returned because 19 = 19.

1.3. COMPLEXITY OF AN ALGORITHM


1. How effective is a certain algorithm at solving a problem with an input of a specific
size?
 How long does it take for the algorithm to execute completely??

9
 How much of computer memory is required to solve a problem via this
algorithm?
2. We estimate the time complexity using big-O and big-Theta notation and measure
it in terms of the number of operations a method performs.
3. Analyze the effectiveness of various algorithms for the same issue.
4. We concentrate on an algorithm's worst-case temporal complexity.
Determine the highest number of operations that a given algorithm will use to
solve a given problem with a given size of input.
(In contrast to the complexity of the typical case.)
5. Here, disregard hardware characteristics and implementation specifics.

1.3.1. Worst case complexity of linear search


The worst case complexity of linear search is O(n), where n is the number of
elements in the list. This means that the worst case time complexity of linear
search is directly proportional to the number of elements in the list.
For example, if the list has 10 elements and the target element is at the end of the
list, it will take the algorithm 10 steps to find the element. If the list has 100
elements and the target element is at the end of the list, it will take the algorithm
100 steps to find the element.
In general, the worst case complexity of linear search is not very efficient,
especially for large lists. There are other search algorithms that have a better worst
case complexity, such as binary search, which has a worst case complexity of
O(log n). However, linear search has the advantage of being simple to implement
and not requiring the list to be sorted.

1.3.2 Average case complexity of a linear search


The average case complexity of linear search is also O(n), where n is the number
of elements in the list. This means that, on average, the time complexity of linear
search is directly proportional to the number of elements in the list.
The average case complexity of an algorithm is a measure of how the algorithm
performs, on average, over a large number of inputs. In the case of linear search,
the average case complexity is the same as the worst case complexity, because the
algorithm always has to check each element in the list, regardless of where the
target element is located.
In general, the average case complexity of linear search is not very efficient,
especially for large lists. There are other search algorithms that have a better
average case complexity, such as binary search, which has an average case
complexity of O(log n). However, linear search has the advantage of being simple
to implement and not requiring the list to be sorted.

10
1.4. EXAMPLE OF A FEW ALGORITHMS
We have already seen the algorithm for binary and linear search. Let us take a
look at a few algorithms, which can be really useful in discrete mathematics.

 Depth First Search:


Algorithm:
1. 1. designate every vertex as unvisited.
2. Mark all vertices as unvisited, and then begin at any vertex.
3. visit an unattended neighbour.
4. continue until you have seen every neighbour you haven't already seen.
5. back up.

example: - consider the following graph:

The steps in a DFS are as follows:


1. begin at (for instance) f
2. go to f, g, h, k, j.
3. go back to k.
4. go back to h.
5. go to I.
6. go back to h.
7. go back to f.
8. go to f, d, e, c, a
9. go back to c.
10. go to c, b.

11
The uses for depth first search are numerous. For instance:
1. Find routes and circuits
2. track down related elements
3. locate cut vertex
4. many applications of AI

 Breadth First search-


Algorithm:
We can attempt to gradually explore at particular distances from the initial vertex
rather than constantly going as deep as is practical (as in depth first search). A
breadth first search is what it is known as, and it works like this:
1. keep track of the vertices that have already been seen, starting with an arbitrary
vertex.
2. move all nearby vertices to the conclusion of the list.
3. Visit the first vertex on the list that you removed.
4. move its unexplored neighbours to the list's end.
5. carry out steps 2-4 until the list is empty.
Consider the following graph:

The steps in the algorithm are as follows:

12
1. begin with (for instance) e
2. go to b, d, f, and I (the vertices at distance 1 from e)
3. Pay a visit to a, c, h, j, g, and k (the vertices at distance 2 from e)
4. go to L, M
A spanning tree is also produced by the procedure. In reality, this also provides the
route from the source node to any other node with the least number of edges. If all
edges are the same length or cost, this is the same as the shortest path.
 Dijkstra’s Algorithm:
Dijkstra's algorithm is an algorithm for finding the shortest path between two
nodes in a graph. It is an example of a single-source shortest path algorithm,
meaning that it is used to find the shortest path from a specific source node to all
other nodes in the graph.
Example: Find the shortest paths between X and Y in the graph using Dijkstra's
Algorithm.

13
Dijkstra's algorithm works by starting at the source node and expanding outward to
visit and "relax" the edges of all its neighbors. When an edge is relaxed, it means
that the algorithm checks to see if the shortest path to the neighbor node through
the current node is shorter than any previously known path. If it is, the algorithm
updates the shortest path to the neighbor node and adds the neighbor to a priority
queue.
The algorithm continues to visit and relax the edges of the nodes in the priority
queue until it reaches the target node or all reachable nodes have been visited. The
final shortest path is then recorded and returned as the result. Dijkstra's algorithm
is often used in routing and network analysis, and it has numerous applications in
fields such as computer science, transportation, and telecommunications.
Solving the problem:
Step 1: Include K is S in Step 1 and find all straight routes that lead from K to
every other vertex without passing through any other vertex.
Distance to all other vertices
S X p q r s Y
X 0 4(X) ∞ 2(X) ∞ 20(X)

Step 2: Include the closest vertex to K in S, find the shortest routes to all other
vertices via this vertex, and update the values. X is the next nearest node.
Distance to all other nodes
S X p q r s Y
X 0 3(X, r) 7(X, r) 2(X) 8(X, r) 18(X, r)

Step 3: The vertex which is 2nd nearest to K is 9, included in S.


Distance to all other nodes
S X p q r s Y
X 0 3(X, r) 7(X, r) 2(X) 7(X, r, p) 18(X, r)

Step 4: Third-closest vertex to X is q, which is a part of S.


Distance to all other nodes
S X p q r s Y
X 0 3(X, r) 7(X, r) 2(X) 7(X, r, p) 8(X, r, q)

Step 5: The vertex in S that is next to X in proximity is s.

14
Distance to all other nodes
S X p q r s Y
K(r, p, q, s) 0 3(X, r) 7(X, r) 2(X) 7(X, r, p) 8(X, r, q)

We have discovered the shortest distance between K and all other vertices because
S contains n-1 vertices. Therefore, the shortest path is K, r, s, L, and the minimum
distance between K and L is 8.

15
CHAPTER - 3: RECURSION
Drum rollsssss!!!
Question time!!!!!!
- what is Recursion??
When something is defined in terms of either itself or its type, recursion
happens. Recursion is employed in several academic fields, including
linguistics and logic. In mathematics and computer science, recursion is
most frequently used when a function is declared and then used within of its
own definition.
Recursive function:
Recursive functions produce a string of phrases by iterating over or utilising as input
their own previous term. The AP-GP, which contains words with a common
difference between them, is typically where we learn about this function.
The set of natural numbers, which begin at one and go all the way to infinity, i.e., 1, 2,
3, 4, 5, 6, 7, ..., is the most typical example we may use. As a result, each term in the
series of natural numbers has a common difference of 1, meaning that each term calls
its predecessor to be executed.
3.1. RECURRENCE RELATIONS:
In order to understand the concept of recurrence relation, look at the following case:
Time (t) Bacteria count
0 5
1 5∗2
2
2 5∗2
… …
… …
100
100 5∗2

Here, at time t=0, the bacteria count is 5 and they double their count with every
second. Now, if we want to find the count at t=50, we have to have the count at t=49,
and for the count at t=49, we need the count at t=48, and so on…
In short: An = 2 X An-1
The question now is: can I deduce a direct and generalised relation so that I do not
need to backtrack the count with each second, and it becomes easier??
Solution: A0 =5
A1 = 2∗A 0

16
A2 = 2∗A 1 = 22∗A 0
A3 = 2∗A 2 =23∗A 0
Hence, we can deduce that An =2n∗A 0

Here, A0 = K
And An = X An-1 for n≥ 1
Therefore, the general solution: An = Xn (K)  type-1

Type-2: consider the same case, but now A3 is dependent on more than one counts.
Consider: An+2 - 8An+1 +15An =0 ; A0=1, A5=2
Now, equate An = x 0 C1 C2
 the polunomial characteristic equation becomes:
2
x −8 x +15=0
( x−3 )( x−5 ) =0
x=3∧x=5
characteristic equation (C.E.): An = 5n C 1+3n C 2
Using the initial conditions: C1=-1/2, C2= -3/2
Put these values in the C.E., and that will be the answer.

Type-3: An + XAn-1 +Y An-2 =0


Its roots would be: A, B
 C.E.: An= AnC1 + Bn C2

Type-4: An + X An-1 + Y An-2 =0


Roots: A, A  C.E.: An = AnC1 + n. AnC2

Type -5: An= X. An-1 +Y. An-2 +Z. An-3


Roots: A, B, C
C.E.: An= C1. An + C2. Bn + C3. Cn

17
3.2. NON-HOMOGENEOUS EQUATIONS:
All the equations seen earlier were homogeneous equations, where f(n)=0.

But in non-homogeneous recurrence relations, f(n) ≠ 0.


Consider: An+2 – 5. An+1 + 6. An = 7n
(Homo part) (non-homo part)
Here, we solve the homogeneous and non-homogeneous equations separately, and
then the resultant is the sum of both the solutions:
Final C.E. = Homogeneous + Non-Homogeneous
F(n) Non homogeneous Characteristic Eqn
an A. (an )
n+2 An + B
n. an (An + B). an
N2 A.N2 + B.N + C
N 2. A n (A. N2 + B.N + C). An

18
19

You might also like