Objective: Understand Concepts related to trees.

Slides:



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

Introduction to Trees Chapter 6 Objectives
Data Structures: A Pseudocode Approach with C 1 Chapter 6 Objectives Upon completion you will be able to: Understand and use basic tree terminology and.
Computer Science C++ High School Level By Guillermo Moreno.
CS 171: Introduction to Computer Science II
Data Structures: Trees i206 Fall 2010 John Chuang Some slides adapted from Marti Hearst, Brian Hayes, or Glenn Brookshear.
Department of Computer Science University of Maryland, College Park
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
CS 206 Introduction to Computer Science II 09 / 22 / 2008 Instructor: Michael Eckmann.
Rooted Trees. More definitions parent of d child of c sibling of d ancestor of d descendants of g leaf internal vertex subtree root.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 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.
Binary Trees Chapter 6.
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.
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.
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.
Tree (new ADT) Terminology:  A tree is a collection of elements (nodes)  Each node may have 0 or more successors (called children)  How many does a.
Computer Science: A Structured Programming Approach Using C Trees Trees are used extensively in computer science to represent algebraic formulas;
Trees CS 105. L9: Trees Slide 2 Definition The Tree Data Structure stores objects (nodes) hierarchically nodes have parent-child relationships operations.
Lecture1 introductions and Tree Data Structures 11/12/20151.
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.
Topics Definition and Application of Binary Trees Binary Search Tree Operations.
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
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.
Binary Search Trees Lecture 5 1. Binary search tree sort 2.
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.
AVL trees1 AVL Trees Height of a node : The height of a leaf is 1. The height of a null pointer is zero. The height of an internal node is the maximum.
BINARY TREES A BINARY TREE t IS EITHER EMPTY OR CONSISTS OF AN ITEM, CALLED THE ROOT ITEM, AND TWO DISTINCT BINARY TREES, CALLED THE LEFT SUBTREE AND.
Trees (Unit 7).
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
Tree Representation and Terminology Binary Trees Binary Search Trees Pointer-Based Representation of a Binary Tree Array-Based Representation of a Binary.
Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
AA Trees.
Fundamentals of Programming II Introduction to Trees
Recursive Objects (Part 4)
Binary search tree. Removing a node
CISC220 Fall 2009 James Atlas Lecture 13: Binary Trees.
Lecture 17 Red-Black Trees
Binary Trees "A tree may grow a thousand feet tall, but its leaves will return to its roots." -Chinese Proverb.
Section 8.1 Trees.
Tree traversal from Introduction to Trees Chapter 6 Objectives
Data Structures & Algorithm Design
Lecture 18. Basics and types of Trees
CHAPTER 4 Trees.
Tonga Institute of Higher Education
ITEC 2620M Introduction to Data Structures
Binary Tree and General Tree
TREES General trees Binary trees Binary search trees AVL trees
CS223 Advanced Data Structures and Algorithms
Trees and Binary Trees.
Abstract Data Structures
Trees.
B-Tree.
Trees Definitions Implementation Traversals K-ary Trees
Trees (Part 1, Theoretical)
Lecture 36 Section 12.2 Mon, Apr 23, 2007
Trees.
Tree.
Trees.
Chapter 20: Binary Trees.
Binary Trees.
Tree and its terminologies
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Introduction to Trees Chapter 6 Objectives
Presentation transcript:

Objective: Understand Concepts related to trees. Introduction to Trees Computer Science 4 Reference: Objective: Understand Concepts related to trees.

What is a Binary Tree? Recall that in a linked list each node contains a link to another similar node. In a binary tree, each node contains a link to two other similar nodes. This leads to a linked data structure that “branches”.

A Binary tree B G O D W A T U

Some Terms Every binary tree has a node at the “top”. No other node references it. This is called the root node. Every binary tree has nodes where both references are null. I.e. it does not point to any lower nodes These are called leaf nodes.

Root Node B G O D W A T U

Leaf Nodes B G O D W A T U

Subtrees The references contained in a binary tree node are traditionally called the left and right childern. Each node can be said to have a left and right subtree Left subtree the left child and all its descendents. Right subtree includes the right child and all its descendants Note that a subtree (like any binary tree) may be empty.

Node B’s left subtree B G O D W A T U

Node B’s right subtree B G O D W A T U

Some More Terms The distance between a node and the root node is called its level Note that this makes the root node level 0 The maximum level in a tree is called its height. The maximum number of nodes on level L 1 for 0, 2 for 1, 4 for 2, 8 for 3, 16 for 4 In general 2L. The maximum number of nodes in a tree of height H 1 for 0, 3 for 1, 7 for 2, 15 for 3 In general, is 2H+1-1

This tree’s height is 3 Level B 1 G O D W A 2 T 3 U

Parent and Child Nodes When nodeA points to nodeB, we say NodeA is nodeB’s parent NodeB is nodeA’s child When nodeA is above nodeC in the tree, we say NodeA is an ancestor of NodeC NodeC is a descendant of NodeA

Node O is the parent of Node A B G O D W A T U

Node O is the child of Node B G O D W A T U

Node T is a descendant of node G B G O D W A T U

Node B is an ancestor of node W G O D W A T U

Minimum Height of a Binary Tree The maximum number of nodes in a binary tree of height H is 2H+1-1 Based on this, what’s the minimum number of levels of a tree containing N nodes. If N is 20 (1), need 0 levels. If N is 21 (2), need 1 level. If N is 22 (4), need 2 levels. If N is 23 (1), need 3 levels. If N is 2p, need P levels. Therefore need Floor(Log2N) levels to store N nodes.

Summary Each node in a binary contains references to two other nodes. Root node at the top of the tree Leaf nodes don’t reference any other nodes Height of the tree is the number of levels Parents and children, ancestors and descendants. Can store 2L nodes on level L Minimum height of a tree with N items is Log2N