class BinarySearchTree[Key, Value] extends OrderedSymbolTable[Key, Value]
This class implements an ordered symbol table of generic key/value pairs.
This implementation uses a binary search tree.
The put, get and contains operations take linear time in the worst case, but logarithmic time on the average. All order-based operations take time proportional to the height of the tree in the worst case; this applies to minimum, maximum and select as well as floor, ceiling and the tow-argument size. The one-argument size and is-empty are constant in time.
Adapted from the book Algorithms 4 by R. Sedgewick and K. Wayne.
- See also
Section 3.2 of Algorithms, 4th Edition
Algorithms, 4th edition by Robert Sedgewick and Kevin Wayne, Addison-Wesley Professional, 2011, ISBN 0-321-57351-X. http://algs4.cs.princeton.edu
- Alphabetic
- By Inheritance
- BinarySearchTree
- OrderedSymbolTable
- BasicSymbolTable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
apply(key: Key): Value
- returns
value paired with key
- Definition Classes
- BinarySearchTree → BasicSymbolTable
- Exceptions thrown
NoSuchElementExceptionif key is not in table
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
ceil(key: Key): Key
- returns
the smallest key greater than or equal to the specified key
- Definition Classes
- BinarySearchTree → OrderedSymbolTable
- Exceptions thrown
NoSuchElementExceptionif key is greater than maximum key
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
contains(key: Key): Boolean
- Definition Classes
- BasicSymbolTable
-
def
delete(key: Key): Unit
Removes key/value pair from table.
Removes key/value pair from table.
- Definition Classes
- BinarySearchTree → BasicSymbolTable
- Exceptions thrown
NoSuchElementExceptionif key is not in table
-
def
deleteMax(): Unit
Removes the node with the the largest key.
Removes the node with the the largest key.
- Definition Classes
- BinarySearchTree → OrderedSymbolTable
- Exceptions thrown
NoSuchElementExceptionif table is empty
-
def
deleteMin(): Unit
Removes the node with the the smallest key.
Removes the node with the the smallest key.
- Definition Classes
- BinarySearchTree → OrderedSymbolTable
- Exceptions thrown
NoSuchElementExceptionif table is empty
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
floor(key: Key): Key
- returns
the largest key less than or equal to the specified key
- Definition Classes
- BinarySearchTree → OrderedSymbolTable
- Exceptions thrown
NoSuchElementExceptionif key is less than minimum key
-
def
get(key: Key): Option[Value]
- Definition Classes
- BasicSymbolTable
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
getOrElse(key: Key, default: ⇒ Value): Value
- Definition Classes
- BasicSymbolTable
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
-
def
isEmpty: Boolean
- Definition Classes
- BasicSymbolTable
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
keys(lo: Key, hi: Key): Iterable[Key]
- returns
all keys in the table between lo and hi (inclusive) in sorted order
- Definition Classes
- BinarySearchTree → OrderedSymbolTable
-
def
keys(): Iterable[Key]
- returns
all keys in the table
- Definition Classes
- OrderedSymbolTable → BasicSymbolTable
-
def
max: Key
- returns
the largest key
- Definition Classes
- BinarySearchTree → OrderedSymbolTable
- Exceptions thrown
NoSuchElementExceptionif table is empty
-
def
min: Key
- returns
the smallest key
- Definition Classes
- BinarySearchTree → OrderedSymbolTable
- Exceptions thrown
NoSuchElementExceptionif table is empty
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
implicit
val
ord: Ordering[Key]
- Attributes
- protected
- Definition Classes
- BinarySearchTree → OrderedSymbolTable
-
def
rank(key: Key): Int
- returns
the number of keys less than the specified key
- Definition Classes
- BinarySearchTree → OrderedSymbolTable
-
def
select(k: Int): Key
- returns
the key of rank k
- Definition Classes
- BinarySearchTree → OrderedSymbolTable
- Exceptions thrown
NoSuchElementExceptionif k is less than 0 or greater than the maximum rank
-
def
size: Int
- Definition Classes
- BinarySearchTree → OrderedSymbolTable → BasicSymbolTable
-
def
size(lo: Key, hi: Key): Int
- returns
the number of keys between lo and hi (inclusive)
- Definition Classes
- OrderedSymbolTable
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- BinarySearchTree → OrderedSymbolTable → BasicSymbolTable → AnyRef → Any
-
def
update(key: Key, value: Value): Unit
Inserts key/value pair into table.
Inserts key/value pair into table. Replaces value if key is already there.
- Definition Classes
- BinarySearchTree → BasicSymbolTable
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )