Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Chapter 6: Graph Theory, Study notes of Discrete Structures and Graph Theory

A graph is a picture of dots called vertices and lines called edges. ... If there is a way to get from one vertex of a graph to all the other vertices of ...

Typology: Study notes

2021/2022

Uploaded on 09/12/2022

tomcrawford
tomcrawford 🇺🇸

4.1

(14)

263 documents

1 / 34

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter 6: Graph Theory
________________________________________________________________________
Chapter 6: Graph Theory
Graph theory deals with routing and network problems and if it is possible to find a
“best” route, whether that means the least expensive, least amount of time or the least
distance. Some examples of routing problems are routes covered by postal workers, UPS
drivers, police officers, garbage disposal personnel, water meter readers, census takers,
tour buses, etc. Some examples of network problems are telephone networks, railway
systems, canals, roads, pipelines, and computer chips.
Section 6.1: Graph Theory
There are several definitions that are important to understand before delving into Graph
Theory. They are:
A graph is a picture of dots called vertices and lines called edges.
An edge that starts and ends at the same vertex is called a loop.
If there are two or more edges directly connecting the same two vertices, then
these edges are called multiple edges.
If there is a way to get from one vertex of a graph to all the other vertices of the
graph, then the graph is connected.
If there is even one vertex of a graph that cannot be reached from every other
vertex, then the graph is disconnected.
Example 6.1.1: Graph Example 1
Figure 6.1.1: Graph 1
In the above graph, the vertices are U, V, W, and Z and the edges are UV, VV,
VW, UW, WZ1, and WZ2.
This is a connected graph. VV is a loop. WZ1, and WZ2 are multiple edges.
________________________________________________________________________
Page 197
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22

Partial preview of the text

Download Chapter 6: Graph Theory and more Study notes Discrete Structures and Graph Theory in PDF only on Docsity!

________________________________________________________________________

Chapter 6: Graph Theory

Graph theory deals with routing and network problems and if it is possible to find a “best” route, whether that means the least expensive, least amount of time or the least distance. Some examples of routing problems are routes covered by postal workers, UPS drivers, police officers, garbage disposal personnel, water meter readers, census takers, tour buses, etc. Some examples of network problems are telephone networks, railway systems, canals, roads, pipelines, and computer chips.

Section 6.1: Graph Theory

There are several definitions that are important to understand before delving into Graph Theory. They are:

  • A graph is a picture of dots called vertices and lines called edges.
  • An edge that starts and ends at the same vertex is called a loop.
  • If there are two or more edges directly connecting the same two vertices, then these edges are called multiple edges.
  • If there is a way to get from one vertex of a graph to all the other vertices of the graph, then the graph is connected.
  • If there is even one vertex of a graph that cannot be reached from every other vertex, then the graph is disconnected.

Example 6.1.1: Graph Example 1

Figure 6.1.1: Graph 1

In the above graph, the vertices are U, V, W, and Z and the edges are UV, VV, VW, UW, WZ 1 , and WZ 2.

This is a connected graph. VV is a loop. WZ 1 , and WZ 2 are multiple edges.

________________________________________________________________________

________________________________________________________________________

Example 6.1.2: Graph Example 2

Figure 6.1.2: Graph 2 Figure 6.1.3: Graph 3

The graph in Figure 6.1.2 is connected while the graph in Figure 6.1.3 is disconnected.

Graph Concepts and Terminology:

Order of a Network: the number of vertices in the entire network or graph

Adjacent Vertices: two vertices that are connected by an edge

Adjacent Edges: two edges that share a common vertex

Degree of a Vertex: the number of edges at that vertex

Path: a sequence of vertices with each vertex adjacent to the next one that starts and ends at different vertices and travels over any edge only once Circuit: a path that starts and ends at the same vertex

Bridge: an edge such that if it were removed from a connected graph, the graph would become disconnected

Example 6.1.3: Graph Terminology

Figure 6.1.4: Graph 4

In the above graph the following is true:


________________________________________________________________________

Example 6.2.1: Spanning Subgraph

Figure 6.2.1: Map of Connecting Towns

This is a graph showing how six cities are linked by roads. This graph has many spanning subgraphs but two examples are shown below.

Figure 6.2.2: Spanning Subgraph 1

This graph spans all of the cities (vertices) of the original graph, but does not contain any circuits.

Figure 6.2.3: Spanning Subgraph 2

________________________________________________________________________

________________________________________________________________________

This graph spans all of the cities (vertices) of the original graph, but does not contain any circuits.

Tree: A tree is a graph that is connected and has no circuits. Therefore, a spanning subgraph is a tree and the examples of spanning subgraphs in Example 6.2.1 above are also trees.

Properties of Trees:

  1. If a graph is a tree, there is one and only one path joining any two vertices. Conversely, if there is one and only one path joining any two vertices of a graph, the graph must be a tree.
  2. In a tree, every edge is a bridge. Conversely, if every edge of a connected graph is a bridge, then the graph must be a tree.
  3. A tree with N vertices must have N-1 edges.
  4. A connected graph with N vertices and N-1 edges must be a tree.

Example 6.2.2: Tree Properties

Figure 6.2.2: Spanning Subgraph 1

Consider the spanning subgraph highlighted in green shown in Figure 6.2.2.

a. Tree Property 1 Look at the vertices Appleville and Heavytown. Since the graph is a tree, there is only one path joining these two cities. Also, since there is only one path between any two cities on the whole graph, then the graph must be a tree.

b. Tree Property 2 Since the graph is a tree, notice that every edge of the graph is a bridge, which is an edge such that if it were removed the graph would become disconnected.

________________________________________________________________________

________________________________________________________________________

Example 6.2.4: Minimum Spanning Tree

Figure 6.2.5: Weighted Graph 1

The above is a weighted graph where the numbers on each edge represent the cost of each edge. We want to find the minimum spanning tree of this graph so that we can find a network that will reach all vertices for the least total cost.

Figure 6.2.6: Minimum Spanning Tree for Weighted Graph 1

This is the minimum spanning tree for the graph with a total cost of 51.

________________________________________________________________________

________________________________________________________________________

Kruskal’s Algorithm: Since some graphs are much more complicated than the previous example, we can use Kruskal’s Algorithm to always be able to find the minimum spanning tree for any graph.

  1. Find the cheapest link in the graph. If there is more than one, pick one at random. Mark it in red.
  2. Find the next cheapest link in the graph. If there is more than one, pick one at random. Mark it in red.
  3. Continue doing this as long as the next cheapest link does not create a red circuit.
  4. You are done when the red edges span every vertex of the graph without any circuits. The red edges are the MST (minimum spanning tree).

Example 6.2.5: Using Kruskal’s Algorithm

Figure 6.2.7: Weighted Graph 2

Suppose that it is desired to install a new fiber optic cable network between the six cities (A, B, C, D, E, and F) shown above for the least total cost. Also, suppose that the fiber optic cable can only be installed along the roadways shown above. The weighted graph above shows the cost (in millions of dollars) of installing the fiber optic cable along each roadway. We want to find the minimum spanning tree for this graph using Kruskal’s Algorithm.

________________________________________________________________________

________________________________________________________________________

Step 3: Find the next cheapest link of the whole graph and mark it in red as long as it does not create a red circuit. The next cheapest link is between C and E with a cost of seven million dollars.

Figure 6.2.10: Kruskal’s Algorithm Step 3

Step 4: Find the next cheapest link of the whole graph and mark it in red as long as it does not create a red circuit. The next cheapest link is between B and D with a cost of eight million dollars.

Figure 6.2.11: Kruskal’s Algorithm Step 4

________________________________________________________________________

________________________________________________________________________

Step 5: Find the next cheapest link of the whole graph and mark it in red as long as it does not create a red circuit. The next cheapest link is between A and B with a cost of nine million dollars, but that would create a red circuit so we cannot use it. Therefore, the next cheapest link after that is between E and F with a cost of 12 million dollars, which we are able to use. We cannot use the link between C and D which also has a cost of 12 million dollars because it would create a red circuit.

Figure 6.2.12: Kruskal’s Algorithm Step 5

This was the last step and we now have the minimum spanning tree for the weighted graph with a total cost of $37,000,000.

Section 6.3: Euler Circuits

Leonhard Euler first discussed and used Euler paths and circuits in 1736. Rather than finding a minimum spanning tree that visits every vertex of a graph, an Euler path or circuit can be used to find a way to visit every edge of a graph once and only once. This would be useful for checking parking meters along the streets of a city, patrolling the streets of a city, or delivering mail.

Euler Path: a path that travels through every edge of a connected graph once and only once and starts and ends at different vertices

________________________________________________________________________

________________________________________________________________________

Euler Circuit: an Euler path that starts and ends at the same vertex

Example 6.3.2: Euler Circuit

Figure 6.3.3: Euler Circuit Example

One Euler circuit for the above graph is E, A, B, F, E, F, D, C, E as shown below.

Figure 6.3.4: Euler Circuit

This Euler path travels every edge once and only once and starts and ends at the same vertex. Therefore, it is also an Euler circuit.

________________________________________________________________________

________________________________________________________________________

Euler’s Theorems:

Euler’s Theorem 1: If a graph has any vertices of odd degree, then it cannot have an Euler circuit.

If a graph is connected and every vertex has an even degree, then it has at least one Euler circuit (usually more). Euler’s Theorem 2 : If a graph has more than two vertices of odd degree, then it cannot have an Euler path.

If a graph is connected and has exactly two vertices of odd degree, then it has at least one Euler path (usually more). Any such path must start at one of the odd-degree vertices and end at the other one. Euler’s Theorem 3 : The sum of the degrees of all the vertices of a graph equals twice the number of edges (and therefore must be an even number).

Therefore, the number of vertices of odd degree must be even.

