Chapter 20: Binary Trees.

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

S. Sudarshan Based partly on material from Fawzi Emad & Chau-Wen Tseng
Senem Kumova Metin Spring2009 BINARY TREES && TREE TRAVERSALS Chapter 10 in A Book on C.
SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.
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.
CS 171: Introduction to Computer Science II
Binary Tree Terminology Linear versus hierarchical data Tree – connected graph with no cycles Child Parent Descendant Sibling Ancestor Leaf vs. internal.
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A12 – Binary Trees.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 10 Ming Li Department of.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A12 – Binary Trees.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 19 Binary.
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.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 19: Binary Trees.
Data Structures – Binary Tree
Types of Binary Trees Introduction. Types of Binary Trees There are several types of binary trees possible each with its own properties. Few important.
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.
Binary Trees Chapter Definition And Application Of Binary Trees Binary tree: a nonlinear linked list in which each node may point to 0, 1, or two.
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.
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.
Tree Data Structures.
 Trees Data Structures Trees Data Structures  Trees Trees  Binary Search Trees Binary Search Trees  Binary Tree Implementation Binary Tree Implementation.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Modified for use at Midwestern State University Chapter.
Topics Definition and Application of Binary Trees Binary Search Tree Operations.
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
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.
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.
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 Tree. Some Terminologies Short review on binary tree Tree traversals Binary Search Tree (BST)‏ Questions.
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.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
Copyright © 2012 Pearson Education, Inc. Chapter 20: Binary Trees.
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.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 20: Binary Trees.
Foundation of Computing Systems Lecture 4 Trees: Part I.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 20: Binary Trees.
(c) University of Washington20-1 CSC 143 Java Trees.
Binary Trees.
Binary Search Trees Chapter 7 Objectives
Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Data Structure and Algorithms
Binary Trees.
Recursive Objects (Part 4)
Week 6 - Wednesday CS221.
Binary Search Tree (BST)
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Tree.
Section 8.1 Trees.
Tonga Institute of Higher Education
Chapter 20: Binary Trees.
CS223 Advanced Data Structures and Algorithms
Chapter 21: Binary Trees.
Binary Trees.
Abstract Data Structures
Binary Trees.
Trees Definitions Implementation Traversals K-ary Trees
Lecture 36 Section 12.2 Mon, Apr 23, 2007
Binary Trees, Binary Search Trees
Binary Trees.
Trees.
Binary Trees.
Binary Trees, Binary Search Trees
Data Structures Using C++ 2E
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Presentation transcript:

Chapter 20: Binary Trees

Definition and Application of Binary Trees 20.1 Definition and Application of Binary Trees

Definition and Application of Binary Trees Binary tree: a nonlinear linked list in which each node may point to 0, 1, or two other nodes Each node contains one or more data fields and two pointers NULL

Binary Tree Terminology Tree pointer: like a head pointer for a linked list, it points to the first node in the binary tree Root node: the node at the top of the tree NULL

Binary Tree Terminology Child nodes, children: nodes below a given node The children of the node containing 31 are the nodes containing 19 and 59 NULL 7 19 31 43 59

Binary Tree Terminology Parent node: node above a given node The parent of the node containing 43 is the node containing 59 NULL 7 19 31 43 59

Binary Tree Terminology Leaf nodes: nodes that have no children The nodes containing 7 and 43 are leaf nodes NULL 7 19 31 43 59

Binary Tree Terminology Subtree: the portion of a tree from a node down to the leaves The nodes containing 19 and 7 are the left subtree of the node containing 31 NULL 7 19 31 43 59

Uses of Binary Trees Binary search tree: data organized in a binary tree to simplify searches Left subtree of a node contains data values < the data in the node Right subtree of a node contains values > the data in the node NULL 7 19 31 43 59

Binary Search Tree Operations 20.2 Binary Search Tree Operations

Binary Search Tree Operations Insert a node into a binary tree – put node into tree in its correct position to maintain order Find a node in a binary tree – locate a node with particular data value Traverse a binary tree

Traversing a Binary Tree Three traversal methods: Inorder: Traverse left subtree of node Process data in node Traverse right subtree of node Preorder: Postorder:

Traversing a Binary Tree NULL 7 19 31 43 59 TRAVERSAL METHOD NODES VISITED IN ORDER Inorder Preorder Postorder

Traversing a Binary Tree NULL 7 19 31 43 59 TRAVERSAL METHOD NODES VISITED IN ORDER Inorder 7, 19, 31, 43, 59 Preorder 31, 19, 7, 59, 43 Postorder 7, 19, 43, 59, 31