1 Chapter 1 - 2 Elementary Notions and Notations.

Slides:



Advertisements
Similar presentations
Chapter 2 Revision of Mathematical Notations and Techniques
Advertisements

Chapter 5: Tree Constructions
Chapter 10: Trees. Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.
22C:19 Discrete Structures Trees Spring 2014 Sukumar Ghosh.
Equivalence, Order, and Inductive Proof
Introduction to Trees Chapter 6 Objectives
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
Discrete Structures Lecture 13: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
1 Chapter Equivalence, Order, and Inductive Proof.
CMPS 2433 Discrete Structures Chapter 5 - Trees R. HALVERSON – MIDWESTERN STATE UNIVERSITY.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
CS 206 Introduction to Computer Science II 11 / 09 / 2009 Instructor: Michael Eckmann.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
KNURE, Software department, Ph , N.V. Bilous Faculty of computer sciences Software department, KNURE The trees.
Advanced Algorithms Analysis and Design Lecture 8 (Continue Lecture 7…..) Elementry Data Structures By Engr Huma Ayub Vine.
Notions & Notations (3) - 1ICOM 4075 (Spring, 2010) UPRM Department of Electrical and Computer Engineering University of Puerto Rico at Mayagüez Summer.
Chapter 2 Graph Algorithms.
Graph Theory Topics to be covered:
Introduction Of Tree. Introduction A tree is a non-linear data structure in which items are arranged in sequence. It is used to represent hierarchical.
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
1 Section 1.4 Graphs and Trees A graph is set of objects called vertices or nodes where some pairs of objects may be connected by edges. (A directed graph.
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.
Copyright © Cengage Learning. All rights reserved. CHAPTER 10 GRAPHS AND TREES.
Construction Techniques (1) - 1ICOM 4075 (Fall, 2010) UPRM Department of Electrical and Computer Engineering University of Puerto Rico at Mayagüez 2005.
CSCI 115 Chapter 7 Trees. CSCI 115 §7.1 Trees §7.1 – Trees TREE –Let T be a relation on a set A. T is a tree if there exists a vertex v 0 in A s.t. there.
Lecture 8 Tree.
Discrete Structure Li Tak Sing( 李德成 ) Lectures
Discrete Structures Li Tak Sing( 李德成 ) Lecture note 2 1.
TREES. What is a tree ? An Abstract Data Type which emulates a tree structure with a set of linked nodes The nodes within a tree are organized in a hierarchical.
4.3 Recursive Definitions and Structural Induction Sometimes it is difficult to define an object explicitly. However, it may be easy to define this object.
Discrete Structures Trees (Ch. 11)
Chap 8 Trees Def 1: A tree is a connected,undirected, graph with no simple circuits. Ex1. Theorem1: An undirected graph is a tree if and only if there.
ICS 253: Discrete Structures I Induction and Recursion King Fahd University of Petroleum & Minerals Information & Computer Science Department.
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
Trees By P.Naga Srinivasu M.tech,(MBA). Basic Tree Concepts A tree consists of finite set of elements, called nodes, and a finite set of directed lines.
1 Section 4.3 Order Relations A binary relation is an partial order if it transitive and antisymmetric. If R is a partial order over the set S, we also.
M180: Data Structures & Algorithms in Java Trees & Binary Trees Arab Open University 1.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
Section 1.4ICOM 4075 (Spring, 2010) UPRM Department of Electrical and Computer Engineering University of Puerto Rico at Mayagüez Spring 2010 ICOM 4075:
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Discrete Structures CISC 2315 FALL 2010 Graphs & Trees.
Data Structures Lakshmish Ramaswamy. Tree Hierarchical data structure Several real-world systems have hierarchical concepts –Physical and biological systems.
1 Section 4.2 Equivalence Relations A binary relation is an equivalence relation if it has the three properties reflexive, symmetric, and transitive (RST).
Graphs and Trees Mathematical Structures for Computer Science Chapter 5 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesGraphs and Trees.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
1 Chapter Construction Techniques. 2 Section 3.1 Inductively Defined Sets To define a set S inductively is to do three things: Basis: Specify one.
Chapter 6 – Trees. Notice that in a tree, there is exactly one path from the root to each node.
1 Trees : Part 1 Reading: Section 4.1 Theory and Terminology Preorder, Postorder and Levelorder Traversals.
Discrete Mathematics Chapter 10 Trees.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
Discrete Structures Li Tak Sing( 李德成 ) Lectures
Trees Chapter 15.
Chapter 5 : Trees.
Redraw these graphs so that none of the line intersect except at the vertices B C D E F G H.
Discrete Mathematicsq
Source Code for Data Structures and Algorithm Analysis in C (Second Edition) – by Weiss
12. Graphs and Trees 2 Summary
Lecture 18. Basics and types of Trees
Graphs Chapter 11 Objectives Upon completion you will be able to:
Week nine-ten: Trees Trees.
COMPS263F Unit 2 Discrete Structures Li Tak Sing( 李德成 ) Room A
Trees.
Section 3.1 Inductively Defined Sets
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Chapter 4 (Part 2): Mathematical Reasoning, Induction & Recursion
Presentation transcript:

1 Chapter Elementary Notions and Notations

2 Section 1.3 Ordered Structures Tuples: Have order and can have repetitions. For example, (6, 7, 6) is a 3-tuple and ( ) is the empty tuple. We write (x 1, …, x n ) = (y 1, …, y n ) to mean x i = y i for 1 ≤ i ≤ n.

3 Cartesian Product Cartesian Product: A ╳ B = {(x, y) | x ∊ A and y ∊ B}. The definition extends to more than two sets. For example, A ╳ B ╳ C = {(x, y, z) | x ∊ A, y ∊ B, z ∊ C}. Notation: A 0 = {( )}, A 1 = {(x) | x ∊ A}, and in general, A n = {(x 1, …, x n ) | x i ∊ A}. Quiz (1 minute). Does (A ╳ B) ╳ C = A ╳ (B ╳ C)?

4 Lists Lists: Are like tuples but there is no random access. For example, is a list with 4 elements and <> is the empty list. The operations on lists are head, tail, and cons. For example, head( ) = a tail( ) = cons(a, ) = The set of lists whose elements are in A is denoted by lists(A). Quiz (1 minute). For L =, b, >, find head(L) and tail(L).

5 Strings Strings: Are like lists, but are represented as juxtaposed elements from a given alphabet. For example, if A = {a, b}, then some strings over A are: a, b, aa, ab, ba, bb, aaa, bbb. The empty string is denoted by ∧. The concatenation of two strings is their juxtaposition. For example, the concatenation of ab and bab is abbab. For any string s we have s ∧ = ∧ s = s. If s is a string, s n denotes the concatenation of s with itself n times. Also s 0 = ∧. For example, (ab) 3 = ababab.

6 Languages A language is a set of strings, usually taken over some alphabet. Notation: If A is an alphabet, then the set of all strings over A is denoted by A*. Example. Some languages over A are: Ø, { ∧ }, A, and A*. Example. {ab n a | n ∊ N} = {aa, aba, abba, abbba, … } is a language over {a, b}.

7 Language Operations Let L and M be languages. The product of L and M, denoted LM, is the language LM = {st | s ∊ L and t ∊ M}. Notation: L 0 = { ∧ }; and L n = {s 1 …s n | s i ∊ L}.

8 Quizzes Quiz (1 minute). What are the products LØ and L{ ∧ }? Quiz (1 minute). Solve for L in the equation { ∧, a, b}L = { ∧, a, b, aa, ba, aba, bba}.

9 closure The closure L* is the set of all possible concatenations of strings in L. So L* = L 0 U L 1 U … U L n U … Quiz (1 minute). What are { ∧ }* and Ø*?

10 Example Examine the structure of an arbitrary string x ∊ L*(ML)*. A solution: Use the definitions to write x in terms of strings in L and M. 1. Since x ∊ L*(ML)*, it follows that x = uv where u ∊ L* and v ∊ (ML)*. 2. Since u ∊ L*, either u = ∧ or u = s 1 …s n for some n where s i ∊ L. 3. Since v ∊ (ML)*, either v = ∧ or v = r 1 t 1 …r k t k for some k where r i ∊ M and t i ∊ L. So x has one of four forms: ∧, s 1 …s n, r 1 t 1 …r k t k, or s 1 …s n r 1 t 1 …r k t k.

11 Relations A relation is a set of tuples. If R is a relation and (x 1, …, x n ) ∊ R, we write R(x 1, …, x n ). We can usually represent a relation as a subset of some cartesian product. Example. Let R = {(0, 0), (1, 1), (4, 2), (9, 3), …, (n 2, n), …} = {(n 2, n) | n ∊ N}. We might call R the “is square of” relation on N. Notice also that R ⊂ N ╳ N. Notation: If R is binary, we can use infix to represent pairs in R. For example, from the previous example, we have (9, 3) ∊ R. So we can also write R(9, 3) or 9 R 3 or 9 is square of 3.

12 Relational Databases A relational database is a relation where the indexes of a tuple have associated names called attributes.

13 Example Let Students = {(x, y, z) | x is a Name, y is a Major, and z is Credits}. Who are the people majoring in CS? {x | (x, CS, z) ∊ Students, for some z}. Note: We need “for some z” to indicate that z is a variable. How many math majors are upper division students? | {x | (x, math, z) ∊ Students and z ≥ 90} |. What is the major of AbeLincoln? {y | (AbeLincoln, y, z) ∊ Students, for some z}. What is the history department database of names and their credits? {(x, z) | (x, history, z) ∊ Students}.

14 Counting Tuples (or strings or lists) Product Rule: | A ╳ B | = | A | | B | and | A n | = | A | n. Example. If A = {a, b} and B = {1, 2, 3}, then A ╳ B = {(a, 1), (a, 2), (a, 3), (b, 1), (b, 2), (b, 3)}. So | A ╳ B | = 6 = (2)(3) = | A | | B |.

15 Example Count the number of strings of length 8 over A = {a, b, c} that begin with either a or c and have at least one b. A Solution: Split the problem up into easier problems and combine the results (divide and conquer). Let U be the universe consisting of the strings over A of length 8 that begin with either a or c. Let B be the subset of U consisting of strings with no b’s. Then the set of strings to count is U – B, as pictured. U-BU B

16 Example (cont’d) It is easy to calculate the cardinality of U – B: | U – B | = | U | – | U ∩ B | = | U | – | B | (since B is a subset of U) It is also easy to count U because it has the same cardinality as the set {a, c} ╳ A 7, which is | {a, c} ╳ A 7 | = | {a, c} | | A 7 | = | {a, c} | | A | 7 = (2)3 7. It is also easy to count B because it has the same cardinality as the set {a, c} 8, which is | {a, c} 8 | = | {a, c} | 8 = 2 8. So we have the answer: | U – B | = | U | – | U ∩ B | = | U | – | B | = (2)3 7 – 2 8, which is 4118.

17 Section 1.4 Graphs and Trees A graph is set of objects called vertices or nodes where some pairs of objects may be connected by edges. (A directed graph has edges that point in one direction.)

18 Example Draw a graph of the South American countries that touch the Pacific Ocean and their neighbors, where the vertices are countries and an edge indicates a common border. Vertices = {Co, V, E, Br, P, Bo, Ch, A} Edges = {{Co, V}, {Co, E}, ….}. Co V E P Ch Bo Br A

19 Some definitions A path from vertex x 0 to x n is a sequence of edges that we denote by vertices x 0, x 1, …, x n, where there is an edge from x i–1 to x i for 1≤ i ≤ n. The length of a path is the number of edges. A cycle is a path with distinct edges that begins and ends at the same vertex. Example. A, Bo, A, is not a cycle since the edge{A, Bo} occurs twice. A, Bo, Br, A, is a cycle.

20 Quiz (1 minute) What is a longest path from A to V with distinct edges and no cycles? Answer: The length is 6. For example, A, Bo, Br, P, E, Co, V.

21 n-colorable A graph is n-colorable if it’s vertices can be colored with n colors with distinct colors for adjacent vertices. The chromatic number of a graph is the smallest such n. Quiz (1 minute). What is the chromatic number of the example graph?

22 Graph Traversals A graph traversal starts at some vertex v and visits all vertices x that can be reached by a path from v to x. But don’t visit any vertex more than once.

23 Breadth-First If the graph has n vertices then start with a vertex v and do the following: for k := 0 to n – 1 do visit(v, k) od where visit(v, k) visits all x not visited if there is a path from v to x of length k.

24 Quizzes Use the pictured graph for the following quizzes. Quiz (1 minute). Find a breadth- first traversal that starts at F. One answer: F, H, D, G, B, A, E, C. Quiz (1 minute). Find a breadth- first traversal that starts at C. One answer: C, A, E, D, B, F, H, G. A B D F H G E C

25 Depth-First Start at a vertex v and call the procedure D(v), which is defined as follows: D(v): if v has not been visited then visit(v); for each edge from v to x do D(x) od fi

26 Quizzes Quiz (1 minute). Find a depth-first traversal of the pictured graph that starts at F. One answer: F, H, G, D, B, A, C, E. Quiz (1 minute). Find a depth-first traversal of the pictured graph that starts at E. One answer: E, D, F, H, G, A, C, B.

27 Trees A tree is a connected graph (a path between any two points) with no cycles. Most trees are oriented so that they look like upside-down trees, such as the tree pictured. The top node is the root, the nodes directly below a node are its children, the node directly above a node is the parent, the bottom nodes are leaves, and the height or depth of the tree is the length of the longest path of distinct edges from root to a leaf. Example. For this tree the root is A. The children of A are B, C, D. D is the parent of G. The height or depth of the tree is 3. The leaves are E, F, C, H, I. A BCD EFG H I

28 A Recursive Definition Any node of a tree is the root of a subtree. One way to represent a tree is as a list whose head is the root of the tree and whose tail is the list of subtrees, where each subtree is represented in the same way. Example. The pictured tree can be represented by the list, >,,, >>>.

29 Expression Tree Any algebraic expression can be represented as a tree. For example, the tree for the expression (x – y) + log(z + w) is pictured to the right. Quiz (1 minute). Do a depth-first (left to right) traversal. Answer: + – x y log + z w. This is the prefix form of the expression. + - log x y + z w

30 Binary Trees A binary tree is either empty, denoted by <>, or each node has two subtrees that are binary trees and are called the left and right subtrees of the node. If a binary tree is not empty, we’ll represent it as a list of the form, where x is the root and L and R are the left and right subtrees, respectively. Example. The binary tree with a single node x is denoted by, x, <>>.

31 binary search tree A binary search tree represents ordered information, where the predecessors and successors of a node are in its left and right subtrees, respectively. Example. A binary search tree for the first six prime numbers is pictured

32 Spanning Trees A spanning tree for a connected graph is a tree whose nodes are the nodes of the graph and whose edges are a subset of the edges of the graph. A minimal spanning tree minimizes the sum of weights on the edges of all spanning trees.

33 Example Use Prim’s algorithm to construct a minimal spanning tree for the pictured graph, starting with node D. Solution: A minimal spanning tree is constructed in 4 steps AB C D E B D 1111 BBB DD D CC C AA 1 1 E 2

34 The End of Chapter 1 – 2