Package dsa
Class RedBlackBinarySearchTreeST<K extends Comparable<K>,V>
java.lang.Object
dsa.RedBlackBinarySearchTreeST<K,V>
- Type Parameters:
K
- the type of keys in this symbol table.V
- the type of values in this symbol table.
- All Implemented Interfaces:
OrderedST<K,
V>
public class RedBlackBinarySearchTreeST<K extends Comparable<K>,V>
extends Object
implements OrderedST<K,V>
This data type provides an implementation of the ordered symbol table (OrderedST) API, using a red-black binary
search tree (RBBST) as the underlying data structure.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns the smallest key in this symbol table that is larger than or equal tokey
.boolean
Returnstrue
if this symbol table containskey
, andfalse
otherwise.void
Deleteskey
and the associated value from this symbol table.void
Deletes the largest key and the associated value from this symbol table.void
Deletes the smallest key and the associated value from this symbol table.Returns the largest key in this symbol table that is smaller than or equal tokey
.Returns the value associated withkey
in this symbol table, ornull
.inOrder()
Returns all the keys from this symbol table in "in" order.boolean
isEmpty()
Returnstrue
if this symbol table is empty, andfalse
otherwise.keys()
Returns all the keys in this symbol table in sorted order.Returns the keys in this symbol table that are in the interval[lo, hi]
in sorted order.Returns all the keys from this symbol table in "level" order.static void
Unit tests the data type.max()
Returns the largest key in this symbol table.min()
Returns the smallest key in this symbol table.Returns all the keys from this symbol table in "post" order.preOrder()
Returns all the keys from this symbol table in "pre" order.void
Inserts thekey
andvalue
pair into this symbol table.int
Returns the number of keys in this symbol table that are strictly smaller thankey
.select
(int k) Returns the key in this symbol table with the rankk
.int
size()
Returns the number of key-value pairs in this symbol table.int
Returns the number of keys in this symbol table that are in the interval[lo, hi]
.toString()
Returns a string representation of this symbol table.
-
Constructor Details
-
RedBlackBinarySearchTreeST
public RedBlackBinarySearchTreeST()Constructs an empty symbol table.
-
-
Method Details
-
isEmpty
public boolean isEmpty()Returnstrue
if this symbol table is empty, andfalse
otherwise. -
size
public int size()Returns the number of key-value pairs in this symbol table. -
put
Inserts thekey
andvalue
pair into this symbol table. -
get
Returns the value associated withkey
in this symbol table, ornull
. -
contains
Returnstrue
if this symbol table containskey
, andfalse
otherwise. -
delete
Deleteskey
and the associated value from this symbol table. -
keys
Returns all the keys in this symbol table in sorted order. -
min
Returns the smallest key in this symbol table. -
max
Returns the largest key in this symbol table. -
deleteMin
public void deleteMin()Deletes the smallest key and the associated value from this symbol table. -
deleteMax
public void deleteMax()Deletes the largest key and the associated value from this symbol table. -
floor
Returns the largest key in this symbol table that is smaller than or equal tokey
. -
ceiling
Returns the smallest key in this symbol table that is larger than or equal tokey
. -
rank
Returns the number of keys in this symbol table that are strictly smaller thankey
. -
select
Returns the key in this symbol table with the rankk
. -
size
Returns the number of keys in this symbol table that are in the interval[lo, hi]
. -
keys
Returns the keys in this symbol table that are in the interval[lo, hi]
in sorted order. -
preOrder
Returns all the keys from this symbol table in "pre" order.- Returns:
- all the keys from this symbol table in "pre" order.
-
inOrder
Returns all the keys from this symbol table in "in" order.- Returns:
- all the keys from this symbol table in "in" order.
-
postOrder
Returns all the keys from this symbol table in "post" order.- Returns:
- all the keys from this symbol table in "post" order.
-
levelOrder
Returns all the keys from this symbol table in "level" order.- Returns:
- all the keys from this symbol table in "level" order.
-
toString
Returns a string representation of this symbol table. -
main
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-