CS2420: Lecture 13 Vladimir Kulyukin Computer Science Department Utah State University.

Slides:



Advertisements
Similar presentations
COSC2007 Data Structures II Chapter 10 Trees I. 2 Topics Terminology.
Advertisements

22C:19 Discrete Structures Trees Spring 2014 Sukumar Ghosh.
Introduction to Trees Chapter 6 Objectives
Binary Trees Chapter 6. Linked Lists Suck By now you realize that the title to this slide is true… By now you realize that the title to this slide is.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
Binary Trees, Binary Search Trees COMP171 Fall 2006.
CS 171: Introduction to Computer Science II
Computer Science 2 Data Structures and Algorithms V section 2 Introduction to Trees Professor: Evan Korth New York University.
CS2420: Lecture 24 Vladimir Kulyukin Computer Science Department Utah State University.
CS2420: Lecture 19 Vladimir Kulyukin Computer Science Department Utah State University.
1 Trees. 2 Outline –Tree Structures –Tree Node Level and Path Length –Binary Tree Definition –Binary Tree Nodes –Binary Search Trees.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
CS 206 Introduction to Computer Science II 09 / 22 / 2008 Instructor: Michael Eckmann.
CS2420: Lecture 27 Vladimir Kulyukin Computer Science Department Utah State University.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
1 Chapter 7 Trees. 2 What is a Tree In computer science, a tree is an abstract model of a hierarchical structure A tree consists of nodes with a parent-child.
CS2420: Lecture 15 Vladimir Kulyukin Computer Science Department Utah State University.
Trees CMSC 433 Chapter 8.1 Nelson Padua-Perez Bill Pugh.
CSC 2300 Data Structures & Algorithms February 6, 2007 Chapter 4. Trees.
Binary Trees Chapter 6.
Version TCSS 342, Winter 2006 Lecture Notes Trees Binary Trees Binary Search Trees.
Binary Tree. Binary Trees – An Informal Definition A binary tree is a tree in which no node can have more than two children Each node has 0, 1, or 2 children.
COSC2007 Data Structures II
CS261 Data Structures Trees Introduction and Applications.
CS Data Structures Chapter 5 Trees. Chapter 5 Trees: Outline  Introduction  Representation Of Trees  Binary Trees  Binary Tree Traversals 
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
CMSC 341 Introduction to Trees. 8/3/2007 UMBC CMSC 341 TreeIntro 2 Tree ADT Tree definition  A tree is a set of nodes which may be empty  If not empty,
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.
Binary Trees. Binary Tree Finite (possibly empty) collection of elements A nonempty binary tree has a root element The remaining elements (if any) are.
Chapter 6 Binary Trees. 6.1 Trees, Binary Trees, and Binary Search Trees Linked lists usually are more flexible than arrays, but it is difficult to use.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Computer Science: A Structured Programming Approach Using C Trees Trees are used extensively in computer science to represent algebraic formulas;
CS-2852 Data Structures LECTURE 11 Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Data Structures TREES.
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.
Disusun Oleh : Budi Arifitama Pertemuan ke-8. Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 6.
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.
M180: Data Structures & Algorithms in Java Trees & Binary Trees Arab Open University 1.
CMSC 341 Introduction to Trees. 2/21/20062 Tree ADT Tree definition –A tree is a set of nodes which may be empty –If not empty, then there is a distinguished.
DATA STRUCTURE BS(IT)3rd. Tree An Introduction By Yasir Mustafa Roll No. BS(IT) Bahauddin Zakariya University, Multan.
24 January Trees CSE 2011 Winter Trees Linear access time of linked lists is prohibitive  Does there exist any simple data structure for.
1Computer Sciences. 2 HEAP SORT TUTORIAL 4 Objective O(n lg n) worst case like merge sort. Sorts in place like insertion sort. A heap can be stored as.
1 Trees General Trees  Nonrecursive definition: a tree consists of a set of nodes and a set of directed edges that connect pairs of nodes.
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.
1 Trees General Trees  Nonrecursive definition: a tree consists of a set of nodes and a set of directed edges that connect pairs of nodes.
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.
Question 4 Tutorial 8. Part A Insert 20, 10, 15, 5,7, 30, 25, 18, 37, 12 and 40 in sequence into an empty binary tree
Fundamentals of Algorithms MCS - 2 Lecture # 17. Binary Search Trees.
1 CMSC 341 Introduction to Trees Textbook sections:
1 Trees. 2 Trees Trees. Binary Trees Tree Traversal.
Tree Representation and Terminology Binary Trees Binary Search Trees Pointer-Based Representation of a Binary Tree Array-Based Representation of a Binary.
What is a Tree? Formally, we define a tree T as a set of nodes storing elements such that the nodes have a parent-child relationship, that satisfies the.
Decision Trees DEFINITION: DECISION TREE A decision tree is a tree in which the internal nodes represent actions, the arcs represent outcomes of an action,
Trees Chapter 15.
Lecture 1 (UNIT -4) TREE SUNIL KUMAR CIT-UPES.
Trees.
Data Structures & Algorithm Design
Binary Trees, Binary Search Trees
CS223 Advanced Data Structures and Algorithms
Trees (Part 1, Theoretical)
CSE 373, Copyright S. Tanimoto, 2002 Binary Trees -
Lecture 36 Section 12.2 Mon, Apr 23, 2007
Binary Trees, Binary Search Trees
Trees.
CSE 373, Copyright S. Tanimoto, 2001 Binary Trees -
Binary Trees, Binary Search Trees
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Presentation transcript:

