Results 1 to 3 of 3

Thread: Algorithms

  1. #1
    Join Date
    Jun 2003
    Posts
    160
    Rep Power
    0

    Default Algorithms

    Has anyone implemented Algorithms such as B-Trees, Red Black Trees, Binary Search in Java? If so could you possibly explain the code to me. I am trying implement these algorithms to work on a dynamic set of data. The data would be generated randomly.

  2. #2
    Join Date
    Jul 2002
    Posts
    818
    Rep Power
    0

    Default Re:Algorithms

    I've done BT and BST in Java. Don't remember a thing about them though but I'll try.


    The first thing you must commit to memory when dealing with trees are the definition of a Tree, a Leaf and Recursion.

    A Tree is an item that has children, while a Leaf is a similar item without children. The children of a tree are probable trees themselves.

    Trees are recursive in nature. i.e. A tree is solved by the definition of a tree. Confused as yet? Simply put, the root of a tree is a tree, the root may or may not have children, if the child has a child of it's own, then the child is also a tree, etc. etc. etc.

    Implementation of a tree takes two forms:

    Creating and Traversing.

    The creation of your tree will depend on the purpose of the tree but the basic concept remains the same. The child of a tree can be a tree itself.

    Traversing a tree speaks to the order in which data is read from a tree. It can take any of three forms: Prefix, Infix or Postfix.

    Prefix: root -> left -> right
    Infix: left -> root -> right
    Postfix: left -> right -> root

    The appropriate method of traversing a tree will again depend upon your application.

    A very good example of a tree implementation is that of an Expression Tree. Implementing one of these IMO gives you practically all the theoretical and practical understanding you need for trees including the creation and traversing of the tree using Stacks and other data structures.

    Your question is not very detailed and doesn't exactly explain how the trees are to be used, and as such there is nothing for me to explain. Give some details about what you're trying to accomplish.

  3. #3
    Join Date
    Jun 2003
    Posts
    160
    Rep Power
    0

    Default Re:Algorithms

    I am simply trying to implement several search algorithms that operate on dynamic sets (e.g. binary search, red black trees, B-trees and that the data must be randomly generated. I guess I'm having trouble understanding the concepts of these sets in order to write the code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •