Thread: Binary Trees

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    55

    Binary Trees

    Hi All,

    I have been trying out the binary tree tutorial on this site. I ahve
    got it working but i have a few questions/observations. Here is the thing:



    1. I added 10000 elements using a for loop and used the loop
    counter as key value. I got a stack overflow at 9960 each time.

    2. I adden 1000000 elements using the rand function. This
    work perfectly.

    3. I went out on a limb and added 4000000 elements also
    using the rand function. The program never finished.


    I am wondering what one can expect out of binary trees and
    if there are notible different ways in implementing them. I know
    there is in linked list. e.g is 4000000 elements to much? or should they be able to handle that. And has any one got any tips or suggenstions on how to implement and use them.

    G'n'R

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Without seeing your code, one can only speculate. Binary trees are basicly just linked lists (or that's how I'd implement it anyway) where you have a left and a right pointer and some value.
    Code:
    struct node
    {
        struct node *left, *right;
        <type> data;
    };
    Basicly you just go down the list, if you're greater than the value, you go to one side, if you're less than, you go to the other.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    When you add the elements in increasing order
    to a binary tree you get what basically is a list.
    The stack on the delete tree method would have 100000 stack frames which could overflow.

    2. I adden 1000000 elements using the rand function. This
    work perfectly.
    One of my books derives this but the average height of a
    randomally built binary tree is about 2lg n so that
    makes the height of this tree on average about 40.

    The problem is inherent in the basic binary tree. You will
    probably want to learn more about balenced trees.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    55

    Binary....

    Hello,

    Thanks for the info. Balanced tree?? Sounds interesting. I'll see if i can find som good info and tutorials on it. The one in the tutorial on this site, what would you call that? (Trying to get everything perspective here )

    Regards,
    G'n'R

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A Binary Search Tree of... Binary Search Trees...
    By SlyMaelstrom in forum C++ Programming
    Replies: 5
    Last Post: 12-10-2005, 02:12 PM
  2. Binary Trees
    By wvu2005 in forum C Programming
    Replies: 7
    Last Post: 10-15-2005, 04:59 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM