Binary Search Trees A binary tree:A binary tree: –No node has more than two child nodes (called child subtrees). –Child subtrees must be differentiated,

Slides:



Advertisements
Similar presentations
AVL Trees Balancing. The AVL Tree An AVL tree is a balanced binary search tree. What does it mean for a tree to be balanced? It means that for every node.
Advertisements

AVL Tree Smt Genap Outline AVL Tree ◦ Definition ◦ Properties ◦ Operations Smt Genap
The Mystery Vault Game Played by radio stations A listener can win up to $25,000 if he/she guesses the correct amount in the vault One guess per hour until.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
1 Chapter 10 Trees. Tree Definition 1. A tree is a connected undirected graph with no simple circuits. Theorem 1. An undirected graph is a tree if and.
1 Section 9.1 Introduction to Trees. 2 Tree terminology Tree: a connected, undirected graph that contains no simple circuits –must be a simple graph:
AA Trees another alternative to AVL trees. Balanced Binary Search Trees A Binary Search Tree (BST) of N nodes is balanced if height is in O(log N) A balanced.
CS 171: Introduction to Computer Science II
Tirgul 5 AVL trees.
1 Trees. 2 Outline –Tree Structures –Tree Node Level and Path Length –Binary Tree Definition –Binary Tree Nodes –Binary Search Trees.
Rooted Trees. More definitions parent of d child of c sibling of d ancestor of d descendants of g leaf internal vertex subtree root.
Binary Tree Properties & Representation. Minimum Number Of Nodes Minimum number of nodes in a binary tree whose height is h. At least one node at each.
CS2420: Lecture 15 Vladimir Kulyukin Computer Science Department Utah State University.
Tirgul 5 This tirgul is about AVL trees. You will implement this in prog-ex2, so pay attention... BTW - prog-ex2 is on the web. Start working on it!
Balanced Trees. Binary Search tree with a balance condition Why? For every node in the tree, the height of its left and right subtrees must differ by.
Balanced Search Trees CS 3110 Fall Some Search Structures Sorted Arrays –Advantages Search in O(log n) time (binary search) –Disadvantages Need.
Week 7 - Wednesday.  What did we talk about last time?  Recursive running time  Master Theorem  Introduction to trees.
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.
B-trees (Balanced Trees) A B-tree is a special kind of tree, similar to a binary tree. However, It is not a binary search tree. It is not a binary tree.
©Silberschatz, Korth and Sudarshan12.1Database System Concepts B + -Tree Index Files Indexing mechanisms used to speed up access to desired data.  E.g.,
COSC2007 Data Structures II
CS261 Data Structures Trees Introduction and Applications.
AVL Trees Amanuel Lemma CS252 Algoithms Dec. 14, 2000.
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.
CSIT 402 Data Structures II
AVL Tree Definition: Theorem (Adel'son-Vel'skii and Landis 1962):
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
Preview  Graph  Tree Binary Tree Binary Search Tree Binary Search Tree Property Binary Search Tree functions  In-order walk  Pre-order walk  Post-order.
Chapter 7 Trees_Part3 1 SEARCH TREE. Search Trees 2  Two standard search trees:  Binary Search Trees (non-balanced) All items in left sub-tree are less.
D. ChristozovCOS 221 Intro to CS II AVL Trees 1 AVL Trees: Balanced BST Binary Search Trees Performance Height Balanced Trees Rotation AVL: insert, delete.
Discrete Mathematics Chapter 5 Trees.
© University of Auckland Trees – (cont.) CS 220 Data Structures & Algorithms Dr. Ian Watson.
1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.
Lecture 10COMPSCI.220.FS.T Binary Search Tree BST converts a static binary search into a dynamic binary search allowing to efficiently insert and.
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.
Week 7 - Wednesday.  What did we talk about last time?  Recursive running time  Master Theorem  Symbol tables.
TREES General trees Binary trees Binary search trees AVL trees Balanced and Threaded trees.
2 Binary Heaps What if we’re mostly concerned with finding the most relevant data?  A binary heap is a binary tree (2 or fewer subtrees for each node)
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.
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables II.
3.1 Height-Balanced Trees 3.2 Weight-Balanced Trees
CSCE 210 Data Structures and Algorithms
AA Trees.
Multiway Search Trees Data may not fit into main memory
Binary search tree. Removing a node
Red Black Trees
Source Code for Data Structures and Algorithm Analysis in C (Second Edition) – by Weiss
AVL DEFINITION An AVL tree is a binary search tree in which the balance factor of every node, which is defined as the difference between the heights of.
AVL Tree.
Binary Search Tree Chapter 10.
Tree.
Tree data structure.
Slide Sources: CLRS “Intro. To Algorithms” book website
Binary Trees, Binary Search Trees
Slide Sources: CLRS “Intro. To Algorithms” book website
Tree data structure.
BTrees.
Binary Search Trees.
Binary Heaps What if we’re mostly concerned with finding the most relevant data? A binary heap is a binary tree (2 or fewer subtrees for each node) A heap.
Binary Trees, Binary Search Trees
AVL Trees B.Ramamurthy 4/27/2019 BR.
Basic Data Structures - Trees
Binary Trees, Binary Search Trees
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
A Binary Tree is a tree in which each node has at most 2 children
Presentation transcript:

