Chapter 6 – Trees. Notice that in a tree, there is exactly one path from the root to each node.

Slides:



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

Andreas Savva Data Structures Chapter 5 Recursion.
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.
Computer Science 2 Data Structures and Algorithms V section 2 Introduction to Trees Professor: Evan Korth New York University.
CS2420: Lecture 13 Vladimir Kulyukin Computer Science Department Utah State University.
Chapter 4: Trees General Tree Concepts Binary Trees Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm Analysis in Java.
1 Trees. 2 Outline –Tree Structures –Tree Node Level and Path Length –Binary Tree Definition –Binary Tree Nodes –Binary Search Trees.
CHAPTER 12 Trees. 2 Tree Definition A tree is a non-linear structure, consisting of nodes and links Links: The links are represented by ordered pairs.
CSC 2300 Data Structures & Algorithms February 6, 2007 Chapter 4. Trees.
Binary Trees Chapter 6.
Chapter 18 - basic definitions - binary trees - tree traversals Intro. to Trees 1CSCI 3333 Data Structures.
1 Chapter 18 Trees Objective To learn general trees and recursion binary trees and recursion tree traversal.
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
1 Trees Tree nomenclature Implementation strategies Traversals –Depth-first –Breadth-first Implementing binary search trees.
Chapter 19: Binary Trees. Objectives In this chapter, you will: – Learn about binary trees – Explore various binary tree traversal algorithms – Organize.
CS261 Data Structures Trees Introduction and Applications.
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.
CS Data Structures Chapter 5 Trees. Chapter 5 Trees: Outline  Introduction  Representation Of Trees  Binary Trees  Binary Tree Traversals 
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 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,
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.
CS-2852 Data Structures LECTURE 11 Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Data Structures TREES.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
CE 221 Data Structures and Algorithms Chapter 4: Trees (Binary) Text: Read Weiss, §4.1 – 4.2 1Izmir University of Economics.
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
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.
Binary Tree. Some Terminologies Short review on binary tree Tree traversals Binary Search Tree (BST)‏ Questions.
24 January Trees CSE 2011 Winter Trees Linear access time of linked lists is prohibitive  Does there exist any simple data structure for.
Data Structures Lakshmish Ramaswamy. Tree Hierarchical data structure Several real-world systems have hierarchical concepts –Physical and biological systems.
Trees Ellen Walker CPSC 201 Data Structures Hiram College.
CHAPTER 11 TREES INTRODUCTION TO TREES ► A tree is a connected undirected graph with no simple circuit. ► An undirected graph is a tree if and only.
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.
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.
TREES General trees Binary trees Binary search trees AVL trees Balanced and Threaded trees.
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 Trees : Part 1 Reading: Section 4.1 Theory and Terminology Preorder, Postorder and Levelorder Traversals.
Trees CSIT 402 Data Structures II 1. 2 Why Do We Need Trees? Lists, Stacks, and Queues are linear relationships Information often contains hierarchical.
1 CMSC 341 Introduction to Trees Textbook sections:
Trees A non-linear implementation for collection classes.
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.
TREES From root to leaf. Trees  A tree is a non-linear collection  The elements are in a hierarchical arrangement  The elements are not accessible.
CSE 373 Data Structures Lecture 7
Trees Chapter 15.
Lecture 1 (UNIT -4) TREE SUNIL KUMAR CIT-UPES.
Trees.
Source Code for Data Structures and Algorithm Analysis in C (Second Edition) – by Weiss
Tree.
Section 8.1 Trees.
CHAPTER 4 Trees.
Binary Trees, Binary Search Trees
TREES General trees Binary trees Binary search trees AVL trees
Trees.
Trees CMSC 202, Version 5/02.
Trees (Part 1, Theoretical)
CMSC 202 Trees.
Binary Trees, Binary Search Trees
Chapter 20: Binary Trees.
Binary Trees.
Stacks A list where insertions and deletions can occur only at the end of the list. linked list or array implementation topOfStack  operations:
General Tree Concepts Binary Trees
Binary Trees, Binary Search Trees
Presentation transcript:

Chapter 6 – Trees

Notice that in a tree, there is exactly one path from the root to each node

Trees – linked lists, stacks, and queues which are linear data structures – A tree is a nonlinear data structure: a tree is a collection of nodes connected by edges root at the top the leaves (i.e., terminal nodes) at the bottom The root has no parent; Leaves, on the other hand, have no children, or rather, their children are empty structures

A Recursive Definition 1. An empty structure is a tree (a tree is a collection of nodes and the collection can be empty) 2. If T 1, …, T k are trees, then the structure whose root has as its children the roots of T 1, …, T k is also a tree 3. Only structures generated by rules 1 and 2 are trees

A Recursive Definition (cont’d) ROOT OF TREE T T1T1 T2T2 T3T3 TkTk SUBTREES

An Example A BC DE F G H I N nodes, N-1 edges in a tree.

Some Definitions Nodes with no children are leaves: (C,E,F,H,I), they are also called external nodes. Nodes which are not leaves are called internal nodes Nodes with the same parents are siblings: (B,C,D,E) and (G,H) A path from node n i to node n j is the sequence of directed edges from n i to n j The level or depth of a node n i is the number of edges from the root to n i. The depth of the root is 0

Some Definitions (cont’d) The height of a node n i is the length of the longest path from n i to a leaf. The height of a leaf node is 0 The height of a tree is equal to the height of the root

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

Binary Trees – A Recursive Definition 1. An empty structure is a binary tree 2. If T 1 and T 2 are binary trees, then the structure whose root has as its children the roots of T 1 and T 2 is also a binary tree 3. Only structures generated by rules 1 and 2 are binary trees

Trees vs. Binary Trees No node in a binary tree may have more than 2 children, whereas there is no limit on the number of children of a node in a tree