Lecture142134

Lecture142134 - – Faster to do iteratively • Fastest methods are careful to limit of comparisons CS2134 Other operations on binary search trees

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CS2134 Lecture 14 Binary Search Trees
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS2134 Binary Search Trees Binary Trees which store elements in “tree” order “Key” of node is element it stores Tree order: for each node x in the tree keys in left subtree of x <= key(x) keys in right subtree of x >= key(x) Code in BinarySearchTree.cpp and BinarySearchTree.h
Background image of page 2
CS2134 Searching in BSTs To search for key i in BST Starting at root node, continue until find i or node is NULL Compare i to key at current node if equal, done if i < key, move on to left child If i > key, move on to right child Can do recursively
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: – Faster to do iteratively • Fastest methods are careful to limit # of comparisons CS2134 Other operations on binary search trees • Insertion – Assume don’t allow duplicate elements in tree – Insertion is like search, but when reach NULL, insert new node there containing element – Shape of tree depends on order of insertions • Deletion – Trickier – Find node to delete – If no children, remove (need to change parent) – If one child, attach that child to node’s parent – If two children, replace node with its successor...
View Full Document

This note was uploaded on 12/09/2009 for the course CS 2134 taught by Professor Hellerstein during the Spring '07 term at NYU Poly.

Page1 / 4

Lecture142134 - – Faster to do iteratively • Fastest methods are careful to limit of comparisons CS2134 Other operations on binary search trees

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online