Binary search tree BST - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

Binary search tree BST

Description:

Binary search tree (BST) In BST, for every node v. Left subtree has keys v's key ... BST heights. average: O(logn) worst case: O(n) --- which we want to avoid ... – PowerPoint PPT presentation

Number of Views:68
Avg rating:3.0/5.0
Slides: 8
Provided by: csUi
Category:
Tags: bst | binary | bst | search | tree

less

Transcript and Presenter's Notes

Title: Binary search tree BST


1
Binary search tree (BST)
  • In BST, for every node v
  • Left subtree has keys vs key
  • Right subtree has keys vs key
  • BST heights
  • average O(logn)
  • worst case O(n) --- which we want to avoid
  • A better balanced BST Red-Black trees
  • worst case height 2log2n

2
Red-black tree rules
  • Every node is either black or red.
  • The root is always black.
  • Red nodes parent must be black.
  • Every path from the root to a left have the same
    black-height (i.e. same number of black nodes).

3
Why same black height?
  • Balance!
  • h - black height
  • h - height of the tree
  • longest path from root to leaf
  • __________________________________________________
    ________________________________
  • shortest path from root to left

h lt 2h
lt 2
4
Is this a red-black tree?
5
Is this a red-black tree?
new inserted node
6
Is this a red-black tree?
new inserted node
7
Is this a red-black tree?
new inserted node
Write a Comment
User Comments (0)
About PowerShow.com