SplayTree
is a self-balancing binary search tree. It has an additional property with the recently accessed elements to quickly access it.
The time complexity for the insert, search, and delete is .
Note: is the number of nodes in the
SplayTree
.
Below is a sample code for using a SplayTree
in Julia:
using DataStructures# create a new spaly treesplayTree = SplayTree();push!(splayTree, 1)push!(splayTree, 5)push!(splayTree, 2)push!(splayTree, 4)push!(splayTree, 10)for k in 1:length(splayTree)println("tree[$(k)] :", splayTree[k] )end#check if the spalytree contains a keyprintln("Check if spalytree has key 4 :", haskey(splayTree, 4))# deleting 4 from the splayTreedelete!(splayTree, 4)println("After deleting 4, The spalyTree is")# print the elements of splayTreefor k in 1:length(splayTree)println("tree[$(k)] :", splayTree[k] )end
SplayTree
object with the name splayTree
. push!
method to insert five elements into the splayTree
.splayTree
.haskey
method to check if the splayTree
contains key 4
.delete
method to delete the key 4
from the splayTree
.Note: The complete reference to the
SplayTree
can be found on the official Julia page here.