1 / 36

Discrete Structures

Discrete Structures. Li Tak Sing( 李德成 ). Relations problems. Let R be the binary relation defined on the set N5={0,1,2,3,4} by xRy iff y=x+1. Write R as a set by listing each individual tuple. Evaluate {(x,y}| x>y and x,y {1,2,3}}. Evaluate {(x,y) | x,y N and 1x+y<4}.

thu
Download Presentation

Discrete Structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Discrete Structures Li Tak Sing(李德成)

  2. Relations problems • Let R be the binary relation defined on the set N5={0,1,2,3,4} by xRy iff y=x+1.Write R as a set by listing each individual tuple. • Evaluate {(x,y}| x>y and x,y {1,2,3}}. • Evaluate {(x,y) | x,y N and 1x+y<4}

  3. Proofs and Challenges • Page 54 Chapter 1 • Prove each of the following statements about combining set operations with Cartesian product. • (AB)C=(AC)(BC) • (A-B)C=(AC)-(BC)

  4. Let L, M and N be languages. Prove each of the following properties of the product operation on languages. • L{}={}L=L • L=L= • L(MN)=LMLN • (MN)L=MLNL

  5. If L, M are languages, prove that • L  L* • LLM* and L M*L • {}*={} • L*=L*L*=(L*)* • All languages that formed from L and M must be subset of (LM)* • (L*M*)*=(L*M*)*=(LM)*

  6. Counting tuples • |AB|=|A||B| • ABCA(BC) but |ABC|=|A(BC)| • |An|=|A|n

  7. Counting examples • Calculate the number of strings over the alphabet {a,b} that have length 7, begin with a, and contain at least one b. • Calcuate the number of strings over the alphabet {a,b,c} that have length 6, begin with an a or b, and contain at least one c.

  8. Graphs • A graph is a set of objects in which some of the objects are connected to each other in some way. The objects are called vertices or nodes and connections are called edges.

  9. Graph example

  10. Directed graph • A directed graph is a graph where each edge points in one direction. For example, the vertices could be cities and the edges could be the one-way air routes between them.

  11. Representation of graphs • A graph can be represented by an ordered pair (V,E) where V is a set of vertices. E is a set of edges. • If the graph is non-directed, then an edge can be represented as a set that contains the two vertices. • In the second last example, V={1,2,3,4,5,6}, E={{1,2},{1,5},{2,3},{3,4},{4,5},{4,6}}

  12. In the last example, G=(V,E) where V={A,B,C} and E={(A,B),(A,C),(B,C),(C,A)}

  13. Weighted Graphs • An edge can have value itself. For example, if a graph represents highways between different cities, and an edge represents a highway, then every edge can have the information that represents the length of the highway. Or it can have the value represents the cost to travel the highway.

  14. Weighted graphs • Such information is called the weight of the edge. • Such edges are represented by 3-tuples:(a,b,w) where a, b are the vertices and w is the weight.

  15. Graphs and Binary Relations • A binary relation R on a set A can be thought of as a digraph G=(A,R) with vertices A and edges R. • Let R={(3,4),(1,3),(3,2),(1,1)}, the graph is:

  16. Subgraphs • A graph (V’,E’) is a subgraph of a graph (V,E) if V’V and E’E.

  17. Paths in Graphs • A path from x0 to xn is a sequence of edges that we denoted by a sequence of vertices x0, x1, ..., xn such that there is an edge from xi-1 to xi from 1in. A path allows the possibility that some edge or some vertex occurs more than once. • A cycle is a path whose beginning and ending vertices are equal and in which no edge occurs more than once.

  18. A graph with no cycles is called acyclic. • The length of the path x0, ...,xn is the number n of edges.

  19. Connected graphs • A graph is connected if there is a path between every pair of vertices. A directed graph is connected if, when direction is ignored, the resulting undirected graph is connected.

  20. Graph traversals • A graph traversal starts at some vertex v and visits all vertices x that can be reached from v to x. If a vertex has already been visited, it is not visited again. Two popular traversal algorithms are called breadth-first and depth-first.

  21. Breadth-first traversal • If visit(v,k) denote the procedure that visits every vertex x not yet visited for which there is a length k path from v to x. • In the breadth-frist traversal, it can be described as:for k:=0 to n-1 do visit(v,k) od.

  22. Breadth-first traversal example a b c d e f

  23. Depth-first traversal • If DF(v) represents the depth-first procedure that traverses the graph starting at vertex v. Then DF(v) has the following definition.DF(v): if v has not been visited then visit v; for each edge from vto x do DF(x) od fi

  24. Trees • A tree is a graph with no cycles. • The vertices and edges of a tree are called nodes and braches, respectively. • Trees are usually shown as upside down versions of real trees.

  25. Trees • The node at the top is called the root. The nodes that hang immediately below a given node are its children, and the node immediately above a given node is its parent. If a node is childless, then it is a leaf. The height or depth of a tree is the length of the longest path from the root to its leaves. The path from a node to the root contains all the ancestors of the node. Any path from a node to a leaf contains descendants of the node.

  26. Trees • A tree with a designated root is often called a rooted tree. Otherwise, it is called a free tree or an unrooted tree.

  27. Subtrees • If x is a node in a tree T, then x together with all its descendants forms a tree S with x as its root. S is called a subtree of T. If y is the parent of x, then S is sometimes called a subtree of y.

  28. Ordered and unordered trees • If we don’t care about the ordering of the children of a tree, then the tree is called an unordered tree. A tree is ordered if there is a unique ordering of the children of each node.

  29. Representation of trees • A tree can be represented as list <a, b, c…> where a represents the root and b, c are subtrees of a.

  30. Binary trees • A binary tree is an ordered tree that may be empty or else has the property that each node has two subtrees, called the left and right substrees of the node, which are binary trees.

  31. Binary Search Trees • Binary trees can be used to represent sets whose elements have some ordering. Such a tree is called a binary search tree and has the property that for each node of the tree, each element in the left subtree precedes the node element and each element in its right subtree succeeds the node element.

  32. Spanning trees • A spanning tree for a connected graph is a subgraph that is a tree and contains all the vertices of the graph.

  33. Minimal spanning tree • A minimal spanning tree for a connected weighted graph is a spanning tree such that the sum of the edge weights is minium among all spanning trees.

  34. Prim’s algorithm • Initialize S:=. • Pick any vertex vV and W:={v}. • While WV do Find a minimum weight edge {x,y}, where xW and y V-W; S:=S{{x,y}}; W:=W{y}od

  35. Graph and tree examples • Given the following graph. F A H C B G D • Write down the vertices of the graph in the order that they are visited by a breadth-first search of the graph that starts at vertex A.

  36. Write down the vertices of the graph in the order that they are visited by a depth-first search of the graph that starts at vertex A.

More Related