CHAPTER 3: Algorithms Flashcards
Weights
consider pairs (bold(G),w) where bold(G) = (V,E) is a connected graph and w: E → N_0.
For each edge e∈E, the quantity w(e) is called the weight of e
Given a set S of edges
The weight of S:
w(S) = sum of e∈S of [w(e)]
TREE
connected graph without cycles
ISOMORPHISM CLASSES OF TREES ON n-VERTICES
counting isomers ie these aren’t isomorphisms to each other (they are classes of different types)
n = 1 • n = 2 •-• n = 3 \_\_ | | •-•-• •-• • (1,2,1) ~(2,1,1)
(does this count as 1-YES)
n = 4 •-•-•-• • >•-• • (1,2,2,1) (1,1,3,1)
n = 5 • •-•-•-•-• • | >•-•-• •-•-• • | •
(1,2,2,2,1) (1,1,3,2,1) (1,1,1,1,4)
8??
LABELLED TREES: KILLING ISOMORPHISMS
n=1
•1
n=1
•1-•2
n=3 •1-•2-•3 •2-•1-•3 •1-•3-•2 3 labelled trees :
n=4
•-•-•-•
has 4!/2=12 different labelled trees
(4! ways to label but some same graph due to symmetries)
• | • / \ • •
only choosing the middle number and permute the other 3
4!/3!=4 labelled trees
16 labelled trees
IN GENERAL LABELLED TREES WITH N VERTICES
(n!)/ |Automorphism group of T|
IN GENERAL LABELLED TREES WITH n VERTICES
(n!)/(#symmetris)
n=5
•-•-•-•-• 120/2=60
• | • | • / \ • • 20/2=60
• | •-•-• | • 5!/4!=3 --- 125 labelled trees
unlabelled vs labelled trees
n: unlabelled:labelled
1: 1:1
2: 1:1
3: 1:3
4: 2:16
5: 3:125
6: 6:1296
7: 11:16807
*vertices are no longer interchangeable once labelled this implies that are n! ways to label an unlabelled tree minus the symmetries
CAYLEYS FORMULA
n^(n-2) labelled trees on n vertices
Pr¨ufer code
a unique sequence associated with a labelled tree
Definition3.4.4
Prüfer code If record the edges of a tree
T as in the Pruning Algorithm, the first n−2 number appear in the top row is the Prüfer code of T
- A labelled trees Pr¨ufer code is obtained: by removing the leaf with the smallest label and set the ith element of the prufer sequence to be the label of this lease neighbour. for a labelled tree this is unique and has length n-2
- the proof of code is in bijection and we can construct the tree from the code
- prufer codes can be used to prove Curley’s formula
- some form will be on the exam
PR¨UFER CODE:
algorithm
1) find the lowest leaf l of T
2) record Edge e connecting it to the rest of the tree
3) delete l & e to get a simpler tree T’
4) repeat process with T’
* no number will appear twice in the bottom row
Output: A 2×n−1 table with entries in {1,…,n} that records the edges of T in a specified order.
Find the leaf v with the lowest label; it will have one edge e, connecting it to some vertex (its “parent”) w
Form a new tree T′ by deleting v and e, and record e in the output table, putting the deleted vertex
v in the bottom row and its parent w above it in the top row.
PR¨UFER CODE:
algorithm EXAMPLE
given 9 Vertex labelled tree, 8 edges
[7]\ [8]---[9] \ | [4]---[5] [6] / | / | [1 ]/ [2]/ [3]
Parent: 5|6|5|2|5|5|8|9|
Leaf: 1 |3|4|6|2|7|5|8|
1*removing Leaf i.e. Edge 1-5, leaves us with lowest leaves 3479- sometimes new leaves appear eg 2 only after 3 and 6(new leaf) removed
PR¨UFER CODE: A BIJECTION
we can construct the tree from the code:
given any sequence of n−2 numbers between 1 and n, we can construct a tree have that sequence as its Prüfer code.
Parent: 5|6|5|2|5|5|8|9|
Leaf: 1 |3|4|6|2|7|5|8|
- any # appearing as a parent isn’t a leaf this implies one is the lowest # which doesn’t appear so it’s Leaf. The first we deleted. Than the next lowest number that isn’t a leaf. But we go deleting so next is 6.
- finally numbers we have not used for edge col with 9 and 8 added
Given pru¨fer code example:
Parent: 4|2|2|8|8|3|7|9|
Leaf: | | | | | | | | |
*by Finding lowest # not in remaining code delete the first column and iterate , last 2 spaces left are last Edge
Parent: 4|2|2|8|8|3|7|9|
Leaf: 1|4|5|2|6|8|3|7|
drawing
tree with 9 vertices, leaves 1,5,6,9
**lowest number not in first row, ignore the previous top and bottom row numbers and write the lowest
CAYLEYS ENRICHMENT
Degree of vertex i=
#times i appears in table
= # times i appears in PRUFER CODE +1
COROLLARY labelled trees with degrees
the # of labelled trees on n vertices where for each i, Vertex i has degree d_i is
(n-2)!/ [pi (d_i-1)!]
*consistent with hand shaking
PRUFER CODE EXAMPLE:
Draw the tree whose Pr¨ufer code is (1, 1, 1, 1, 6, 5).
*The given Pr¨ufer code has six entries, therefore the corresponding
tree will have 6 + 2 = 8 entries.
The first number in the Pr¨ufer code is 1 and the lowest number not included in the Pr¨ufer code is 2, so we connect 1 to 2.
*We then drop the leading 1 in the code and put 2 at the back of the code:
(1, 1, 1, 6, 5, 2).
The first number in the code is still 1 and the lowest number not included is now
3, so we connect 1 to 3.
etc
*last numbers missing are 5 and 8 so we connect them
Parent: 1| 1| 1| 1|6|5|5|
Leaf: 2|3|4|7| 1|6|8|
- 1 connected to 2,7,3,4,6
then 6 connected to 5 which is connected to 8
ie leaves are 2,7,3,4,8
8 vertices
example degrees and trees
*trees on 6 vertices where vertices 1 and 3 have degree 3 everything else is a leaf
- prufer code where
1 appears 3-1 = 2
3 appears 2-_ times
*1331,11331,3311,
4!/(2!2!) ways to arrange 4 #s
n-2 #s : ways to arrange two of each of two different #s
ie permute x2
prufer code and degree notes
- for the table every column is an edge
- so looking at the table (prev example) the degree of 5 is 5, as 5 appears 5 times
- from the code 1 and 5 didn’t appear previously
- two appears twice and has degree 3
SPANNING TREES
*minimal connected graphs and spanning trees are minimal subgraphs containing all vertices that are still connected
Let G be a connected graph. A spanning tree T of G is a subgraph T⊆ G st T is a tree and contains every Vertex of G.
*found by deleting edges and preserving connectedness
example 3 vertices triangle
spanning trees are ABC
st different edges but still connected
3 spanning trees: A-B-C C-A-B and A-C-B
Spanning trees of K_n
Spanning trees of K_n are the same as label trees on n vertices, i.e. any tree on the n vertices
K_5 is pentagon with star and a spanning tree is C_5 for example, others include any other edges st vertices are connected
weighted graph encoded:
[A] [4][B] [5][7][C] [9][8][8][D] [5][5][5][8][E]
[A] [4][B] [5][7][C] [9][8][8][D] [5][5][5][8][E]
drawing: edge from A-B weight 4, edge from A to C weight 5,…
pentagon with star in the middle ABCDE - ie complete
outside weights 4,7,8,8,5