CSC 1300 – Discrete Structures Chapter 3: Funcons and Graphs

f A a 1 B Major Themes a c b 2 c 3 f d 4 d e 5 b

• Funcons • g Funcons and Graphs Graphs e – f : A→B – verces – domain/co-domain – edges CSC 1300 – Discrete Structures – range – path Villanova University – one-to-one – – onto – Handshaking theorem – bijecon – Isomorphism

Villanova CSC 1300 - Dr Papalaskari Villanova CSC 1300 - Dr Papalaskari

Funcons: Basic terminology Funcons: How many?

A funcon f from A to B assigns exactly one element of B to each element of A.

A a 1 f B A a 1 f B f : A→ B b 2 f : A→ B b 2 c 3 c 3 d 4 d 4 domain co-domain e 5 domain co-domain e 5 or or target space target space • We write f(x) = y if the funcon f assigns y to x Suppose |A| = m, |B| = q. • The range of f is the set of all images of elements of A. m • How many funcons are there from A to B? q NB: Range can be smaller than co-domain! • …one-to-one funcons? q(q-1)(q-2)…(q-(m-1)) • (… onto? …. this queson is much harder, see #24 in Chapter) 6 Villanova CSC 1300 - Dr Papalaskari Villanova CSC 1300 - Dr Papalaskari

Dr Papalaskari 1 CSC 1300 – Discrete Structures Chapter 3: Funcons and Graphs

One-to-One Funcons Onto Funcons

• A funcon ƒ : X→Y is one-to-one (or injecve) iff for A funcon ƒ : X→Y is onto (or surjecve) if for each y∈Y there is at most one x∈X with ƒ(x) = y each y∈Y there exists an x∈X with ƒ(x) = y • Examples: (co-domain = range) {(1,5), (2,3), (4,5) } ƒ(x) = x2 for x ∈ Z ƒ(x) = x2 for x ∈ {1,0,-1} ƒ(x) = x2 for x ∈ {1,0,2} {(1,2), (2,4), (3,6), (4,6) } and y ∈ {1,0,2} and y ∈ {1,0,4} one-to-one / injective Not one-to-one 1 2 1 1 1 1 2 4 1 5 1 1 0 0 0 0 3 6 2 3 0 0 -1 2 2 4 4 4 6 -1 Onto (but not Not onto Onto and one-to-one) one-to-one Villanova CSC 1300 - Dr Papalaskari Villanova CSC 1300 - Dr Papalaskari (Bijection)

Bijecons Graphs

• A funcon ƒ from X to Y is a bijecon (or a • Graphs are discrete structures consisng of one-to-one correspondence) if it is both verces and edges that connect these injecve and surjecve. verces. Quesons • Graphs can be used to model: nisomorphism ƒ(x) = x2 for x ∈ {1,0,2} nshortest paths and y ∈ {1,0,4} – computer systems/networks a c Example. Let f(x) = x+1. Is f a bijecon? – mathemacal relaons ncycles/paths 1 1 nplanarity • if the domain and codomain are N? - no f 0 0 – logic circuit layout ncoloring d • if the domain and codomain are Z? -yes 2 4 – jobs/processes b • if the domain and codomain are R? -yes Onto and e one-to-one Villanova CSC 1300 - Dr Papalaskari Villanova CSC 1300 - Dr Papalaskari (Bijection)

Dr Papalaskari 2 CSC 1300 – Discrete Structures Chapter 3: Funcons and Graphs

Graphs: Basic Terminology Directed Graphs • By definion, the edges of a • A graph is defined as G = (V, E) with the set of are ordered pairs. verces V and a set of edges E • In a directed graph, if we have edge e = (u,v), • Two verces u and v in an undirected graph G then are adjacent (or neighbors) if {u, v} is an edge of G. – u is said to be adjacent to v, the terminal vertex – v is said to be adjacent from u, the inial vertex – The edge e is said to connect (or to be incident e = (a,b) with) u and v. b c 1 e2 = (b,a) v2 e v3 2 e = (b,c) 3 G = ({v , v ,v }, {e , e }) a d e = (b,d) 1 2, 3 1 2 e1 4 eg: edge e2 connects v2 and v3 G e5 = (d,d) v1 Villanova CSC 1300 - Dr Papalaskari Villanova CSC 1300 - Dr Papalaskari

Types of Graphs Degree of a vertex

• The degree of a vertex v is the number of Multiple Type Edges Edges? Loops? edges incident on v. Simple graph Undirected No No – Denoted deg(v) Undirected Yes No – A loop on v contributes 2 to the deg(v) Pseudograph Undirected Yes Yes

Directed graph Directed No Yes Directed multigraph Directed Yes Yes • Example: deg(a) = 3 b c e deg(b) = 1 deg(c) = 5 deg(e) = 0 a d deg(d) = 1

Villanova CSC 1300 - Dr Papalaskari Villanova CSC 1300 - Dr Papalaskari

Dr Papalaskari 3 CSC 1300 – Discrete Structures Chapter 3: Funcons and Graphs

Handshaking Lemma Path

In an undirected graph, the sum of the degrees • A path begins at vertex v0, follows an edge e1 of the verces is twice the number of edges. to v1, follows another edge to v2 … Therefore, the sum of the degrees of all the – A path is represented without edges (especially verces is even. when there are no parallel edges) • (v0, v1, v2, … vn) – Said to be of length n Σ deg(v) = 2|E|. • A path on a vertex itself is of length 0 v∈V • A simple path from v0 to vn is a path with no • Corollary: An undirected graph has an even repeated edges. number of verces of odd degree. Villanova CSC 1300 - Dr Papalaskari Villanova CSC 1300 - Dr Papalaskari

Cycle Connected Graph

• A cycle (or circuit) is a path of nonzero length • A graph G is connected if given any verces v1 from v to v. and v2 in G, there is a path from v1 to v2. Some cycles: b c e (b,c,d,e,a,b) (a,b,a,e,d,c,a) Connected (b,a,c,d,e,a,b) b c Not Connected a d (a,d,c,a,e,d,a) e f (c,d,e,a,b,c) b c f • A simple circuit is a circuit from v to v with no repeated edges a d a d connected components

Villanova CSC 1300 - Dr Papalaskari Tree: a connected graph with no cyclesVillanova CSC 1300 - Dr Papalaskari

Dr Papalaskari 4 CSC 1300 – Discrete Structures Chapter 3: Funcons and Graphs

Biparte Graph Special Graphs

• A simple graph is called biparte if its vertex • - Kn – Simple graph that contains exactly 1 edge between each pair set V can be paroned into 2 disjoint sets V1 of n disnct verces. and V such that every edge in the graph 2 • Complete Biparte Graph – Kn,m connects a vertex in V1 to a vertex in V2. – Simple graph that contains exactly 1 edge between each pair of n disnct verces to m disnct verces. b c b c V V • Cycles – Cn 1 – For n≥3, consists of n verces and edges {v ,v }, {v ,v } … a d a d 1 2 2 3 e {vn-1,vn} 2 Not Biparte • Wheels – W Biparte e n V = {b,a,e} – Cycle Cn with an addional vertex added and an 1 edge from the new vertex to each of the n verces V2 = {c,d} Villanova CSC 1300 - Dr Papalaskari Villanova CSC 1300 - Dr Papalaskari

Representaon of Graphs Isomorphism… V E {{a, b, c, d, e}, {{a,b}, {b,b}, {c,d}, {a,c}, {e,d}, {e,d}, {a,e}} • It means two graphs are essenally the same b (maybe drawn differently and re-labeled) e1 e2

a e4 c – Same number of verces necessary but NOT sufficient e e7 3 e condions e 5 d mulset representaon (allows repeon) – Same number of edges e6 1 – Same degree sequence a Adjacency list b G2 3 a: b, e a b c d e G1 2 a 0 1 1 0 1 b: a, b d b 1 1 0 0 0 5 c: a, d c 1 0 0 1 0 c 4 e d: c, e, e d 0 0 1 0 2 f e: a, d, d e 1 0 0 2 0 6 Somemes it is hard to tell… Villanova CSC 1300 - Dr Papalaskari 3.8 Problem#3: are these essenally the same graph? Villanova CSC 1300 - Dr Papalaskari

Dr Papalaskari 5 CSC 1300 – Discrete Structures Chapter 3: Funcons and Graphs

Isomorphism Isomorphism

• Graphs are isomorphic if they have the same Isomorphic graphs will have the same adjacency matrix structure under some reordering of the verces – 1-to-1 mapping of verces that preserves edges abcdef è bacdfe a c b c 0 1 1 0 1 0 a c f a e f 1 0 0 1 0 0 1 0 0 1 0 0 e e f e 0 1 1 0 0 1 d d 1 0 0 0 0 1 f b b a d 0 0 0 1 1 0 b d c

Villanova CSC 1300 - Dr Papalaskari Villanova CSC 1300 - Dr Papalaskari

Special Graphs More Graph Terminology

• Connected, simple graph Let G = (V, E) – The complement G = (V, E’) – Cycle Cn • where E’= {{u,v} | u ∈ V and v ∈ V and {u,v} ∉ E} – Wheels Wn – ⊆ – Complete graph K A graph G’=(v’,E’) is a subgraph of G iff V’ V n and E’⊆ E – The Complement Graph G – A connected component of a graph is a – A Complete Biparte Kn,m subgraph that is connected. – Tree: a connected graph with no cycles Tree: a connected graph with no cycles

Forest: graph with no cycles

Villanova CSC 1300 - Dr Papalaskari Villanova CSC 1300 - Dr Papalaskari

Dr Papalaskari 6