1 Replies - 3929 Views - Last Post: 03 November 2010 - 11:26 AM Rate Topic: -----

#1 megglz  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 414
  • Joined: 22-August 08

array based binary tree implementation

Posted 03 November 2010 - 11:16 AM

Looking for general advice and guidance. I have decided to use a binary tree implementation for my project, it has also been suggested that an array based binary tree implementation may be best. I already have a binary tree php class to play around with, but I am not 100% certain how to go about implementing it using arrays. Anyone know of any good resources that could help? Thank you :)

Is This A Good Question/Topic? 0
  • +

Replies To: array based binary tree implementation

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10396
  • View blog
  • Posts: 38,463
  • Joined: 27-December 08

Re: array based binary tree implementation

Posted 03 November 2010 - 11:26 AM

I have a Recursion Tutorial Focusing on Stacks and Trees and a Tree Data Structure snippet you may find helpful. I know it's Java, not PHP, but the concepts are the same.

As for your Binary Tree, focus on the Node class. It should have an element, and the array for children. Your Tree class basically manages the Node class.
class Node{
   private $elem;
   private $children;

   public function __construct($elem){
       $this->elem = $elem;
       $children = array();
   }
}


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1