Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. public final class Trees {
  2.  
  3.  
  4.     /**
  5.      * Node of a binary search tree
  6.      * Left subtree contains values that are less (or equal) than value of this node
  7.      * Right subtree contains values that are greater than a value of this node
  8.      */
  9.     //FIXME Make this type safe using generics
  10.     public interface Node {
  11.  
  12.         /**
  13.          * Returns value associated with this node
  14.          */
  15.         Comparable value();
  16.  
  17.         /**
  18.          * Returns left subtree if present
  19.          */
  20.         Node left();
  21.  
  22.         /**
  23.          * Returns right subtree if present
  24.          */
  25.         Node right();
  26.  
  27.     }
  28.  
  29.     /**
  30.      * Check whether tree contains provided value
  31.      * @return true if value present in the tree
  32.      */
  33.     static boolean contains(Node tree, Comparable a) {
  34.         //FIXME Provide implementation
  35.         return false;
  36.     }
  37.  
  38.     /**
  39.      * Find a tree node that is Least Common Ancestor (com.example.LCA) for
  40.      * provided values
  41.      *
  42.      * @param searchTree root node of a binary search tree
  43.      * @param a    one of thee nodes in a tree
  44.      * @param b    one of thee nodes in a tree
  45.      * @return com.example.LCA
  46.      */
  47.     public static Node findLCA(Node searchTree, Node a, Node b) {
  48.         //FIXME Provide implementation
  49.         return null;
  50.     }
  51.  
  52.  
  53.     public static Node bfs(Node tree, Node a) {
  54.         //FIXME Provide implementation
  55.         return null;
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement