dbTalk Databases Forums  

Binary tree

comp.databases comp.databases


Discuss Binary tree in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
kashi
 
Posts: n/a

Default Binary tree - 02-02-2009 , 02:49 AM






hi, ia m doing project like multi level marketing, i have to store the
values in binary tree fromat,
how to store the string values in binarytree format in database, send
me the qureys,

i used this
CREATE TABLE NestedSet ( node CHAR(1) NOT NULL PRIMARY KEY, lf INT NOT
NULL, rg INT NOT NULL);
CREATE TABLE AdjacencyList ( node CHAR(1) NOT NULL PRIMARY KEY, parent
CHAR(1) NULL);
INSERT INTO AdjacencyList SELECT A.node,B.node AS parent FROM
NestedSet AS A,NestedSet AS B where B.lf = (SELECT MAX(C.lf) FROM
NestedSet C WHERE A.lf > C.lf AND A.lf < C.rg)

Reply With Quote
  #2  
Old   
Ed Prochak
 
Posts: n/a

Default Re: Binary tree - 02-02-2009 , 07:29 AM






On Feb 2, 3:49*am, kashi <vishwa.bhyra... (AT) gmail (DOT) com> wrote:
Quote:
hi, ia m doing project like multi level marketing, i have to store the
values in binary tree fromat,
how to store the string values in binarytree format in database, send
me the qureys,

i used this
CREATE TABLE NestedSet ( node CHAR(1) NOT NULL PRIMARY KEY, lf INT NOT
NULL, rg INT NOT NULL);
CREATE TABLE AdjacencyList ( node CHAR(1) NOT NULL PRIMARY KEY, parent
CHAR(1) NULL);
INSERT INTO AdjacencyList SELECT A.node,B.node AS parent FROM
NestedSet AS A,NestedSet AS B where B.lf = (SELECT MAX(C.lf) FROM
NestedSet C WHERE A.lf > C.lf AND A.lf < C.rg)
For starters, CHAR(1) holds very short strings.
Usually in a binary tree, each node's Left and Right (lf & rg?) links
contain values that identify the child nodes. IOW, they contain values
of the same type as the primary key.
You never populated nestedset, so I have no clue if the INSERT is
right or wrong.

Ed



Reply With Quote
  #3  
Old   
CJ
 
Posts: n/a

Default Re: Binary tree - 02-03-2009 , 03:21 AM



On Feb 2, 3:49*am, kashi <vishwa.bhyra... (AT) gmail (DOT) com> wrote:
Quote:
hi, ia m doing project like multi level marketing, i have to store the
values in binary tree fromat,
how to store the string values in binarytree format in database, send
me the qureys,

i used this
CREATE TABLE NestedSet ( node CHAR(1) NOT NULL PRIMARY KEY, lf INT NOT
NULL, rg INT NOT NULL);
CREATE TABLE AdjacencyList ( node CHAR(1) NOT NULL PRIMARY KEY, parent
CHAR(1) NULL);
INSERT INTO AdjacencyList SELECT A.node,B.node AS parent FROM
NestedSet AS A,NestedSet AS B where B.lf = (SELECT MAX(C.lf) FROM
NestedSet C WHERE A.lf > C.lf AND A.lf < C.rg)
I've done something like this for familial relationships. What you
want to use is self referencing foreign keys. Which way those keys
reference depends on whether you need to control to number of children
(since you're specifically refering to a binary tree, I'll assume you
want to limit it to two children). Something like this should work:

CREATE TABLE NestedSet (id int auto_increment primary key, lf int
null, rg in null, <add additional columns for node data here>);
ALTER TABLE NestedSet ADD FOREIGN KEY (lf) REFERENCES NestedSet(id);
ALTER TABLE NestedSet ADD FOREIGN KEY (rg) REFERENCES NestedSet(id);

lf and rg would reference the rows for the left and right children.

As for the AdjacencyList is honestly don't see where you're trying to
go with that or the insert into it.

CJ

P.S.: If the number of children is not to be limited (as would be the
case of a MLM), you can easily reverse the relationships I showed
above and use just one foreign key (parent).


Reply With Quote
  #4  
Old   
Philipp Post
 
Posts: n/a

Default Re: Binary tree - 02-03-2009 , 04:27 AM



Kashi,

could it be that you mix up things? Nested sets, Adjacency and binary
trees are different ways to represent trees.

You may have a look at Joe Celko's book "Trees and hierarchies in SQL"
which gives you the details about all this. Also "send me the query".

brgds

Philipp Post


Reply With Quote
  #5  
Old   
kashi
 
Posts: n/a

Default Re: Binary tree - 02-05-2009 , 11:46 PM



On Feb 3, 3:27 pm, Philipp Post <Post.Phil... (AT) googlemail (DOT) com> wrote:
Quote:
Kashi,

could it be that you mix up things? Nested sets, Adjacency and binary
trees are different ways to represent trees.

You may have a look at Joe Celko's book "Trees and hierarchies in SQL"
which gives you the details about all this. Also "send me the query".

brgds

Philipp Post
CREATE TABLE NestedSet ( node CHAR(1) NOT NULL PRIMARY KEY, lf INT NOT
Quote:
NULL, rg INT NOT NULL);
CREATE TABLE AdjacencyList ( node CHAR(1) NOT NULL PRIMARY KEY, parent
CHAR(1) NULL);
INSERT INTO AdjacencyList SELECT A.node,B.node AS parent FROM
NestedSet AS A,NestedSet AS B where B.lf = (SELECT MAX(C.lf) FROM
NestedSet C WHERE A.lf > C.lf AND A.lf < C.rg)

Reply With Quote
  #6  
Old   
kashi
 
Posts: n/a

Default Re: Binary tree - 02-06-2009 , 04:21 AM



On Feb 2, 6:29 pm, Ed Prochak <edproc... (AT) gmail (DOT) com> wrote:
Quote:
On Feb 2, 3:49 am, kashi <vishwa.bhyra... (AT) gmail (DOT) com> wrote:

hi, ia m doing project like multi level marketing, i have to store the
values in binary tree fromat,
how to store the string values in binarytree format in database, send
me the qureys,

i used this
CREATE TABLE NestedSet ( node CHAR(1) NOT NULL PRIMARY KEY, lf INT NOT
NULL, rg INT NOT NULL);
CREATE TABLE AdjacencyList ( node CHAR(1) NOT NULL PRIMARY KEY, parent
CHAR(1) NULL);
INSERT INTO AdjacencyList SELECT A.node,B.node AS parent FROM
NestedSet AS A,NestedSet AS B where B.lf = (SELECT MAX(C.lf) FROM
NestedSet C WHERE A.lf > C.lf AND A.lf < C.rg)

For starters, CHAR(1) holds very short strings.
Usually in a binary tree, each node's Left and Right (lf & rg?) links
contain values that identify the child nodes. IOW, they contain values
of the same type as the primary key.
You never populated nestedset, so I have no clue if the INSERT is
right or wrong.

Ed
can u send me the query how to store the string values in database,i
doing multilevel marketing project , in that i am stroeing the values
in binary format.


Reply With Quote
  #7  
Old   
Ed Prochak
 
Posts: n/a

Default Re: Binary tree - 02-09-2009 , 08:19 AM



On Feb 6, 5:21*am, kashi <vishwa.bhyra... (AT) gmail (DOT) com> wrote:
Quote:
On Feb 2, 6:29 pm, Ed Prochak <edproc... (AT) gmail (DOT) com> wrote:



On Feb 2, 3:49 am, kashi <vishwa.bhyra... (AT) gmail (DOT) com> wrote:

hi, ia m doing project like multi level marketing, i have to store the
values in binary tree fromat,
how to store the string values in binarytree format in database, send
me the qureys,

i used this
CREATE TABLE NestedSet ( node CHAR(1) NOT NULL PRIMARY KEY, lf INT NOT
NULL, rg INT NOT NULL);
CREATE TABLE AdjacencyList ( node CHAR(1) NOT NULL PRIMARY KEY, parent
CHAR(1) NULL);
INSERT INTO AdjacencyList SELECT A.node,B.node AS parent FROM
NestedSet AS A,NestedSet AS B where B.lf = (SELECT MAX(C.lf) FROM
NestedSet C WHERE A.lf > C.lf AND A.lf < C.rg)

For starters, CHAR(1) holds very short strings.
Usually in a binary tree, each node's Left and Right (lf & rg?) links
contain values that identify the child nodes. IOW, they contain values
of the same type as the primary key.
You never populated nestedset, so I have no clue if the INSERT is
right or wrong.

* Ed

can u send me the query how to store the string values in database,i
doing multilevel marketing project , in that i am stroeing the values
in binary format.

Before I can send you the solution, please forward a contract request
to my business account, edprochak, at Magic Interface, Ltd.
(magicinterface.com). I'll send you a rate schedule and a contract for
your manager to sign. I am sure that with such a finely worded
requirements specification, I can complete the work in a brief period
of time at our standard billing rate.

8^)

Ed


Reply With Quote
  #8  
Old   
Marco Mariani
 
Posts: n/a

Default Re: Binary tree - 02-09-2009 , 09:24 AM



kashi wrote:

Quote:
can u send me the query how to store the string values in database,i
doing multilevel marketing project , in that i am stroeing the values
in binary format.
If you keep asking for help citing "multi level marketing" in a
newsgroup of technically-minded people who know something about math, I
am not sure you'll find many people eager to help you.

Should you be willing to spend something, Ed Prochak is a good choice.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.