A Binary Tree is a tree in which each node has at most 2 children

Slides:



Advertisements
Similar presentations
CS Fall 2012, Lab 08 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /17/2015 Tree - Data Structure  Basic.
Advertisements

Chapter 10: Trees. Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.
SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.
Binary Search Trees CSE 331 Section 2 James Daly.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
CS 171: Introduction to Computer Science II
Chapter 4: Trees General Tree Concepts Binary Trees Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm Analysis in Java.
Tree Traversal. Traversal Algorithms preorder inorder postorder.
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.
Unit 11a 1 Unit 11: Data Structures & Complexity H We discuss in this unit Graphs and trees Binary search trees Hashing functions Recursive sorting: quicksort,
1 Section 9.2 Tree Applications. 2 Binary Search Trees Goal is implementation of an efficient searching algorithm Binary Search Tree: –binary tree in.
Trees and Tree Traversals Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.
Types of Binary Trees Introduction. Types of Binary Trees There are several types of binary trees possible each with its own properties. Few important.
TREES A tree's a tree. How many more do you need to look at? --Ronald Reagan.
Chapter 19: Binary Trees. Objectives In this chapter, you will: – Learn about binary trees – Explore various binary tree traversal algorithms – Organize.
Trees Chapter 15 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
CS Data Structures Chapter 15 Trees Mehmet H Gunes
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
1 Trees 2 Binary trees Section Binary Trees Definition: A binary tree is a rooted tree in which no vertex has more than two children –Left and.
© 2011 Pearson Addison-Wesley. All rights reserved 11 B-1 Chapter 11 (continued) Trees.
Emma Price 1.  To be able to:  Explain what a binary tree is.  To traverse a binary tree using the three different methods. 2.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
CISC220 Fall 2009 James Atlas Lecture 13: Trees. Skip Lists.
Binary Trees 2 Overview Trees. Terminology. Traversal of Binary Trees. Expression Trees. Binary Search Trees.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Tree Data Structures.
Compiled by: Dr. Mohammad Omar Alhawarat
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
Binary Search Tree Traversal Methods. How are they different from Binary Trees?  In computer science, a binary tree is a tree data structure in which.
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
Trees 2: Section 4.2 and 4.3 Binary trees. Binary Trees Definition: A binary tree is a rooted tree in which no vertex has more than two children
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.
Binary Search Trees (BST)
Lecture 17: Trees and Networks I Discrete Mathematical Structures: Theory and Applications.
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.
1 Trees 2 Binary trees Section Binary Trees Definition: A binary tree is a rooted tree in which no vertex has more than two children –Left and.
Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 7 Objectives Create and implement binary search trees Understand the operation.
Binary Tree Implementation. Binary Search Trees (BST) Nodes in Left subtree has smaller values Nodes in right subtree has bigger values.
Foundation of Computing Systems Lecture 4 Trees: Part I.
Lecture 7: Searching a Tree Neil Ghani University of Strathclyde.
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.
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.
Balanced Search Trees 2-3 Trees AVL Trees Red-Black Trees
Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Trees Chapter 15.
CSCE 210 Data Structures and Algorithms
Trees Chapter 11 (continued)
Recursive Objects (Part 4)
Trees Chapter 11 (continued)
Binary Search Tree (BST)
Source Code for Data Structures and Algorithm Analysis in C (Second Edition) – by Weiss
Tree.
Section 8.1 Trees.
Binary Trees, Binary Search Trees
Abstract Data Structures
Trees.
Binary Trees.
Principles of Computing – UFCFA3-30-1
Section 9.3 by Andrew Watkins
Binary Search Trees Chapter 7 Objectives
Trees.
Chapter 20: Binary Trees.
Binary Trees.
Data Structures Using C++ 2E
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Presentation transcript:

A Binary Tree is a tree in which each node has at most 2 children A Binary Tree is a tree in which each node has at most 2 children. (Left child and right child.) a b c d e f g h i A binary tree is full if each node has 0 or 2 children. A full binary tree with i internal vertices has i + 1 terminal vertices and 2i + 1 total vertices.

If a binary tree has height h and t terminal vertices then log2 t < h. ( that is t < 2h ) a b c d e f g h What is the maximum number of leaves a tree of height 3 can have?

A binary search tree is a binary tree in which the data stored in its nodes is ordered (usually numerically or alphabetically). The ordering follows the rule that for any node x in the tree, the data in the left subtree < the data in x and the data in the right subtree > the data in x. Joe Pat Gail Ann Hal Zack Kate

Is Ike in the tree? Joe Gail Hal In the worst case ( when the item searched for is on the last level or not in the tree), the time needed is approximately equal to the height of the tree. Exactly equal to the greatest integer < log2 (n) + 1 where n = total no. of nodes in the full tree of minimal height.

Ann Is Tom in the list? Gail Hal Joe Kate Pat Zack

A binary tree is balanced if for every vertex v in the tree, the heights of the left and right subtrees differ by at most 1. The more balanced the tree, the more efficient for searching.

Preorder (left child); Preorder (right child);} Pre order Traversal g e i c f h k a d Recursive Procedure: Preorder (root) g e c a d f i h k If root exists, {process data; Preorder (left child); Preorder (right child);}

{Inorder (left child); process data; Inorder (right child);} a c d e f Inorder Traversal g e i c f h k a d Inorder (root) If root exists, {Inorder (left child); process data; Inorder (right child);} a c d e f g h i k

{Postorder (left child); Postorder Traversal g e i c f h k a d Postorder (root) If root exists, {Postorder (left child); process data;} Postorder (right child); a d c f e h k i g

Traversing a Tree Preorder Traversal i,f,c,b,e,g,k,j,m f k c g j m b e Preorder Traversal i,f,c,b,e,g,k,j,m Inorder Traversal b,c,e,f,g,i,j,k,m Postorder Traversal b,e,c,g,f,j,m,k,i