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

Combinatorial Computing - Assignment 3 - Spring 2009 | MAT 3770, Study notes of Mathematics

Material Type: Notes; Class: Combinatorial Computing; Subject: Mathematics; University: Eastern Illinois University; Term: Spring 2009;

Typology: Study notes

Pre 2010

Uploaded on 08/18/2009

koofers-user-5xk
koofers-user-5xk 🇺🇸

10 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Mat 3770
Week 3
Spring 2009
1
Chapter 1 Supplement:
Representing Graphs with Data Structures
IWhen working with graphs in a program, we're usually not
so much interested in doing some sort of arithmetic
operation as we are mainly searching for neighboring
nodes, for nodes with the least or maximum degree, etc.
IGiven a graph G=(V, E), we can represent G in a computer
program either with an adjacency matrix or adjacency
lists.
IEither an adjacency matrix or adjacency list can store
edge weights rather than 0/1 (indicating edge
existence); they can also be used to store directed
edges.
2
Adjacency Matrix
A
A
B
B
C
C
D
D
E
E
F
F
0
0
0
0
0
0
110 1
1
0
10 0 0
1 1 1 1 0
00100
1 0 01 1
00001
A
B
C
DE
F
INotice that in an adjacency matrix, in order to nd a
neighbor, say of F, we have to do essentially a linear
search. This is true even if we only want to know if F
has any neighbors.
3
Linked Lists
ABCE
BAC
C A B D E
DC
E A CF
FE
A
B
C
DE
F
IAn adjacency list can be stored in an array (vector) or
as linked lists.
INote that in C++ it is possible to “shrink” and “grow”
array/vector size, thus avoiding wasted space. However,
there is a trade off in time.
4
Induction Proofs
The DREADED Mathematical Induction Proof!
(And you thought you'd never see it again HA!!)
ILet P(1), P(2), . .. , P(n), P(n+1), .. . , be an innite sequence
of statements. And suppose we know:
1. P(1) is true, and
2. for some arbitrary n1,
if P(n) is true, then P(n+1) is true
Then, for every n1, P(n) is true.
5
Induction Proofs Steps
IThere are three steps to an Induction Proof:
1. Base Case (BC): establish the truth for P(1) (or P(i) for
some small or initial i); pick an easy case if possible.
2. Induction Hypothesis (IH): Assume the theorem is true
for some arbitrary case, say P(n). Note: in strong
induction, assume all cases up to an arbitrary case is
true.
3. Inductive Step (IS): Show (or verify) that using the IH,
we can prove P(n+1) is true.
6
pf3
pf4
pf5
pf8

Partial preview of the text

Download Combinatorial Computing - Assignment 3 - Spring 2009 | MAT 3770 and more Study notes Mathematics in PDF only on Docsity!

Mat 3770

Week 3

Spring 2009

1

Chapter 1 Supplement:

Representing Graphs with Data Structures

I (^) When working with graphs in a program, we're usually not so much interested in doing some sort of arithmetic operation as we are mainly searching ñ for neighboring nodes, for nodes with the least or maximum degree, etc.

I (^) Given a graph G=(V, E), we can represent G in a computer program either with an adjacency matrix or adjacency lists.

I (^) Either an adjacency matrix or adjacency list can store edge weights rather than 0/1 (indicating edge existence); they can also be used to store directed edges.

2

Adjacency Matrix

A A B

B

C

C

D

D

E

E

F

F 0 0 0 0 0 0 1 1 0 1 1

0 1 0 0 0 1 1 1 1 0 0 0 1 0 0 (^1 0 1 ) 0 0 0 0 1

A

B

C

D E

F

I (^) Notice that in an adjacency matrix, in order to nd a

neighbor, say of F , we have to do essentially a linear

search. This is true even if we only want to know if F

has any neighbors.

3

Linked Lists

A (^) B C E B A C C A B D E D C E A (^) C F F E

A

B

C

D

E

F

I An adjacency list can be stored in an array ( vector ) or

as linked lists. I (^) Note that in C++ it is possible to ìshrinkî and ìgrowî array/vector size, thus avoiding wasted space. However, there is a trade off in time.

4

Induction Proofs

The DREADED Mathematical Induction Proof! (And you thought you'd never see it again ó HA!!)

I (^) Let P(1), P(2),... , P(n), P(n+1),... , be an innite sequence of statements. And suppose we know:

  1. P(1) is true, and
  2. for some arbitrary n  1, if P(n) is true, then P(n+1) is true Then, for every n  1, P(n) is true.

Induction Proofs ó Steps

I (^) There are three steps to an Induction Proof:

  1. Base Case (BC): establish the truth for P(1) (or P(i) for some small or initial i); pick an easy case if possible.
  2. Induction Hypothesis (IH): Assume the theorem is true for some arbitrary case , say P(n). Note: in strong induction, assume all cases up to an arbitrary case is true.
  3. Inductive Step (IS): Show (or verify) that using the IH, we can prove P(n+1) is true.

Prove

Use induction to prove:

n i = 1 i^ =^

n ( n + 1 ) 2 ∀^ n^ ^1 BC : IH :

IS :

7

Another Proof

Use induction to prove:

n i = 1 (^2 i^ ^1 ) =^ n

(^2) ∀ n  1

BC : IH :

IS :

8

Yet Another Proof

Use induction to prove: 11 n^ 4 n^ is evenly divisible by 7 ∀ n  0 BC : IH :

IS :

9

General Position

I (^) A set of lines is in General Position if no two are parallel and no three pass through the same point.

General Not General Not General

10

Number of Regions

Given n lines in general position in the plane, into how many regions is the plane divided?

# lines # regions

I (^) Do all sets of 4 lines (in general position in the plane) yield the same number of regions? Why?

I (^) Question : How many new regions seem to get added by the i th^ line? Why? i of them

I (^) Let R(n) be the number of regions formed by n lines in general position in the plane.

I (^) Claim: R(n+1) = R(n) + (n+1)

I (^) Observation: line n+1 passes through n + 1 regions of the plane divided by n lines. Thus , each of these regions is cut in two, for a net gain of n + 1 regions.

If G is a tree, then e = v 1

BC Let v = 1 One vertex → no edges, e = 0 Thus, clearly true (0 = 1 1 = 0)

IH Assume a tree of n vertices has n 1 edges for some arbitrary n  1.

IS Show a tree Gn + 1 with n + 1 vertices has n edges I (^) Find a vertex of degree 1 (it must be a leaf), and remove it and its edge, forming tree Gn I (^) By the IH, en = vn 1, so Gn + 1 has 1 more vertex than edges (i.e., vn + 1 1 = en + 1 ) I (^) Hence, vn + 1 1 = en + 1 since we add 1 vertex and 1 edge to Gn to construct Gn + 1 Thus, if G is a tree, then e = v 1

End of Subproof

19

Back to Euler

IH Assume Euler's formula holds for graphs with n faces, for some arbitrary n  1, i.e., that n = e v + 2

IS Show the formula holds for any connected planar graph G with n+1 faces, v vertices, and e edges (i.e., n+1=ev+2, or n=ev+1)

I Pick a region of G and let a be an edge on that face.

I (^) Then G a has (n+1)1 = n regions; e 1 edges, and v vertices

a

20

Conclusion

I (^) By the IH: n = (e 1) v + 2 = e v + 1

I Thus, r = e v + 2 ∀ r  1

21

Chapter 2: Covering Circuits and Graph Coloring

2.1 Euler Cycles

Cycle : a sequence of consecutively linked edges:

((x 1 ; x 2 ), (x 2 ; x 3 ),... , (xn 1 ; xn ))

whose starting vertex is the ending vertex

(x 1 = xn )

and in which no edge can appear more than once.

A vertex may be visted multiple times, however.

22

Finding Cycles

A

B

C

D E

F

A

B

E

D

C

a

b

c

d

e

f

g

h

i

j

Konigsberg Bridge Problem

The old Prussian city of Konigsberg, located on the banks of the Pregel River, included two islands which were joined to the banks and to each other by seven bridges:

A

B C

D

Because sex and television hadn't been invented yet, the townspeople strolled about the town and across the bridges, and had entirely too much time to think...

Eventually, someone tried to determine a walk which began at their front door, crossed each bridge exactly once, and allowed them to return to their front door... A

B C

D

C

A

D

B

They weren't able to do this, so took the problem to the famous and fabulously well respected mathematician, Leonhard “Lenny” Euler!

He was able to solve the problem, and thus spawned Graph

Theory!

25

Multigraphs

Multigraph : a graph which allows multiple edges between the same vertices, as well as permitting selfñloops.

26

Euler Cycles

I (^) Can we nd a tour of the bridges which allows us to return home without crossing any bridge more than one time? Why or why not?

C

A

D

B

I (^) Euler Cycle : a cycle that contains all the edges in a graph and visits each vertex at least once.

27

An Investigation

Let G = (V, E) be a graph. Does G contain a path that begins and ends at the same vertex and traverses each edge exactly once (an Euler Cycle)?

B

A

C

D

F E

B

A C

D E

A

B

C

A

B

C

B

A

C

D

F E

28

Questions

Question : If an Euler Cycle exists, does it matter where we start?

Question : Do we need to produce an Euler cycle to know if one exists?

A F

C

E

D

B

B

A

C

D

F E

Observation 1

I (^) If G has an Euler Cycle, then every vertex has even degree... Why?

I (^) Suppose degree(v) is odd and I (^) we begin at v Can't end there, no way back I (^) we don't begin at v Must end there, contrary to the denition of Euler Cycle

Adjacency Matrix

How efcient may depend on what data structure is used to store the edges.

B

A

C

D

F E

A B C D E F

A 0 1 1 1 0 1

B 1 0 0 1 0 0

C 0 0 0 1 1 1

D 1 1 1 0 1 0

E 0 0 1 1 0 0

F 1 0 1 0 0 0

Finding ìnext edgeî in the path could take n = j V j steps, and this happens once for each edge; thus, j V j ∗ j E j steps are required.

37

Linked Lists

B

A

C

D

F E

A B C D E F

B

A D

A

A

C

A

C

D

B

D

C

D F

E F

C E

38

PseudoñCode

// S - Set of vertices with unmarked edges // P - Euler Path we’re building S = V P = {} fail = false while vertex remains with unmarked edge in S and haven’t failed 1.choose vertex with unmarked edge, u 2."walk" a path P’ to vertex v, marking edges 3.if u doesn’t equal v then fail = true else augment P with P’ endwhile

if not all edges marked, or G not connected, then fail = true

if not fail, then Euler Cycle exists

39

Theorem. An undirected multigraph has an Euler Cycle IFF it is connected and all vertices have even degree.

The proof follows the same construction as we gave for the Euler Cycle on a regular graph:

Take a walk, leaving breadcrumbs as we go.

If we do not return to where we started, yet all the edges we may take are marked, there is no cycle.

Otherwise, if there is a vertex on our path with an unmarked edge, repeat the walk with the same results.

40

Associated Problems

In graphs that do not contain Euler Cycles, we must traverse some edges more than one time (called Deadheading edges ) to obtain a tour. (Example in text: street cleaning)

I (^) New Problem : minimize the number of deadheading edges (i.e., nd the minimum set of edges needed to make all vertices of even degree and the graph connected.

I (^) Another Problem : minimize the number of Uñturns and turns the street cleaner must make (takes time and wastes fuel). This same concept is used in VLSI chip design ó minimize layers and vias.

Trails

Trail : a sequence of consecutively linked edges in which no edge appears more than once.

Trail is to Path as Cycle is to Circuit

Both trails and cycles allow repeated vertices

Euler Trail : a trail which contains all the edges in a graph. ( Note : it will visit each vertex at least once assuming the graph is connected.)

A Corollary

Corollary (to Euler's Theorem): A multigraph has an Euler Trail, but not an Euler Cycle, IFF it is connected and has exactly two vertices of odd degree.

Proof (⇒) Assume multigraph G has an Euler trail T but no Euler cycle and show it has exactly two vertices of odd degree.

We note the starting and ending vertices of T, the Euler trail, must have odd degree while all other vertices must have even degree (by the same reasoning used to show all vertices in a graph with an Euler Cycle must have even degree). Further, G must be connected.

(⇐) Assume multigraph G has exactly two vertices of odd degree (say p and q ), and show it has an Euler Trail but not an Euler Cycle.

Let us add a supplementary edge < p , q > to G, obtaining the graph H. H is connected and has all vertices of even degree. Hence by the Euler Cycle theorem, H has an Euler Cycle.

Let us call this Cycle C. Now, remove the edge < p , q > from C. This reduces the Euler Cycle to an Euler Trail and includes all edges of G.