Lecture 17: Trees and Networks I Discrete Mathematical Structures: Theory and Applications.

Slides:



Advertisements
Similar presentations
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 20: Binary Trees.
Advertisements

Advanced Data Structures
CMPS 2433 Discrete Structures Chapter 5 - Trees R. HALVERSON – MIDWESTERN STATE UNIVERSITY.
Binary Trees Terminology A graph G = is a collection of nodes and edges. An edge (v 1,v 2 ) is a pair of vertices that are directly connected. A path,
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Tree Traversal. Traversal Algorithms preorder inorder postorder.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
MATH 310, FALL 2003 (Combinatorial Problem Solving) Lecture 14, Wednesday, October 1.
Transforming Infix to Postfix
Data Structures Using C++ 2E Chapter 11 Binary Trees and B-Trees.
1 Section 9.2 Tree Applications. 2 Binary Search Trees Goal is implementation of an efficient searching algorithm Binary Search Tree: –binary tree in.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 20: Binary Trees.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Trees.
KNURE, Software department, Ph , N.V. Bilous Faculty of computer sciences Software department, KNURE The trees.
Data Structures Using C++1 Chapter 11 Binary Trees.
Data Structures Using C++1 Chapter 11 Binary Trees.
Types of Binary Trees Introduction. Types of Binary Trees There are several types of binary trees possible each with its own properties. Few important.
Review Binary Tree Binary Tree Representation Array Representation Link List Representation Operations on Binary Trees Traversing Binary Trees Pre-Order.
Chapter 19: Binary Trees. Objectives In this chapter, you will: – Learn about binary trees – Explore various binary tree traversal algorithms – Organize.
Lecture 17 Non-Linear data structures Richard Gesick.
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
CISC220 Fall 2009 James Atlas Lecture 13: Trees. Skip Lists.
Tree Data Structures.
Chapter 19: Binary Trees Java Programming: Program Design Including Data Structures Program Design Including Data Structures.
Trees A tree is a set of nodes which are connected by branches to other nodes in a 'tree-like' structure. There is a special node called the root from.
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.
Discrete Structures Trees (Ch. 11)
Review 1 Queue Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
Tree Traversals, TreeSort 20 February Expression Tree Leaves are operands Interior nodes are operators A binary tree to represent (A - B) + C.
Binary Trees In computer science, a binary tree is a tree data structure in which each node has at most two children, which are referred to as the left.
Discrete Mathematics Chapter 5 Trees.
1 Chapter 7 Objectives Upon completion you will be able to: Create and implement binary search trees Understand the operation of the binary search tree.
M180: Data Structures & Algorithms in Java Trees & Binary Trees Arab Open University 1.
Binary Tree. Some Terminologies Short review on binary tree Tree traversals Binary Search Tree (BST)‏ Questions.
1 Binary Trees and Binary Search Trees Based on Dale & Co: Object-Oriented Data Structures using C++ (graphics)
Lecture - 11 on Data Structures. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Threaded Trees Binary trees have a lot of wasted space: the leaf nodes each.
Binary Search Trees (BST)
Trees Chapter 10. CS 308 2Chapter Trees Preview: Preview: The data organizations presented in previous chapters are linear, in that items are one.
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.
Data Structures Using C++ 2E Chapter 11 Binary Trees.
Trees Ellen Walker CPSC 201 Data Structures Hiram College.
Binary Tree Implementation. Binary Search Trees (BST) Nodes in Left subtree has smaller values Nodes in right subtree has bigger values.
1 Joe Meehean. A A B B D D I I C C E E X X A A B B D D I I C C E E X X  Terminology each circle is a node pointers are edges topmost node is the root.
CMSC 202, Version 5/02 1 Trees. CMSC 202, Version 5/02 2 Tree Basics 1.A tree is a set of nodes. 2.A tree may be empty (i.e., contain no nodes). 3.If.
Foundation of Computing Systems Lecture 4 Trees: Part I.
Hello Everyone!!! 1. Tree And Graphs 2 Features of Trees  Tree Nodes Each node have 0 or more children A node have must one parent  Binary tree Tree.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
1 Trees : Part 1 Reading: Section 4.1 Theory and Terminology Preorder, Postorder and Levelorder Traversals.
Trees By JJ Shepherd. Introduction Last time we discussed searching and sorting in a more efficient way Divide and Conquer – Binary Search – Merge Sort.
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)
1 Trees. 2 Trees Trees. Binary Trees Tree Traversal.
Topic 2: binary Trees COMP2003J: Data Structures and Algorithms 2
Trees Chapter 15.
Data Structure and Algorithms
CSCE 210 Data Structures and Algorithms
Binary Trees and Binary Search Trees
Binary Search Tree (BST)
Source Code for Data Structures and Algorithm Analysis in C (Second Edition) – by Weiss
Tree.
Section 8.1 Trees.
CS223 Advanced Data Structures and Algorithms
Section 9.3 by Andrew Watkins
Trees.
Chapter 20: Binary Trees.
Non-Linear data structures
Data Structures Using C++ 2E
A Binary Tree is a tree in which each node has at most 2 children
Presentation transcript:

