Module: lib-tde.datastructure.binary-tree

Lua implementation of a Binary Search Tree

This binary Tree is not the most efficient implementation in terms of insertion or removal

Time complexity:

  • Lookup element O(log(n))
  • Insert element O(n)
  • Remove element O(n)

Info:

  • Copyright: 2020 Tom Meyers
  • Author: Tom Meyers

Static module functions

lib-tde.datastrucuture.binary-tree () -> table Create a new Binary Search Tree (BST)
lib-tde.datastrucuture.binary-tree.contains (data) Check if an element is present in the binary tree
lib-tde.datastrucuture.binary-tree.insert (data) Insert an element into the binary tree, not that insertion can be rather expensive
lib-tde.datastrucuture.binary-tree.remove (data) Remove an element from the tree


Static module functions

lib-tde.datastrucuture.binary-tree () -> table
Create a new Binary Search Tree (BST)

Returns:

    table A table containing the BST methods

Usage:

    -- This will create a new empty binary tree
     lib-tde.datastrucuture.binarytree()
lib-tde.datastrucuture.binary-tree.contains (data)
Check if an element is present in the binary tree

Parameters:

  • data object The data to look for in the tree

Usage:

    -- Check if "tde" exists (in O(log(n)) time)
     tree.contains("tde")
lib-tde.datastrucuture.binary-tree.insert (data)
Insert an element into the binary tree, not that insertion can be rather expensive

Parameters:

  • data object The data to insert

Usage:

    -- Insert "tde" into the tree
     tree.insert("tde")
lib-tde.datastrucuture.binary-tree.remove (data)
Remove an element from the tree

Parameters:

  • data object The data to remove from the tree

Usage:

    -- Remove tde from the tree
     tree.remove("tde")
generated by LDoc 1.4.6 Build with 💜 By F0xedb Last updated 2021-05-21 03:30:15