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

  • SEARCH
  • Home
  • 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
  • 3 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

Related Questions

I was reading the following article: http://odetocode.com/articles/294.aspx This article raised me a lot of
I was reading the following article: http://msdn.microsoft.com/en-us/magazine/cc817398.aspx Solving 11 Likely Problems In Your Multithreaded
I was reading the following article: http://java.sun.com/docs/hotspot/gc1.4.2/example.html and have trouble understanding the following lines:
I was reading this article => http://mgutz.com/2010/10/01/check_gmail_with_node_js.html . Below in the comments Shomrom says:
I was reading the following article http://blogs.msdn.com/b/wenlong/archive/2008/08/13/orcas-sp1-improvement-asynchronous-wcf-http-module-handler-for-iis7-for-better-server-scalability.aspx and I am a little confused. First
Reading this DZone article about Java concurrency I was wondering if the following code:
I spot some interesting articles about exception handle in CodeProject http://www.codeproject.com/KB/cpp/seexception.aspx After reading, I
I am following the spring MVC tutorial and also reading this article on mvc
I was reading this: http://en.wikipedia.org/wiki/Thread_safety Is the following function thread-safe? void foo(int y){ int
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

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.