Binary Search Trees A binary tree:A binary tree: –No node has more than two child nodes (called child subtrees). –Child subtrees must be differentiated, into: Left-child subtreeLeft-child subtree Right-child subtreeRight-child subtree A search tree:A search tree: –For every node, p: All nodes in the left subtree are < pAll nodes in the left subtree are < p All nodes in the right subtree are > pAll nodes in the right subtree are > p

Binary Search Tree - Example

Binary Search Trees (cont) Searching for a value is in a tree of N nodes is:Searching for a value is in a tree of N nodes is: –O(log N) if the tree is “balanced” –O(N) if the tree is “unbalanced”

“Unbalanced” Binary Search Trees Below is a binary search tree that is NOT “balanced”Below is a binary search tree that is NOT “balanced”

Properties of Binary Trees A binary tree is a full binary tree if and only if:A binary tree is a full binary tree if and only if: –Each non leaf node has exactly two child nodes –All leaf nodes have identical path length It is called full since all possible node slots are occupiedIt is called full since all possible node slots are occupied

A Full Binary Tree - Example

Full Binary Trees A Full binary tree of height h will have how many leavesA Full binary tree of height h will have how many leaves? A Full binary tree of height h will have how many nodesA Full binary tree of height h will have how many nodes?

Complete Binary Trees A complete binary tree (of height h) satisfies the following conditions:A complete binary tree (of height h) satisfies the following conditions: –Level 0 to h-1 represent a full binary tree of height h-1 –One or more nodes in level h-1 may have 0, or 1 child nodes –If j,k are nodes in level h-1, then j has more child nodes than k if and only if j is to the left of k

Complete Binary Trees - Example

Complete Binary Trees (cont) Given a set of N nodes, a complete binary tree of these nodes provides the maximum number of leaves with the minimal average path length (per node)Given a set of N nodes, a complete binary tree of these nodes provides the maximum number of leaves with the minimal average path length (per node) The complete binary tree containing n nodes must have at least one path from root to leaf of length  log n The complete binary tree containing n nodes must have at least one path from root to leaf of length  log n 

Height-balanced Binary Tree A height-balanced binary tree is a binary tree such that:A height-balanced binary tree is a binary tree such that: –The left & right subtrees for any given node differ in height by no more than one Each complete binary tree is a height- balanced binary treeNote: Each complete binary tree is a height- balanced binary tree

Height-balanced Binary Tree - Example

Advantages of Height-balanced Binary Trees Height-balanced binary trees are “balanced”Height-balanced binary trees are “balanced” Operations that run in time proportional to the height of the tree are O(log n), n the number of nodeslimited performance varianceOperations that run in time proportional to the height of the tree are O(log n), n the number of nodes with limited performance variance Variance is a very important concern in real time applications, e.g. connecting calls in a telephone networkVariance is a very important concern in real time applications, e.g. connecting calls in a telephone network