The root is the most accessible node 5 8 15 9 29 11

This preview shows page 7 - 17 out of 26 pages.

followed to reach that node. The root is the most accessible node. 5 8 15 9 29 11 What is the depth of the root? The root always has a depth of 0. The depth of a tree is the depth of the deepest node.
Image of page 7

Subscribe to view the full document.

Binary tree All the trees presented thus far exhibit a certain property, what is it? 5 8 15 12 29 2 7 1 4 50 13
Image of page 8
Binary search tree A binary search tree is a binary tree such that, the nodes of a left sub-tree contain elements that are less than the element stored at the local root (or is empty); the nodes of a right sub-tree contain elements that are greater than the element stored at the local root (or is empty). 5 8 15 12 29 2 7 1 4 50 13 The definition precludes duplicate values.
Image of page 9

Subscribe to view the full document.

Binary search tree Implementing a binary search tree, what is needed? That’s right, we need a class Node . What are its instance variables? Its instance variables are value , left and right . What are the types of these variables? value should be Comparable , left and right should be of type Node .
Image of page 10
Binary search tree A static nested class to store the elements of the tree. public class BinarySearchTree< E extends Comparable<E> > { private static class Node<E> { private E value; private Node<E> left; private Node<E> right; }
Image of page 11

Subscribe to view the full document.

Binary search tree Instance variable(s) of the class BinarySearchTree ? public class BinarySearchTree< E extends Comparable<E> > { private static class Node<E> { private E value; private Node<E> left; private Node<E> right; } private Node<E> root;
Image of page 12
Memory diagram 8 root t Node BinarySearchTree right left value Comparable
Image of page 13

Subscribe to view the full document.

8 9 15 11 5 root t Node BinarySearchTree
Image of page 14
8 9 15 11 5 root t 5 8 11 9 15
Image of page 15

Subscribe to view the full document.

Observations A leaf is a Node such that both its descendant reference variables ( left and right ) are null .
Image of page 16
Image of page 17
You've reached the end of this preview.
  • Spring '10
  • Samaan
  • Tree traversal, Nested set model

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern