Skip to content

Instantly share code, notes, and snippets.

@V0L0DYMYR
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save V0L0DYMYR/2eb4908d4b9a6407596e to your computer and use it in GitHub Desktop.

Select an option

Save V0L0DYMYR/2eb4908d4b9a6407596e to your computer and use it in GitHub Desktop.
package cormen;
public interface BinaryTree<Key extends Comparable> {
Key next(Key key);
Key previous(Key key);
Key max();
Key min();
BinaryTree<Key> merge(BinaryTree<Key> tree);
boolean equals(BinaryTree<Key> tree);
Object serialize();
/**
* leetcode
* @param o
* @return
*/
BinaryTree<Key> deserializer(Object o);
/**
* leetcode
* @param key
* @return
*/
BinaryTree<Key> subTree(Key key);
void balance();
Tree<Key> constructFromInOrderAndPreOrder(Iterable<Key> in, Iterable<Key> pre);
Tree<Key> constructFromInOrderAndPostOrder(Iterable<Key> in, Iterable<Key> post);
/*
_______7______
/ \
__10__ ___2
/ \ /
4 3 _8
\ /
1 11
The preorder and inorder traversals for the binary tree above is:
preorder = {7,10,4,3,1,2,8,11}
inorder = {4,10,3,1,7,11,8,2}
*/
/*
Print Edge Nodes (Boundary) of a Binary Tree
Print all edge nodes of a complete binary tree anti-clockwise.
That is all the left most nodes starting at root, then the leaves left to right and finally all the rightmost nodes.
In other words, print the boundary of the tree.
Variant: Print the same for a tree that is not complete.
*/
}
package cormen;
import java.util.Collection;
public interface Tree<Key> {
void delete(Key value);
void put(Key value);
int height();
int size();
/**
* leetcode
* @return
*/
Iterable<Key> inOrderTraversal();
/**
* leetcode
* @return
*/
Iterable<Key> preOrderTraversal();
/**
* leetcode
* @return
*/
Iterable<Key> postOrderTraversal();
Key lowestCommonAccessor(Key k1, Key k2);
/**
* leetcode
* @return
*/
BinaryTree largestBST();
Collection<Key> maxPassSum();
/**
* leetcode
* @return
*/
Collection<Key> edgesNodes();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment