Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 524829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:36:31+00:00 2026-05-13T08:36:31+00:00

I am reading the following article, http://articles.sitepoint.com/article/hierarchical-data-database/2 aboutStoring Hierarchical Data in a Database. This

  • 0

I am reading the following article, http://articles.sitepoint.com/article/hierarchical-data-database/2 about”Storing Hierarchical Data in a Database”.

This is talking about these structures. http://sitepointstatic.com/graphics/sitepoint_numbering.gif and http://sitepointstatic.com/graphics/table02.gif

I don’t understand the following passages. What do these mean.

“Each time you start with the children of a node, you add the right value of that node to the stack.”

and

“When you’re finished displaying a node, you remove its right value from the stack. If you count the elements in the stack, you’ll get the level of the current node.”

I am hoping someone explains these in a simpler way if possible.

To show the tree structure, children
should be indented slightly more than
their parent. We can do this by
keeping a stack of right values. Each
time you start with the children of a
node, you add the right value of that
node to the stack. You know that all
children of that node have a right
value that is less than the right
value of the parent, so by comparing
the right value of the current node
with the last right node in the stack,
you can see if you’re still displaying
the children of that parent. When
you’re finished displaying a node, you
remove its right value from the stack.
If you count the elements in the
stack, you’ll get the level of the
current node.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:36:31+00:00Added an answer on May 13, 2026 at 8:36 am

    They’re trying to come up with a way to use Nested Sets for indenting data by the level in the tree.

    Food (1,12)
    |
    +--Fruit (2,11)
      |
      +--Red (3,6)
      | |
      | +--Cherry (4,5)
      |
      +--Yellow (7,10)
        |
        +--Banana (8,9)
    

    So as you fetch the rows, you push the rgt number onto the end of an array:

    $right[] = $row['rgt'];
    

    This array grows as you process children and subchildren. For example, by the time we get to “Cherry” the array looks like this:

    array(11, 6, 5)
    

    As long as we’re descending down a branch of the tree, the rgt values in this should be getting less, because a child’s rgt value is always less than its parent’s rgt value.

    The next row we process is “Yellow” which has a rgt value of 10. This value 10 is greater than the last value in the array, which means we’re not descending down one branch anymore, we’re on a different branch. We need to pop numbers out of the array until 10 is no longer greater than the last number in the array.

    array(11, 6) // 10 is still greater than 6
    array(11)    // 10 is not greater than 11, so stop
    

    Now we know that the array contains only ancestors of our current row “Yellow”.

    The level in the tree is always equal to the number of elements in that array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 275k
  • Answers 275k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You definitely must read this document: Foundations: Workflow Services You… May 13, 2026 at 2:41 pm
  • Editorial Team
    Editorial Team added an answer Like whrd commented, you can't call update(...) on the result… May 13, 2026 at 2:41 pm
  • Editorial Team
    Editorial Team added an answer Try this: JScrollPane sp = new JScrollPane(t); providing the component… May 13, 2026 at 2:41 pm

Related Questions

Sorry, another super basic ASP.NET question. this so embarrassing. I am reading the article
I was reading custom serialization article on msdn: http://msdn.microsoft.com/en-us/library/ty01x675%28VS.80%29.aspx It mentions that there are
I am reading the article: Nine Options for Managing Persistent User State in Your
In this tutorial I am reading , Dave Ward creates a page that shows
I have a barcode scanner (which acts like a keyboard) and of course I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.