CS 270 Algorithms Oliver Kullmann Binary trees The notion
- f “binary
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
Week 8 Oliver Kullmann Binary trees The notion BinaryTrees of - - PowerPoint PPT Presentation
CS 270 Algorithms Week 8 Oliver Kullmann Binary trees The notion BinaryTrees of binary search tree Tree traversal Binary trees 1 Queries in binary The notion of binary search tree search trees 2 Insertion Tree
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
1 Sections 12.1, 12.2, 12.3 on binary search trees.
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
1 First print out the keys of the left subtree of the root. 2 Then print the key of the root. 3 Finally print out the keys of the right subtree of the root.
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
1 If the key k′ of the root of T equals k, then return the root. 2 Otherwise, if k ≤ k′ then return the result for the left
3 Otherwise return the result for the right subtree of T.
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
1 x′ > x (that is (for a linear order) x′ ≥ x and x′ = x), 2 there is no y ∈ M with y > x and y < x′.
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
1 If x has a right child, then by our definition (and the
2 But what if x has no right child? Perhaps then there is no
3 Considering the example 8 slides ago, we see that the node
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
1 d b 2 h a 3 f c 4 i g 5 and finally g has no successor.
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
1 “Validity” must include that the observable content of
2 However links to parents and children may be altered.
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
1 If z has no children, then z can be just deleted, and for its
2 If z has only one child, then again z can be just deleted,
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
1 If z has no children, then delete z, and put the child-link of
2 If z has exactly one child, then delete z, and put the
3 If z has two children, then obtain the successor-node z′ of z
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
1 Hope for randomness. 2 Or improve the worst-case behaviour, by using more
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
1 Hope for randomness. 2 Or improve the worst-case behaviour, by using more
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial
1 Yet we produce a degenerated tree (the worst-case), just
2 This is due to the fact that in the existing inorder sequence
3 One could also insert it into last possible position, always
4
CS 270 Algorithms Oliver Kullmann Binary trees The notion
search tree” Tree traversal Queries in binary search trees Insertion Deletion Tutorial