Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.6 / 3....
  • Linux Kernel 3.0.82 LTS...
  • KDE Software Compilatio...
  • PulseAudio 4.0
  • Wireshark 1.10.0
  • NetworkManager 0.9.8.2
  • LibreOffice 3.6.6 / 4.0...
  • SystemRescueCd 3.7.0
  • Linux Kernel 3.10 RC6
  • Ubuntu Tweak 0.8.5
  • Home > Linux > Programming > Perl Modules

    Tree::Binary::Search 0.07

    Download button

    No screenshots available
    Downloads: 284  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Stevan Little | More programs
    Perl Artistic License / FREE
    July 21st, 2007, 18:05 GMT
    ROOT / Programming / Perl Modules

     Read user reviews (0)  Refer to a friend  Subscribe

    Tree::Binary::Search description

    Tree::Binary::Search is a binary search tree for Perl.

    Tree::Binary::Search is a binary search tree for Perl.

    SYNOPSIS

    use Tree::Binary::Search;

    my $btree = Tree::Binary::Search->new();

    $btree->useNumericComparison();

    $btree->insert(5 => "Five");
    $btree->insert(2 => "Two");
    $btree->insert(1 => "One");
    $btree->insert(3 => "Three");
    $btree->insert(4 => "Four");
    $btree->insert(9 => "Nine");
    $btree->insert(8 => "Eight");
    $btree->insert(6 => "Six");
    $btree->insert(7 => "Seven");

    # this creates the following tree:
    #
    # +-------(5)----------+
    # | |
    # +-(2)-+ +-(9)
    # | | |
    # (1) (3)-+ +----(8)
    # | |
    # (4) (6)-+
    # |
    # (7)
    #

    $btree->exists(7); # return true

    $btree->update(7 => "Seven (updated)");

    $btree->select(9); # return 'Nine'

    $btree->min_key(); # returns 1

    $btree->min(); # returns 'One'

    $btree->max_key(); # return 9

    $btree->max(); # return 'Nine'

    $btree->delete(5);

    # this results in the following tree:
    #
    # +-------(6)-------+
    # | |
    # +-(2)-+ +-(9)
    # | | |
    # (1) (3)-+ +-(8)
    # | |
    # (4) (7)
    #


    This module implements a binary search tree, which is a specialized usage of a binary tree. The basic principle is that all elements to the left are less than the root, all elements to the right are greater than the root. This reduces the search time for elements in the tree, by halving the number of nodes that need to be searched each time a node is examined.

    Binary search trees are a very well understood data-structure and there is a wealth of information on the web about them.

    Trees are a naturally recursive data-structure, and therefore, tend to lend themselves well to recursive traversal functions. I however, have chosen to implement the tree traversal in this module without using recursive subroutines. This is partially a performance descision, even though perl can handle theoreticaly unlimited recursion, subroutine calls to have some overhead. My algorithm is still recursive, I have just chosen to keep it within a single subroutine.


    Product's homepage

    Requirements:

    · Perl

      


    TAGS:

    binary search | tree search | Perl module | Tree | binary | search

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM