[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/verifyCode/algorithms/master/src/main/java/com/set/BSTSet.java [Back]  [Original]

package com.set;

import com.tree.bst.BST;

/**
 * 
 *
 * @author xjn
 * @since 2019-12-25
 */
public class BSTSet implements MySet {

    private BST bst;

    public BSTSet() {
        bst = new BST();
    }

    //O(h) h:
    // 01
    // 12
    // 24
    // 38
    // 416
    // h2^(h-1)
    // h = 2^h - 1
    // n = 2^h -1
    // h = log2(n + 1)
    //O(h) = O(log n)
    @Override
    public void add(E e) {
        bst.add(e);
    }

    //O(h) h:
    //O(h) = O(log2)
    @Override
    public void remove(E e) {
        bst.remove(e);
    }

    //O(h) = O(log2)
    @Override
    public boolean contains(E e) {
        return bst.contains(e);
    }

    //O(1)
    @Override
    public int getSize() {
        return bst.getSize();
    }
    //O(1)
    @Override
    public boolean isEmpty() {
        return bst.isEmpty();
    }
}

Web Proxy Viewer  |  New URL  |  Original Page