Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Lecture 6

Download as pdf or txt
Download as pdf or txt
You are on page 1of 47

Assiut University

‫قومية‬ ‫كلية‬
‫ل معتمدة من الهيئة ال عتماد‬
‫ضمان جودة التعليم واال‬

Course Title: Discrete Structures


Course Code: CS201

Prof. Dr. Khaled F. Hussain


Proof by induction
• Proof by induction is a powerful technique used to prove
statements about sequences or structures that are defined
recursively. To prove that P(n) is true for all positive integers n,
where P(n) is a propositional function, we complete two steps:
• Base Step :
• We verify that P(1) is true.
• Inductive Step:
• We show that the conditional statement P(k) → P(k + 1) is true for all positive integers k.
• Conclusion:
• If the statement is true for the base case and for all k+1 whenever it is true for k, then
it is true for all values greater than or equal to the base case.
Proof by induction (Cont.)
• Expressed as a rule of inference, this proof technique can be stated as:
(P (1) ∧ ∀k(P(k) → P(k + 1))) → ∀nP (n)
Proof by induction (Cont.)
• Example: For all positive integers n, 1 + 2 + 3 + ... + n = n(n+1)/2.

• Proof by induction:
• Base case: For n = 1, 1 = 1(1+1)/2, which is true.
• Inductive step: Assume the statement is true for n = k: 1 + 2 + 3 + ... + k =
k(k+1)/2. Now, we need to prove it's true for n = k+1:
1 + 2 + 3 + ... + k + (k+1) = k(k+1)/2 + (k+1)
Simplifying the right side: (k+1)(k+2)/2
• Therefore, the statement is true for n = k+1.
Proof by induction (Cont.)
• Example: Use mathematical induction to show that
1 + 2 + 22 +· · ·+2n = 2n+1 − 1 for all nonnegative integers n.

• Proof by induction: Solution: Let P(n) be the proposition that 1 + 2 + 22 +· · ·+2n = 2n+1 − 1 for the integer n.
• BASIS STEP: P(0) is true because 20 = 1 = 21 − 1.
• INDUCTIVE STEP: We assume that P(k) is true for an arbitrary nonnegative integer k. That is, we assume that
1 + 2 + 22 +· · ·+2k = 2k+1 − 1.
• We must show that when we assume that P(k) is true, then P(k + 1) is also true. That is, we must show that
1 + 2 + 22 +· · ·+2k + 2k+1 = 2(k+1)+1 − 1 = 2k+2 − 1
assuming the inductive hypothesis P(k). Under the assumption of P(k), we see that
1 + 2 + 22 +· · ·+2k + 2k+1 = (1 + 2 + 22 +· · ·+2k) + 2k+1
= (2k+1 − 1) + 2k+1 using IH
= 2 · 2k+1 − 1
= 2k+2 − 1.
• We have completed the inductive step.
Strong induction
• Strong induction is a mathematical proof technique that extends
the principle of mathematical induction. Strong induction allows
you to assume that the statement holds for all values up to a
particular value.

• The Principle of Strong Induction


1.Base Case: Prove that the statement is true for the base case (often the
smallest possible value).
2.Inductive Step: Assume that the statement is true for all values from the
base case up to and including a particular value, k.
3.Inductive Conclusion: Use the assumption from step 2 to prove that the
statement is also true for the next value, k+1.
Strong induction (Cont.)
• Example: Proving the Fibonacci Number Formula
The Fibonacci numbers are defined recursively as follows:
F(0) = 0
F(1) = 1
F(n) = F(n-1) + F(n-2) for n ≥ 2

• We can prove the following formula for the nth Fibonacci number
using strong induction:
F(n) = [(1 + √5)/2]^n - [(1 - √5)/2]^n / √5
Strong induction (Cont.)
• Base Cases:

• For n = 0: F(0) = 0, which matches the formula.


• For n = 1: F(1) = 1, which matches the formula.
• Inductive Step: Assume that the formula holds for all values from 0 to k, where k ≥ 1.

