File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99// remove -> O(h) can be O(n) if input is sorted
1010// no duplicate is allowed, for duplicate supported BST look BSTWithDuplicate.java
1111// most methods are recursive, look BSTIterative.java for iterative approach BST
12- public class BST <K extends Comparable > {
12+ public class BST <K extends Comparable > implements Tree < K > {
1313 private Node root ;
1414
15+
16+ @ Override
1517 public void insert (K k ) {
1618 root = put (root , k , null );
1719 }
1820
21+ @ Override
1922 public boolean search (K k ) {
2023 return findNode (k , root ) != null ;
2124 }
2225
26+ @ Override
2327 public void delete (K k ) {
2428 Node x = findNode (k , root );
2529 delete (x );
Original file line number Diff line number Diff line change 1+ package ds ;
2+
3+ /**
4+ * Created by sherxon on 12/18/16.
5+ */
6+ // Binary Search Tree, two nodes (left, right) and one parent.
7+ // insert -> O(h) can be O(n) if input is sorted
8+ // search -> O(h) can be O(n) if input is sorted
9+ // remove -> O(h) can be O(n) if input is sorted
10+ // no duplicate is allowed, for duplicate supported BST look BSTWithDuplicate.java
11+ // most methods are iterative, look BST.java for recursive approach BST
12+ public class BSTIterative <K extends Comparable > implements Tree <K > {
13+
14+ private Node root ;
15+
16+ @ Override
17+ public void insert (K k ) {
18+
19+ }
20+
21+ @ Override
22+ public boolean search (K k ) {
23+ return false ;
24+ }
25+
26+ @ Override
27+ public void delete (K k ) {
28+
29+ }
30+
31+
32+ private class Node {
33+ K value ;
34+ int size = 1 ;
35+ Node left , right , parent ;
36+
37+ public Node (K k , Node parent ) {
38+ this .value = k ;
39+ this .parent = parent ;
40+ }
41+ }
42+
43+ }
Original file line number Diff line number Diff line change 1+ package ds ;
2+
3+ /**
4+ * Created by sherxon on 12/18/16.
5+ */
6+ public interface Tree <K > {
7+ void insert (K k );
8+ boolean search (K k );
9+ void delete (K k );
10+ }
You can’t perform that action at this time.
0 commit comments