Func Ons and Graphs
Total Page:16
File Type:pdf, Size:1020Kb
Func%ons and Graphs CSC 1300 – Discrete Structures Villanova University Villanova CSC 1300 - Dr Papalaskari f A a 1 B Major Themes a c b 2 c 3 f d 4 d e 5 b g • Funcons • Graphs e – f : A→B – verces – domain/co-domain – edges – range – path – one-to-one – cycle – onto – Handshaking theorem – bijecon – Isomorphism Villanova CSC 1300 - Dr Papalaskari Func%ons: Basic terminology A funcon f from A to B assigns exactly one element of B to each element of A. A a 1 f B f : A→ B b 2 c 3 d 4 domain co-domain e 5 or target space • We write f(x) = y if the func%on f assigns y to x • The range of f is the set of all images of elements of A. NB: Range can be smaller than co-domain! Villanova CSC 1300 - Dr Papalaskari Func%ons: How many? A a 1 f B f : A→ B b 2 c 3 d 4 domain co-domain e 5 or target space Suppose |A| = m, |B| = q. • How many func%ons are there from A to B? qm • …one-to-one func%ons? q(q-1)(q-2)…(q-(m-1)) • (… onto? …. this ques%on is much harder, see #24 in Chapter) 6 Villanova CSC 1300 - Dr Papalaskari One-to-One Func%ons • A funcon ƒ : X→Y is one-to-one (or injecve) iff for each y∈Y there is at most one x∈X with ƒ(x) = y • Examples: {(1,5), (2,3), (4,5) } ƒ(x) = x2 for x ∈ Z one-to-one / injective Not one-to-one 1 5 1 1 2 3 0 0 4 6 -1 Villanova CSC 1300 - Dr Papalaskari Onto Func%ons A funcon ƒ : X→Y is onto (or surjecve) if for each y∈Y there exists an x∈X with ƒ(x) = y (co-domain = range) ƒ(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} 1 2 1 1 1 1 2 4 0 0 0 0 3 6 -1 2 2 4 4 Onto (but not Not onto Onto and one-to-one) one-to-one Villanova CSC 1300 - Dr Papalaskari (Bijection) Bijecons • A funcon ƒ from X to Y is a bijecon (or a one-to-one correspondence) if it is both injec%ve and surjec%ve. ƒ(x) = x2 for x ∈ {1,0,2} and y ∈ {1,0,4} Example. Let f(x) = x+1. Is f a bijec%on? 1 1 • if the domain and codomain are N? - no 0 0 • if the domain and codomain are Z? -yes 2 4 • if the domain and codomain are R? -yes Onto and one-to-one Villanova CSC 1300 - Dr Papalaskari (Bijection) Graphs • Graphs are discrete structures consis%ng of ver%ces and edges that connect these verces. Ques4ons • Graphs can be used to model: nisomorphism – computer systems/networks nshortest paths a c – mathemacal relaons ncycles/paths nplanarity f – logic circuit layout ncoloring d – jobs/processes b e Villanova CSC 1300 - Dr Papalaskari Graphs: Basic Terminology • A graph is defined as G = (V, E) with the set of ver%ces V and a set of edges E • Two ver%ces u and v in an undirected graph G are adjacent (or neighbors) if {u, v} is an edge of G. – The edge e is said to connect (or to be incident with) u and v. v2 e v3 2 G = ({v , v ,v }, {e , e }) 1 2, 3 1 2 e1 eg: edge e2 connects v2 and v3 G v1 Villanova CSC 1300 - Dr Papalaskari Directed Graphs • By defini%on, the edges of a directed graph are ordered pairs. • In a directed graph, if we have edge e = (u,v), then – u is said to be adjacent to v, the terminal vertex – v is said to be adjacent from u, the ini:al vertex b c e1 = (a,b) e2 = (b,a) e3 = (b,c) a d e4 = (b,d) e5 = (d,d) Villanova CSC 1300 - Dr Papalaskari Types of Graphs Multiple Type Edges Edges? Loops? Simple graph Undirected No No Multigraph Undirected Yes No Pseudograph Undirected Yes Yes Directed graph Directed No Yes Directed multigraph Directed Yes Yes Villanova CSC 1300 - Dr Papalaskari Degree of a vertex • The degree of a vertex v is the number of edges incident on v. – Denoted deg(v) – A loop on v contributes 2 to the deg(v) • 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 Handshaking Lemma In an undirected graph, the sum of the degrees of the ver%ces is twice the number of edges. Therefore, the sum of the degrees of all the verces is even. Σ deg(v) = 2|E|. v∈V • Corollary: An undirected graph has an even number of verces of odd degree. Villanova CSC 1300 - Dr Papalaskari Path • A path begins at vertex v0, follows an edge e1 to v1, follows another edge to v2 … – A path is represented without edges (especially when there are no parallel edges) • (v0, v1, v2, … vn) – Said to be of length n • A path on a vertex itself is of length 0 • A simple path from v0 to vn is a path with no repeated edges. Villanova CSC 1300 - Dr Papalaskari Cycle • A cycle (or circuit) is a path of nonzero length from v to v. Some cycles: b c e (b,c,d,e,a,b) (a,b,a,e,d,c,a) (b,a,c,d,e,a,b) a d (a,d,c,a,e,d,a) (c,d,e,a,b,c) • A simple circuit is a circuit from v to v with no repeated edges Villanova CSC 1300 - Dr Papalaskari Connected Graph • A graph G is connected if given any ver%ces v1 and v2 in G, there is a path from v1 to v2. Connected b c Not Connected e f b c f a d a d connected components Tree: a connected graph with no cyclesVillanova CSC 1300 - Dr Papalaskari Bipar%te Graph • A simple graph is called biparte if its vertex set V can be par%%oned into 2 disjoint sets V1 and V2 such that every edge in the graph connects a vertex in V1 to a vertex in V2. b c b c a d a d e Not Bipar4te Bipar4te e V1 = {b,a,e} V2 = {c,d} Villanova CSC 1300 - Dr Papalaskari Special Graphs • Complete Graph - Kn – Simple graph that contains exactly 1 edge between each pair of n dis%nct ver%ces. • Complete Bipar%te Graph – Kn,m – Simple graph that contains exactly 1 edge between each pair of n dis%nct ver%ces to m dis%nct ver%ces. • Cycles – Cn – For n≥3, consists of n ver%ces and edges {v1,v2}, {v2,v3} … {vn-1,vn} • Wheels – Wn – Cycle Cn with an addi%onal vertex added and an edge from the new vertex to each of the n ver%ces Villanova CSC 1300 - Dr Papalaskari Representaon of Graphs V E {{a, b, c, d, e}, {{a,b}, {b,b}, {c,d}, {a,c}, {e,d}, {e,d}, {a,e}} b e1 e2 a e4 c e e7 3 e e 5 d mulset representaon (allows repe%%on) e6 Adjacency list Adjacency matrix a: b, e a b c d e a 0 1 1 0 1 b: a, b b 1 1 0 0 0 c: a, d c 1 0 0 1 0 d: c, e, e d 0 0 1 0 2 e: a, d, d e 1 0 0 2 0 Villanova CSC 1300 - Dr Papalaskari Isomorphism… • It means two graphs are essen%ally the same (maybe drawn differently and re-labeled) – Same number of ver%ces necessary but NOT sufficient condions – Same number of edges 1 – Same degree sequence a b G2 3 G1 2 d 5 c 4 e f 6 Some%mes it is hard to tell… 3.8 Problem#3: are these essen%ally the same graph? Villanova CSC 1300 - Dr Papalaskari Isomorphism • Graphs are isomorphic if they have the same structure – 1-to-1 mapping of ver%ces that preserves edges a c f a e e f b d b d c Villanova CSC 1300 - Dr Papalaskari Isomorphism Isomorphic graphs will have the same adjacency matrix under some reordering of the ver&ces abcdef è bacdfe a c b c 0 1 1 0 1 0 e f 1 0 0 1 0 0 1 0 0 1 0 0 f e 0 1 1 0 0 1 b d a d 1 0 0 0 0 1 0 0 0 1 1 0 Villanova CSC 1300 - Dr Papalaskari Special Graphs • Connected, simple graph – Cycle Cn – Wheels Wn – Complete graph Kn – The Complement Graph G – A Complete Bipar%te Kn,m – Tree: a connected graph with no cycles Villanova CSC 1300 - Dr Papalaskari More Graph Terminology Let G = (V, E) – The complement G = (V, E’) • where E’= {{u,v} | u ∈ V and v ∈ V and {u,v} ∉ E} – A graph G’=(v’,E’) is a subgraph of G iff V’⊆ V and E’⊆ E – A connected component of a graph is a subgraph that is connected. Tree: a connected graph with no cycles Forest: graph with no cycles Villanova CSC 1300 - Dr Papalaskari .