CS2420: Lecture 13 Vladimir Kulyukin Computer Science Department Utah State University

Outline Trees (Chapter 4) Sorting Algorithms (Chapter 7)

Trees: Terminology A tree is a set of nodes and a set of directed edges. A rooted tree has the following properties: –One node is the root. –Every node, other than the root, is connected by an edge from exactly one other node. The first node is called a child and the second a parent. Every child has exactly a unique parent. –A path is a sequence of nodes such that every preceding node is the parent of its successor. –There is a unique path from the root to every node in the tree. –The length of the path is the number of edges in it.

Tree: Recursive Definition An empty set of nodes and edges is a tree. A tree consists of a root and zero or more non-empty sub-trees T 1, …, T n, each of whose roots receives an edge from the root.

Tree: Example A B CD EF H G A is the parent of B,C, D. A, B, F, H is a path. A, C, G is not a path.

Depth and Height There are two important numbers associated with every node in a tree: depth and height. The depth of a node N is the length of the path from the root to N. Depth goes from the root to the node. The height of a node N is the length of the longest path from N to a leaf. Height goes from the node to a leaf.

Height & Depth: Example 1 H = 0; D = 0

Height & Depth: Example 2 H=0; D=1 H=1; D=0

Height & Depth: Example 3 H=2; D=0 H=1; D=1 H=0;D=2

Height & Depth: Example 4 A B CD EF H G H=3;D=0 H=2;D=1H=0;D=1 H=1;D=1 H=0;D=2H=1;D=2 H=0;D=3 H=0;D=2

Binary Trees An empty tree is binary. If a binary tree is not empty, it has a unique node called root. Each node in a binary tree has exactly two sub-trees: the left sub-tree and the right sub-tree. The order of the sub-trees matters.

Binary Tree: Complete and Full A full binary tree is a tree where every node is either a leaf or has exactly two children. A complete binary tree of height h is a tree where every position is filled at every level from 0 to h.

Complete vs. Full … And they wandered in the wilderness until one of them uttered: Completeness is full, but fullness is incomplete. And they all became enlightened…

Full Tree: Example A B C EF

Complete Tree: Example A B C DEFG

Binary Tree: Heights and Leaves For any binary tree with L leaves and height H:

A Decision Tree Each internal node represents a decision. Each leaf represents an outcome.

Decision Trees: Observations Different leaves may represent the same outcome because there may be several paths to the same outcome. The number of leaves should be at least as large as the number of outcomes. Number of decisions, in the worst case, is equal to the height of the decision tree for some algorithm.

A Decision Tree: Example a < b a < cb < c acbc YES NO YESNOYESNO Decision Tree for Finding a Minimum of Three Numbers.

Decision Trees for Comparison Sorting Algorithms Given an array A of N elements. Each outcome (leaf) is a sorted array. Each outcome is a permutation of N elements. We will call it P(A). There are N! possible outcomes. Each decision node is a comparison of two elements.