Lecture 17: Trees and Networks I Discrete Mathematical Structures: Theory and Applications

Discrete Mathematical Structures: Theory and Applications 2 Learning Objectives  Learn the basic properties of trees  Explore applications of trees  Learn about networks

Discrete Mathematical Structures: Theory and Applications 3 Trees  Each atom of a chemical compound is represented by a point in a plane  Atomic bonds are represented by lines  Shown in Figure 11.1 for the chemical compound with the formula C 4 H 10.

Discrete Mathematical Structures: Theory and Applications 4 Trees  In chemistry, chemical compounds with formula C k H 2k+2 are known as paraffins, which contain k carbon atoms and 2k + 2 hydrogen atoms.  In the graphical representation, each of the carbon atoms corresponds to a vertex of degree 4 and each of the hydrogen atoms corresponds to a vertex of degree 1.  For the same chemical formula C 4 H 10, the graph shown in Figure 11.2 is also a representation.

Discrete Mathematical Structures: Theory and Applications 5 Trees  These graphs are connected and have no cycles. Hence, each of these graphs is a tree.

Discrete Mathematical Structures: Theory and Applications 6 Trees  Consider the graphs shown in Figure Each of these graphs is connected.  However, each of these graphs has a cycle. Hence, none of these graphs is a tree.

Discrete Mathematical Structures: Theory and Applications 7 Trees

Discrete Mathematical Structures: Theory and Applications 8 Trees

Discrete Mathematical Structures: Theory and Applications 9 Trees

Discrete Mathematical Structures: Theory and Applications 10 Rooted Tree

Discrete Mathematical Structures: Theory and Applications 11 Rooted Tree  The level of a vertex v is the length of the path from the root to v.

Discrete Mathematical Structures: Theory and Applications 12

Discrete Mathematical Structures: Theory and Applications 13

Discrete Mathematical Structures: Theory and Applications 14

Discrete Mathematical Structures: Theory and Applications 15  The root of this binary tree is A. Vertex B is the left child of A and vertex C is the right child of A. From the diagram, it follows that B is the root of the left subtree of A, i.e., the left subtree of the root. Similarly, C is the root of the right subtree of A, i.e., the right subtree of the root. L A = {B, D, E, G} and R A = {C, F,H}. Moreover, for vertex F, the left child is H and F has no right child.

Discrete Mathematical Structures: Theory and Applications 16 Rooted Tree

Discrete Mathematical Structures: Theory and Applications 17 Rooted Tree  Binary Tree Traversal  Item insertion, deletion, and lookup operations require the binary tree to be traversed. Thus, the most common operation performed on a binary tree is to traverse the binary tree, or visit each vertex of the binary tree. The traversal must start at the root because one is typically given a reference to the root. For each vertex, there are two choices.  Visit the vertex first.  Visit the subtrees first.

Discrete Mathematical Structures: Theory and Applications 18 Rooted Tree  Inorder Traversal: In an inorder traversal, the binary tree is traversed as follows.  Traverse the left subtree.  Visit the vertex.  Traverse the right subtree.

Discrete Mathematical Structures: Theory and Applications 19 Rooted Tree  Preorder Traversal: In a preorder traversal, the binary tree is traversed as follows.  Visit the vertex.  Traverse the left subtree.  Traverse the right subtree.

Discrete Mathematical Structures: Theory and Applications 20 Rooted Tree  Postorder Traversal: In a postorder traversal, the binary tree is traversed as follows.  Traverse the left subtree.  Traverse the right subtree.  Visit the vertex.

Discrete Mathematical Structures: Theory and Applications 21 Rooted Tree  Each of these traversal algorithms is recursive.  The listing of the vertices produced by the inorder traversal of a binary tree is called the inorder sequence.  The listing of the vertices produced by the preorder traversal of a binary tree is called the preorder sequence.  The listing of the vertices produced by the postorder traversal of a binary tree is called the postorder sequence.

Discrete Mathematical Structures: Theory and Applications 22 Rooted Tree  Binary Search Trees  To determine whether 50 is in the binary tree, any of the previous traversal algorithms to visit each vertex and compare the search item with the data stored in the vertex can be used.  However, this could require traversal of a large part of the binary tree, so the search would be slow.  Each vertex in the binary tree must be visited until either the item is found or the entire binary tree has been traversed because no criteria exist to guide the search.

Discrete Mathematical Structures: Theory and Applications 23 Rooted Tree  Binary Search Trees  In the binary tree in Figure 11.22, the value of each vertex is larger than the values of the vertices in its left subtree and smaller than the values of the vertices in its right subtree.  The binary tree in Figure is a special type of binary tree, called a binary search tree.

Discrete Mathematical Structures: Theory and Applications 24