•

### Recent Blog Entries

• KodeKool

When faced with a wall of errors and no hope to fix them, remember the following "Programs always do what you tell them to, and seldom what you want them to, but eventually you'll run out of things that can go wrong and it'll just work. and that's the secret to good programming."

Almost a year since I joined...

• Vaielab

Failure Isn't an Option, It's a Fact

• Error

Should I be practicing programming every day? I feel if I don't, I'll get instantly rusty or something.

# Tree

5 replies to this topic

### #1 GOGOS

GOGOS

CC Lurker

• Just Joined
• 2 posts

Posted 07 May 2010 - 08:46 AM

with this problem...if yu have any ideas help me
2-3 tree

Definitions
Neighbours: Two nodes are neighbors if they share the same father and does not interfere with node
between the pipes. The blue nodes are neighbors but not orange
Scalable: A 2-3 tree is scalable if it contains two neighbors where they have three children each
Extension: If a tree is scalable get two neighboring nodes with three children each and
transformed into three nodes with two children.
Implementation: implement the following operations in a 2-3
 empty (): returns true if and only if empty
 contains (x): returns true if and only if it contains the value of x.
 insert (x): inserts the integer x in the tree
 isExpandable (): returns true if and only if the tree is extensible
 expand (): expand the tree (it is call the method immediately after when isExpandable ()
returns true
 numberOfNodes (): returns the number of nodes
 toIntArray (): returns an array of int containing all the tree values in ascending
series
 The Last Two methods are implemented by recursive function calls

• 0

### #2 WingedPanther

WingedPanther

A spammer's worst nightmare

• Moderator
• 16,988 posts
• Location:Upstate, South Carolina
• Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
• Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 07 May 2010 - 01:21 PM

What's your code so far? I'm not clear on your definition of neighbors.
• 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/

### #3 GOGOS

GOGOS

CC Lurker

• Just Joined
• 2 posts

Posted 08 May 2010 - 06:16 AM

• 0

### #4 WingedPanther

WingedPanther

A spammer's worst nightmare

• Moderator
• 16,988 posts
• Location:Upstate, South Carolina
• Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
• Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 09 May 2010 - 02:47 PM

Not right now. I can't event tell if your tree in ternary or n-ary. Given that you haven't clearly defined your terms, I wouldn't start to make a guess. Hopefully, you have some code already created that this is supposed to be based on.
• 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/

### #5 jaywheeler

jaywheeler

CC Lurker

• Just Joined
• 2 posts

Posted 21 May 2010 - 08:57 AM

Robert Sedgewick (Department of Computer Science, Princeton University) published a very good algorithm, complete with detailed explanation, of creating and maintaining 2-3 and 2-3-4 binary trees, called Left Leaning Red Black Binary Trees (LLRB). A pdf of the algorithm is located at

http://www.cs.prince...s/LLRB/LLRB.pdf

He also gave a talk at the 2008 International Conference on the Analysis of Algorithms in Maresias, Brazil. A copy of his presentation, in pdf format, is available from

http://www.ime.usp.b...s/sedgewick.pdf

I was so impressed by the presentation that I implemented the algorithm as a PHP abstract class. The code is available from

LLRB Tree (tree, binary tree) - PHP Classes

Hope that this helps. If it does not provide an immediate solution, perhaps it will provide additional insight for you.

Good Luck.
• 0

### #6 jaywheeler

jaywheeler

CC Lurker

• Just Joined
• 2 posts

Posted 21 May 2010 - 09:00 AM

The copy of Sedgewick's presentation if available at the following URL: http://www.ime.usp.b...s/sedgewick.pdf

Sorry for the bad link in my previous post. This is well worth visiting.
• 0