• Inductive Conclusion: We need to prove that the formula holds for k+1. Using the recursive definition of Fibonacci numbers:

• F(k+1) = F(k) + F(k-1)


• By the inductive hypothesis, we can substitute the formula for F(k) and F(k-1):

• F(k+1) = [(1 + √5)/2]^k - [(1 - √5)/2]^k / √5 + [(1 + √5)/2]^(k-1) - [(1 - √5)/2]^(k-1) / √5


• Simplifying and factoring, we can show that this expression is equivalent to the formula for F(k+1).

• Therefore, by strong induction, the formula holds for all non-negative integers n.
Recursive Definitions
• Recursively Defined Functions
• BASIS STEP: Specify the value of the function at zero.
• RECURSIVE STEP: Give a rule for finding its value at an integer from its values at smaller integers.

• Example: Suppose that f is defined recursively by


f (0) = 3,
f (n + 1) = 2f (n) + 3. Find f (1), f (2), f (3), and f (4).
• Solution: From the recursive definition it follows that
f (1) = 2f (0) + 3 = 2 · 3 + 3 = 9,
f (2) = 2f (1) + 3 = 2 · 9 + 3 = 21,
f (3) = 2f (2) + 3 = 2 · 21 + 3 = 45,
f (4) = 2f (3) + 3 = 2 · 45 + 3 = 93.
Recursive Definitions (Cont.)
• Example: Give a recursive definition of an, where a is a nonzero real number and
n is a nonnegative integer.
• Solution: The recursive definition contains two parts. First a0 is specified, namely, a0 = 1. Then
the rule for finding an+1 from an, namely, an+1 = a · an, for n = 0, 1, 2, 3, . . . , is given. These two
equations uniquely define an for all nonnegative integers n.
Recursive Algorithms
• An algorithm is called recursive if it solves a problem by reducing it to an instance of the same problem with
smaller input.
• Example: Give a recursive algorithm for computing n!, where n is a nonnegative integer.

procedure factorial(n: nonnegative integer)


if n = 0 then return 1
else return n · factorial(n − 1)
Recursive Algorithms (Cont.)
• Example: Give a recursive algorithm for computing an, where a is a nonzero real number and n is a
nonnegative integer.

procedure power(a: nonzero real number, n: nonnegative integer)


if n = 0 then return 1
else return a · power(a, n − 1)
Recursive Algorithms (Cont.)
• Example: Give a recursive algorithm for computing the greatest common divisor of two nonnegative integers a and
b with a < b.

procedure gcd(a, b: nonnegative integers with a < b)


if a = 0 then return b
else return gcd(b mod a, a)

• We illustrate the workings of the function with a trace when the input is a = 5, b = 8.
• gcd(5, 8) = gcd(8 mod 5, 5) = gcd(3, 5).
• gcd(3, 5) = gcd(5 mod 3, 3) = gcd(2, 3)
• cd(2, 3) = gcd(3 mod 2, 2) = gcd(1, 2)
• gcd(1, 2) = gcd(2 mod 1, 1) = gcd(0, 1).
• Finally, to find gcd(0, 1) it uses the first step with a = 0 to find that gcd(0, 1) = 1.
• Consequently, the function finds that gcd(5, 8) = 1.
Recursive Algorithms (Cont.)
• Example: Give a recursive algorithm for Fibonacci Numbers

procedure fibonacci(n: nonnegative integer)


if n = 0 then return 0
else if n = 1 then return 1
else return fibonacci(n − 1) + fibonacci(n − 2)
Recursive Algorithms (Cont.)
• An Iterative Algorithm for Computing Fibonacci Numbers
• This algorithm requires far less computation than does the recursive algorithm.

procedure iterative fibonacci(n: nonnegative integer)


if n = 0 then return 0
else
x := 0
y := 1
for i := 1 to n − 1
z := x + y
x := y
y := z
return y
Assiut University
‫قومية‬ ‫كلية‬
‫ل معتمدة من الهيئة ال عتماد‬
‫ضمان جودة التعليم واال‬

Course Title: Discrete Structures


Course Code: CS201

Prof. Dr. Khaled F. Hussain


Graphs and Graph Models
• DEFINITION:A graph G = (V ,E) consists of V , a nonempty set of vertices (or nodes) and E, a set of edges.
Each edge has either one or two vertices associated with it, called its endpoints. An edge is said to connect its
endpoints.
Graphs
• Undirected graphs are a type of graph where the edges that
connect nodes (or vertices) do not have a specific direction.
• This means that you can traverse an edge in either direction.
Graphs (Cont.)
• A graph in which each edge connects two different vertices and where no two edges connect the same pair of
vertices is called a simple graph.
Graphs (Cont.)
• Graphs that may have multiple edges connecting the same vertices are called multigraphs.
Graphs (Cont.)
• Graphs that may include loops, and possibly multiple edges connecting the same pair of vertices or a vertex to
itself, are sometimes called pseudographs.
• Loops: edges that connect a vertex to itself.
Graphs (Cont.)
• A directed graph (or digraph) (V ,E) consists of a nonempty set of vertices V and a set of directed edges (or
arcs) E. Each directed edge is associated with an ordered pair of vertices. The directed edge associated with
the ordered pair (u, v) is said to start at u and end at v.
Graphs (Cont.)
• Directed graphs that may have multiple directed edges from a vertex to a second (possibly the same) vertex
are used to model such networks. We called such graphs directed multigraphs. When there are m directed
edges, each associated to an ordered pair of vertices (u, v), we say that (u, v) is an edge of multiplicity m.
Graphs (Cont.)
• Graph Terminology
Graph Models
• SOCIAL NETWORKS
• In these graph models, individuals or organizations are represented by vertices;
relationships between individuals or organizations are represented by edges.
Graph Models (Cont.)
• Influence Graphs: In studies of group behaviour, it is observed that certain people can influence the thinking
of others. A directed graph called an influence graph can be used to model this behavior. Each person of the
group is represented by a vertex. There is a directed edge from vertex a to vertex b when the person
represented by vertex a can influence the person represented by vertex b.
Graph Models (Cont.)
• Collaboration Graphs: A collaboration graph is used to model social networks where two people are
related by working together in a particular way.
• In an academic collaboration graph, vertices represent people (perhaps restricted to members of a
certain academic community), and edges link two people if they have jointly published a paper. The
collaboration graph for people who have published research papers in mathematics was found in 2004 to
have more than 400,000 vertices and 675,000 edges.

• Call Graphs: Graphs can be used to model telephone calls made in a network.
• Each telephone number is represented by a vertex and each telephone call is represented by a directed edge.
• The edge representing a call starts at the telephone number from which the call was made and ends at the telephone
number to which the call was made.
• We need directed edges because the direction in which the call is made matters.
• We need multiple directed edges because we want to represent each call made from a particular telephone number to a
second number.
Graph Models (Cont.)
• The Web Graph: The World Wide Web can be modelled as a directed graph where each Web page is
represented by a vertex and where an edge starts at the Web page a and ends at the Web page b if there is a
link on a pointing to b. Because new Web pages are created and others removed somewhere on the Web
almost every second, the Web graph changes on an almost continual basis.

• Citation Graphs: Graphs can be used to represent citations in different types of documents. In such graphs,
each document is represented by a vertex, and there is an edge from one document to a second document if
the first document cites the second in its citation list.

• Road Networks: Graphs can be used to model road networks. In such models, vertices represent intersections
and edges represent roads.

• ….etc.
Graph Terminology
• Two vertices u and v in an undirected graph G are called adjacent (or neighbors) in G if u and v are endpoints
of an edge e of G.
• Such an edge e is called incident with the vertices u and v and e is said to connect u and v.

• The set of all neighbours of a vertex v of G = (V ,E), denoted by N(v), is called the neighborhood of v. If A is a
subset of V , we denote by N(A) the set of all vertices in G that are adjacent to at least one vertex in A. So, N(A)
= Uv∈A N(v).

• The degree of a vertex in an undirected graph is the number of edges incident with it, except that a loop at a
vertex contributes twice to the degree of that vertex. The degree of the vertex v is denoted by deg(v).
Graph Terminology (Cont.)
• EXAMPLE:
• deg(a) = 2, deg(b) = deg(c) = deg(f ) = 4, deg(d ) = 1, deg(e) = 3, and deg(g) = 0.
• The neighborhoods of these vertices are N(a) = {b, f }, N(b) = {a, c, e, f }, N(c) =
{b, d, e, f }, N(d) = {c}, N(e) = {b, c, f }, N(f ) = {a, b, c, e}, and N(g) = ∅.
Graph Terminology (Cont.)
• EXAMPLE
• deg(a) = 4, deg(b) = deg(e) = 6, deg(c) = 1, and deg(d ) = 5.
• The neighborhoods of these vertices are N(a) = {b, d, e}, N(b) = {a, b, c, d, e}, N(c) = {b}, N(d) = {a, b, e},
and N(e) = {a, b, d}.
Graph Terminology (Cont.)
THE HANDSHAKING THEOREM Let G = (V ,E) be an undirected graph with m edges. Then
2𝑚 = ෍ 𝑑ⅇ𝑔 𝑣
𝑣𝜖𝑉
(Note that this applies even if multiple edges and loops are present.)

• Example: How many edges are there in a graph with 10 vertices each of degree six?
• Solution: Because the sum of the degrees of the vertices is 6 ・ 10 = 60, it follows that 2m = 60 where m
is the number of edges. Therefore, m = 30.
Graph Terminology (Cont.)
• When (u, v) is an edge of the graph G with directed edges, the vertex u is called the initial vertex of (u, v), and v
is called the terminal or end vertex of (u, v). The initial vertex and terminal vertex of a loop are the same.
• In a graph with directed edges the in-degree of a vertex v, denoted by deg− (v), is the number of edges with v as
their terminal vertex. The out-degree of v, denoted by deg+ (v), is the number of edges with v as their initial
vertex. (Note that a loop at a vertex contributes 1 to both the in-degree and the out-degree of this vertex.)
• EXAMPLE: Find the in-degree and out-degree of each vertex in the graph G with directed edges.
• Solution: The in-degrees in G are deg−(a) = 2, deg−(b) = 2, deg−(c) = 3, deg−(d) = 2, deg−(e) = 3, and
deg−(f ) = 0.
• The out-degrees are deg+ (a) = 4, deg+(b) = 1, deg+(c) = 2, deg+(d) = 2, deg+(e) = 3, and deg+(f ) = 0.
Graph Terminology (Cont.)
• THEOREM: Let G = (V ,E) be a graph with directed edges. Then

෍ deg − 𝑣 = ෍ deg + 𝑣 = 𝐸
𝑣∈V 𝑣∈V
Some Special Simple Graphs
• Complete Graphs: A complete graph on n vertices, denoted by Kn, is a simple graph that contains exactly
one edge between each pair of distinct vertices.
Some Special Simple Graphs (Cont.)
• Cycles: A cycle Cn, n ≥ 3, consists of n vertices v1, v2, . . . , vn and edges {v1, v2}, {v2, v3}, . . . , {vn−1, vn},
and {vn, v1}.
Some Special Simple Graphs (Cont.)
• Wheels: We obtain a wheel Wn when we add an additional vertex to a cycle Cn, for n ≥ 3, and connect this
new vertex to each of the n vertices in Cn, by new edges.
Some Special Simple Graphs (Cont.)
• n-Cubes An n-dimensional hypercube, or n-cube, denoted by Qn, is a graph that has vertices representing
the 2n bit strings of length n. Two vertices are adjacent if and only if the bit strings that they represent differ in
exactly one bit position.
Some Special Simple Graphs (Cont.)
• A simple graph G is called bipartite if its vertex set V can be partitioned into two disjoint sets V1 and V2 such
that every edge in the graph connects a vertex in V1 and a vertex in V2 (so that no edge in G connects either
two vertices in V1 or two vertices in V2). When this condition holds, we call the pair (V1, V2) a bipartition of
the vertex set V of G.
• For example, consider the graph representing marriages between men and women in a village, where each
person is represented by a vertex and a marriage is represented by an edge. In this graph, each edge connects a
vertex in the subset of vertices representing males and a vertex in the subset of vertices representing females.
• The following figure show a bipartite graph, because its vertex set can be partitioned into the two sets V1 =
{v1, v3, v5} and V2 = {v2, v4, v6}, and every edge of C6 connects a vertex in V1 and a vertex in V2.
Some Special Simple Graphs (Cont.)
• THEOREM: A simple graph is bipartite if and only if it is possible to assign one of two different colors to
each vertex of the graph so that no two adjacent vertices are assigned the same color.
• Example: Use the Theorem to determine whether the following graph is bipartite.
• Solution: Yes

• Example: Use the Theorem to determine whether the following graph is bipartite.
• Solution: No
Representing Graphs
• Adjacency lists, which specify the vertices that are adjacent to each vertex of the graph.

• EXAMPLE: Use adjacency lists to describe the following simple


graph
Representing Graphs (Cont.)
• EXAMPLE: Use adjacency lists to describe the following Directed
Graph
Representing Graphs (Cont.)
• The adjacency matrix A (or AG) of G, with respect to this listing of the vertices, is the n x n zero–one matrix
with 1 as its (i, j )th entry when vi and vj are adjacent, and 0 as its (i, j )th entry when they are not adjacent.
1 𝑖𝑓 𝑣𝑖 , 𝑣𝑗 𝑖𝑠 𝑎𝑛 ⅇ𝑑𝑔ⅇ 𝑜𝑓 𝐺
𝑎𝑖𝑗 = ቊ
0 𝑜𝑡ℎⅇ𝑟𝑤𝑖𝑠ⅇ
• EXAMPLE: Use an adjacency matrix to represent the graph in the following Figure.
• Solution: We order the vertices as a, b, c, d. The matrix representing this graph is
Representing Graphs (Cont.)
• Draw a graph with the adjacency matrix with respect to the ordering of vertices a, b, c, d.
Representing Graphs (Cont.)
• The adjacency matrix of a simple graph is symmetric, that is, aij = aji , because both of these entries are 1 when
vi and vj are adjacent, and both are 0 otherwise. Furthermore, because a simple graph has no loops, each entry
aii, i = 1, 2, 3, . . . , n, is 0.
• Adjacency matrices can also be used to represent undirected graphs with loops and with multiple edges.
• A loop at the vertex vi is represented by a 1 at the (i, i)th position of the adjacency matrix.
• When multiple edges connecting the same pair of vertices vi and vj, or multiple loops at the same vertex,
are present, the adjacency matrix is no longer a zero–one matrix, because the (i, j )th entry of this matrix
equals the number of edges that are associated to {vi , vj }.
• EXAMPLE: Use an adjacency matrix to represent the following graph
Representing Graphs (Cont.)
• TRADE-OFFS BETWEEN ADJACENCY LISTS AND ADJACENCY MATRICES
• When a simple graph contains relatively few edges, that is, when it is sparse, it is usually preferable to
use adjacency lists rather than an adjacency matrix to represent the graph.
• Now suppose that a simple graph is dense, that is, suppose that it contains many edges, such as a graph
that contains more than half of all possible edges. In this case, using an adjacency matrix to represent the
graph is usually preferable overusing adjacency lists.
Representing Graphs (Cont.)
• Incidence matrices. Let G = (V ,E) be an undirected graph. Suppose that v1, v2, . . . , vn are the vertices and
e1, e2, . . . , em are the edges of G. Then the incidence matrix with respect to this ordering of V and E is the n ×
m matrix M = [mij ], where
1 when edge ⅇ𝑗 is incident with 𝑣𝑖
𝑚𝑖𝑗 = ቊ
0 otherwise.
• Example: Represent the following graph with an incidence matrix.

You might also like