Finding Euler Circuits:

  1. Be sure that every vertex in the network has even degree.
  2. Begin the Euler circuit at any vertex in the network.
  3. As you choose edges, never use an edge that is the only connection to a part of the network that you have not already visited.
  4. Label the edges in the order that you travel them and continue this until you have travelled along every edge exactly once and you end up at the starting vertex.

Example 6.3.3: Finding an Euler Circuit

Figure 6.3.5: Graph for Finding an Euler Circuit

________________________________________________________________________

________________________________________________________________________

Hamilton Circuit : a circuit that must pass through each vertex of a graph once and only once

Hamilton Path : a path that must pass through each vertex of a graph once and only once

Example 6.4.1: Hamilton Path:

Figure 6.4.1: Examples of Hamilton Paths

a. b. c.

Not all graphs have a Hamilton circuit or path. There is no way to tell just by looking at a graph if it has a Hamilton circuit or path like you can with an Euler circuit or path. You must do trial and error to determine this. By the way if a graph has a Hamilton circuit then it has a Hamilton path. Just do not go back to home.

Graph a. has a Hamilton circuit (one example is ACDBEA)

Graph b. has no Hamilton circuits, though it has a Hamilton path (one example is ABCDEJGIFH)

Graph c. has a Hamilton circuit (one example is AGFECDBA)

Complete Graph : A complete graph is a graph with N vertices in which every pair of vertices is joined by exactly one edge. The symbol used to denote a complete graph is KN.

________________________________________________________________________

________________________________________________________________________

Example 6.4.2: Complete Graphs

Figure 6.4.2: Complete Graphs for N = 2, 3, 4, and 5

a. K 2 b. K 3 c. K 4 d. K 5

two vertices and one edge

three vertices and three edges

four vertices and six edges

five vertices and ten edges

In each complete graph shown above, there is exactly one edge connecting each pair of vertices. There are no loops or multiple edges in complete graphs. Complete graphs do have Hamilton circuits.

Reference Point : the starting point of a Hamilton circuit

Example 6.4.3: Reference Point in a Complete Graph

Many Hamilton circuits in a complete graph are the same circuit with different starting points. For example, in the graph K 3 , shown below in Figure 6.4.3, ABCA is the same circuit as BCAB, just with a different starting point (reference point). We will typically assume that the reference point is A.

Figure 6.4.3: K 3

A

C B

________________________________________________________________________

________________________________________________________________________

Suppose a delivery person needs to deliver packages to three locations and return to the home office A. Using the graph shown above in Figure 6.4.4, find the shortest route if the weights on the graph represent distance in miles.

Recall the way to find out how many Hamilton circuits this complete graph has. The complete graph above has four vertices, so the number of Hamilton circuits is:

(N – 1)! = (4 – 1)! = 3! = 321 = 6 Hamilton circuits.

However, three of those Hamilton circuits are the same circuit going the opposite direction (the mirror image).

Hamilton Circuit Mirror Image Total Weight (Miles)

ABCDA ADCBA 18 ABDCA ACDBA 20 ACBDA ADBCA 20

The solution is ABCDA (or ADCBA) with total weight of 18 mi. This is the optimal solution.

B. Nearest-Neighbor Algorithm:

  1. Pick a vertex as the starting point.
  2. From the starting point go to the vertex with an edge with the smallest weight. If there is more than one choice, choose at random.
  3. Continue building the circuit, one vertex at a time from among the vertices that have not been visited yet.
  4. From the last vertex, return to the starting point.

Example 6.4.6: Nearest-Neighbor Algorithm

A delivery person needs to deliver packages to four locations and return to the home office A as shown in Figure 6.4.5 below. Find the shortest route if the weights represent distances in miles.

Starting at A, E is the nearest neighbor since it has the least weight, so go to E. From E, B is the nearest neighbor so go to B. From B, C is the nearest neighbor so go to C. From C, the first nearest neighbor is B, but you just came from there. The next nearest neighbor is A, but you do not want to go there yet because that is the starting point. The next nearest neighbor is E, but you already went there. So go to D. From D, go to A since all other vertices have been visited.

________________________________________________________________________

________________________________________________________________________

Figure 6.4.5: Complete Graph for Nearest-Neighbor Algorithm

The solution is AEBCDA with a total weight of 26 miles. This is not the optimal solution, but it is close and it was a very efficient method.

C. Repetitive Nearest-Neighbor Algorithm:

  1. Let X be any vertex. Apply the Nearest-Neighbor Algorithm using X as the starting vertex and calculate the total cost of the circuit obtained.
  2. Repeat the process using each of the other vertices of the graph as the starting vertex.
  3. Of the Hamilton circuits obtained, keep the best one. If there is a designated starting vertex, rewrite this circuit with that vertex as the reference point.

Example 6.4.7: Repetitive Nearest-Neighbor Algorithm

Suppose a delivery person needs to deliver packages to four locations and return to the home office A. Find the shortest route if the weights on the graph represent distances in kilometers.

________________________________________________________________________