CS 2210(22C:19) Discrete Math Graphs

Slides:



Advertisements
Similar presentations
CSE 211 Discrete Mathematics
Advertisements

Chapter 9 Graphs.
2012: J Paul GibsonT&MSP: Mathematical FoundationsMAT7003/L2-GraphsAndTrees.1 MAT 7003 : Mathematical Foundations (for Software Engineering) J Paul Gibson,
22C:19 Discrete Math Graphs Fall 2010 Sukumar Ghosh.
Introduction to Graph Theory Instructor: Dr. Chaudhary Department of Computer Science Millersville University Reading Assignment Chapter 1.
22C:19 Discrete Math Graphs Fall 2014 Sukumar Ghosh.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
Greedy Algorithms Greed is good. (Some of the time)
22C:19 Discrete Structures Trees Spring 2014 Sukumar Ghosh.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
22C:19 Discrete Math Trees Fall 2011 Sukumar Ghosh.
1 Copyright M.R.K. Krishna Rao 2003 Ch 9 - Trees Definition: A tree is a connected undirected graph with no simple circuits. Since a tree cannot have a.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Last time: terminology reminder w Simple graph Vertex = node Edge Degree Weight Neighbours Complete Dual Bipartite Planar Cycle Tree Path Circuit Components.
Applied Discrete Mathematics Week 12: Trees
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Introduction to Graphs
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Trees.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
Discrete Mathematics Lecture 9 Alexander Bukharovich New York University.
22C:19 Discrete Math Graphs Spring 2014 Sukumar Ghosh.
Social Media Mining Graph Essentials.
GRAPH Learning Outcomes Students should be able to:
Data Structures Using C++ 2E
Let G be a pseudograph with vertex set V, edge set E, and incidence mapping f. Let n be a positive integer. A path of length n between vertex v and vertex.
May 5, 2015Applied Discrete Mathematics Week 13: Boolean Algebra 1 Dijkstra’s Algorithm procedure Dijkstra(G: weighted connected simple graph with vertices.
IS 2610: Data Structures Graph April 5, 2004.
Chapter 2 Graph Algorithms.
Graph Theory Topics to be covered:
May 1, 2002Applied Discrete Mathematics Week 13: Graphs and Trees 1News CSEMS Scholarships for CS and Math students (US citizens only) $3,125 per year.
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
Foundations of Discrete Mathematics
Graphs Rosen, Chapter 8. Isomorphism (Rosen 560 to 563) Are two graphs G1 and G2 of equal form? That is, could I rename the vertices of G1 such that the.
Week 11 - Wednesday.  What did we talk about last time?  Graphs  Euler paths and tours.
Tree A connected graph that contains no simple circuits is called a tree. Because a tree cannot have a simple circuit, a tree cannot contain multiple.
1 CS104 : Discrete Structures Chapter V Graph Theory.
CS 200 Algorithms and Data Structures
Module #19: Graph Theory: part II Rosen 5 th ed., chs. 8-9.
Discrete Structures Lecture 12: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
Mathematics of Networks (Cont)
5.5.2 M inimum spanning trees  Definition 24: A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible.
Trees – Chapter 9 Slides courtesy of Dr. Michael P. Frank University of Florida Dept. of Computer & Information Science & Engineering.
5.5.3 Rooted tree and binary tree  Definition 25: A directed graph is a directed tree if the graph is a tree in the underlying undirected graph.  Definition.
Data Structures & Algorithms Graphs
Agenda Review: –Planar Graphs Lecture Content:  Concepts of Trees  Spanning Trees  Binary Trees Exercise.
Graphs 1 Definition 2 Terminology 3 Properties 4 Internal representation Adjacency list Adjacency matrix 5 Exploration algorithms 6 Other algorithms.
1 12/2/2015 MATH 224 – Discrete Mathematics Formally a graph is just a collection of unordered or ordered pairs, where for example, if {a,b} G if a, b.
Most of contents are provided by the website Graph Essentials TJTSD66: Advanced Topics in Social Media.
Graph Theory and Applications
Introduction to Graph Theory
Discrete Structures CISC 2315 FALL 2010 Graphs & Trees.
Chapter 10: Trees A tree is a connected simple undirected graph with no simple circuits. Properties: There is a unique simple path between any 2 of its.
Graph Theory Unit: 4.
Chapter 9: Graphs.
Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Graph Theory Graph Theory - History Leonhard Euler's paper on “Seven Bridges of Königsberg”, published in 1736.
Discrete Mathematics Chapter 10 Trees. Outline 10.1 Introduction to Trees 10.2 Applications of Trees 10.3 Tree Traversal 10.4 Spanning Trees 10.5 Minimal.
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
Discrete Mathematics Trees.
Chapter 5 : Trees.
Greedy Technique.
Discrete Mathematicsq
Graph theory Definitions Trees, cycles, directed graphs.
Agenda Lecture Content: Introduction to Graph Path and Cycle
12. Graphs and Trees 2 Summary
Advanced Algorithms Analysis and Design
Graphs Chapter 13.
Presentation transcript:

CS 2210(22C:19) Discrete Math Graphs Spring 2015 Sukumar Ghosh

Seven Bridges of K⍥nigsberg Is it possible to walk along a route that cross each bridge exactly once?

Seven Bridges of K⍥nigsberg

A Graph

What is a Graph A graph G = (V, E) consists of V, a nonempty set of vertices (or nodes) and E, a set of edges. Each edge connects a pair of nodes that are called its endpoints. Graphs are widely used to model various systems in the real world

Back to the Bridges of K⍥nigsberg

Euler’s solution

Euler path

Simple graph

Types of graph

Definitions Simple graphs vs. multi-graphs At most one edge between a pair of nodes Multiple edges between some pair of nodes Simple graphs vs. multi-graphs Undirected vs. directed graphs (digraphs) Each edge between a pair (u, v) of nodes is directed, and represents an ordered pair

More examples of graphs Each node denotes an actor or an actress, and each edge between P and Q denotes that P, Q worked together in some movie. It is an undirected graph Hollywood graph Web graphs Each node denotes a web page, and each edge from page P to Q Q denotes a link on page P pointing to page Q. It is a directed graph

Application: Exam scheduling Why?

Problems in a computer network

Vertex degree

Degree sequence

Handshaking theorem

Handshaking theorem

A theorem THEOREM. An undirected graph has even number of vertices of odd degree. Can you prove this? It should follow from the handshaking theorem.

Review of basic definitions

Review of basic definitions

Types of graphs A cycle of a graph is a subset of its edge set that forms a path such that the first node of the path corresponds to the last.

Types of graphs Wheel graph The n-cube graph n=3 Complete graph: All vertices are adjacent Wheel graph

Types of graphs Bipartite graph A simple graph is called bipartite if its vertex set V can be partitioned into two disjoint subsets V1 and V2, such that every edge in the graph connects a vertex in V1 to a vertex in V2. Can always be colored using two colors.

Subgraphs

Computer representation of graphs ADJACENCY MATRIX (taken from Wolfram Mathworld)

Computer representation of graphs ADJACENCY LIST 1 Vertex Adjacent to 1 2 3 4 3, 4 1, 2 2 4 3 Can be represented as a linked list

Graph isomorphism Taken from MIT 6.042J/18.062J

Graph isomorphism Taken from MIT 6.042J/18.062J

Graph isomorphism Taken from MIT 6.042J/18.062J

Connectivity An undirected graph is connected if there is a path between every pair of distinct vertices of the graph. A connected component is the maximal connected subgraph of the given graph.

Connectivity issues Erdös number in academic collaboration graph Erdös number = n means the person collaborated with someone whose Erdös number is (n-1) Kevin Bacon number in Hollywood graph Actor Kevin Bacon once remarked that he worked with everybody in Hollywood, or someone who worked with them. Kevin Bacon number is an adaptation of Erdös number in Hollywood movie industry.

Cut vertex, cut set, cut edge A cut vertex (or articulation point ) is a vertex, by removing which one can partition the graph. A cut edge is an edge by removing which one can partition the graph. If multiple edges need to be remove to partition the graph, then the minimal set of such edges a cut set. Examples taken from Wikipedia

Connectivity in directed graphs A directed graph is strongly connected if there is a path from any vertex a to any other vertex b of the graph. A directed graph is weakly connected if there is a path between any two vertices of the underlying undirected graph. Strongly or weakly connected ?

More definitions Vertex cover is a famous problem in graph theory

Vertex Cover A vertex-cover of an undirected graph G=(V,E) is a subset V’ of V such that if edge (u, v) is an edge of G, then u is in V’, or v is in V’, or both. The set V′ is said to "cover" the edges of G Minimal or minimum vertex cover is a famous problem in graph theory

Dominating Set A dominating set for a graph G = (V, E) is a subset D of V such that every vertex not in D is adjacent to at least one member of D. (from Wikipedia) Computing a minimal or minimum dominating set is a famous problem in graph theory

Independent Set no two of which are adjacent to one another. Given a graph G = (V, E) an independent set is a subset of vertices no two of which are adjacent to one another. (from Wikipedia) Computing the maximal independent set is a well-known problem in graph theory

Euler path vs. Hamiltonian path Hamiltonian path = A path that passes through every vertex exactly once. A closed path is a Hamiltonian circuit or cycle. Euler path = A path that includes every edge exactly once. A closed path is a Euler circuit or cycle. We have reviewed Euler path in the 7-bridges of Konigsberg Problem.

Hamiltonian path Does the above graph have a Hamiltonian cycle? No! 1 2 4 5 3 Does the above graph have a Hamiltonian cycle? No! Hamiltonian circuit/cycle colored red

Shortest path Weighted graph. Compute the shortest path from a to z

Shortest path: Dijkstra’s algorithm Read the algorithm from page 712 of your text book

Shortest path: Dijkstra’s algorithm

Shortest path: Dijkstra’s algorithm

Shortest path: Dijkstra’s algorithm Computes the shortest path from a source node to each target node L (source) = 0, and for all other node u, L(u) := infinity, S:= null while z is not in S u := a vertex not in S with L(u) minimal; S := S ∪ {u}; for all vertices v not in S if L(u) + w(u, v) < L(v) then L(v) := L(u) + w(u, v) {known as relaxation: this adds a vertex with minimal label to S and updates the labels of vertices not in S} return L(z)

Traveling Salesman Problem (TSP) A traveling salesman wants to visit each of n cities exactly once, and then return to the starting point. In which order should he visit the cities to travel the minimum total distance? TSP = Computing the minimum cost Hamiltonian circuit. TSP is an extremely hard problem to solve (NP-complete) An optimal TSP tour through Germany’s largest cities (Source: Wikipedia)

Planar Graph A planar graph is one that can be embedded in the plane, i.e., it can be drawn on the plane in such a way that its edges do not intersect except only at their endpoints. planar K4 Butterfly planar Non-planar Non-planar K5 K3,3

Planar Graph How to verify that a graph is a planar graph? It should not depend upon how you draw the graph. Any graph that contains a K5 or K3,3 as its sub-graph is not planar

Graph Coloring Let G be a graph, and C be a set of colors. Graph coloring finds an assignment of colors to the different nodes of G, so that no two adjacent nodes have the same color. The problem becomes challenging when the |C| is small. Chromatic number. The smallest number of colors needs to color a graph is called its chromatic number.

Graph Coloring The chromatic number of a tree is 2.

Graph Coloring What are the chromatic numbers of these two graphs?

Four color theorem Theorem. Any planar graph can be colored using at most four colors. It all started with map coloring – bordering states or counties must be colored with different colors. In 1852, an ex-student of De Morgan, Francis Guthrie, noticed that the counties in England could be colored using four colors so that no adjacent counties were assigned the same color. On this evidence, he conjectured the four-color theorem. It took nearly 124 years to find a proof. It was presented by Andrew Appel and Wolfgang Haken.

CS2210 (22C:19) Discrete Structures Trees Spring 2015 Sukumar Ghosh

What is a tree?

Rooted tree: recursive definition

Rooted tree terminology (If u = v then it is not a “proper” descendant) If v is a descendant of u, then u is an ancestor of v

Rooted tree terminology A subtree

Rooted tree terminology

Important properties of trees

Important properties of trees Theorem. A tree with n nodes has (n-1) edges Proof. Try a proof by induction

Important properties of trees Theorem. A tree with n nodes has (n-1) edges Proof. Try a proof by induction

Trees as models Domain Name System

Trees as models Computer File System directory subdirectory This tree is a ternary (3-ary) tree, since each non-leaf node has three children

Trees as models: game tree

Binary and m-ary tree Binary tree. Each non-leaf node has up to 2 children. If every non-leaf node has exactly two nodes, then it becomes a full binary tree. m-ary tree. Each non-leaf node has up to m children. If every non-leaf node has exactly m nodes, then it becomes a full m-ary tree

Properties of trees Theorem. A full m-ary tree with k internal vertices contains n = (m.k + 1) vertices. Proof. Try to prove it by induction. [Note. Every node except the leaves is an internal vertex]

Properties of trees Theorem. Every tree is a bipartite graph. Theorem. Every tree is a planar graph.

Balanced trees The level of a vertex v in a rooted tree is the length of the unique path from the root to this vertex. The level of the root is zero. The height of a rooted tree is the maximum of the levels of vertices. The height of a rooted tree is the length of the longest path from the root to any vertex. A rooted m-ary tree of height h is balanced if all leaves are at levels h or h − 1.

Balanced trees Theorem. There are at most mh leaves in an m-ary tree of height h. Proof. Prove it by induction. Corollary. If an m-ary tree of height h has l leaves, then If the m-ary tree is full and balanced, then

A binary search tree of size 9 Ordered binary tree. For any non-leaf node The left subtree contains the lower keys. The right subtree contains the higher keys. How can you search an item? How many steps does each search take? A binary search tree of size 9 and depth 3, with root 8 and leaves 1, 4, 7 and 13

Binary search tree

Insertion in a binary search tree procedure insertion (T : binary search tree, x: item) v := root of T {a vertex not present in T has the value null } while v ≠ null and label(v) ≠ x if x < label(v) then if left child of v ≠ null then v := left child of v else add new vertex as a left child of v and set v := null else if right child of v ≠ null then v := right child of v else add new vertex as a right child of v and set v := null if root of T = null then add a vertex v to the tree and label it with x else if v = null or label(v) ≠ x then label new vertex with x and let v be the new vertex return v {v = location of x}

Decision tree Decision trees generate solutions via a sequence of decisions. Example 1. There are seven coins, all of which are of equal weight, and one counterfeit coin that is lighter than the rest. Given a weighing scale, in how many times do you need to weigh (each weighing determines the relative weights of the objects on the the two pans) to identify the counterfeit coin? {We will solve it in the class}.

Comparison based sorting algorithms A decision tree for sorting three elements

Comparison based sorting algorithms Theorem. Given n items (no two of which are equal), a sorting algorithm based on binary comparisons requires at least comparisons Proof. See page 761-762 of your textbook. We will discuss it in the class The complexity of such an algorithm is Why?

Spanning tree Consider a connected graph G. A spanning tree is a tree that contains every vertex of G Many other spanning trees of this graph exist

Computing a spanning tree Given a connected graph G, remove the edges (in some order) without disrupting the connectivity, i.e. not causing a partition of the graph. When no further edges can be removed, a spanning tree is generated. Graph G

Computing a spanning tree Spanning tree of G

Depth First Search procedure DFS (G: connected graph with vertices v1…vn) T := tree consisting only of the vertex v1 visit(v1) {Recursive procedure} procedure visit (v: vertex of G) for each vertex w adjacent to v and not yet in T add vertex w and edge {v, w} to T visit (w) The visited nodes and the edges connecting them form a spanning tree. DFS can also be used as a search or traversal algorithm

Depth First Search: example

Breadth First Search A different way of Given graph G generating a spanning tree Given graph G Spanning tree

Breadth First Search ALGORITHM. Breadth-First Search. procedure BFS (G: connected graph with vertices v1, v2, …vn) T := tree consisting only of vertex v1 L := empty list put v1 in the list L of unprocessed vertices while L is not empty remove the first vertex v from L for each neighbor w of v if w is not in L and not in T then add w to the end of the list L add w and edge {v, w} to T

Minimum spanning tree A minimum spanning tree (MST) of a connected weighted graph is a spanning tree for which the sum of the edge weights is the minimum. How can you compute the MST of a graph G?

Huffman coding Consider the problem of coding the letters of the English alphabet using bit-strings. One easy solution is to use 5 bits for each letter (25 > 26). Another such example is The ASCII code. These are static codes, and do not make use of the frequency of usage of the letters to reduce the size of the bit string. One method of reducing the size of the bit pattern is to use prefix codes.

Prefix codes In typical English texts, e is most frequent, followed by, l, n, s, t … The prefix tree assigns to each letter of the alphabet a code whose length depends on the frequency: e = 0, a = 10, l= 110, n = 1110 etc Such techniques are popular for data compression purposes. The resulting code is a variable-length code. 1 e 1 a 1 l 1 n 1 s t

Huffman codes Another data compression technique first developed By David Huffman when he was a graduate student at MIT in 1951. (see pp. 763-764 of the textbook) Huffman coding is a fundamental algorithm in data compression, the subject devoted to reducing the number of bits required to represent information.

Huffman codes Example. Use Huffman coding to encode the following symbols with the frequencies listed: A: 0.08, B: 0.10, C: 0.12, D: 0.15, E: 0.20, F: 0.35. What is the average number of bits used to encode a character?

Huffman coding example

Huffman coding example

Huffman coding example

Huffman coding example So, in this example, what is the average number of bits needed to encode each letter? 3x 0.08 + 3 x 0.10 + 3 x 0.12 + 3 x 0.15 + 2 x 0.20 + 2 x 0.35 = 2.45 instead of 3-bits per letter.