Order of tree and order of leaf node



I was reading the book Fundamentals Of Database Systems by Navathe. The book mentions the order of internal nodes and order of the leaf node separately.

In other sources I found the order of tree to be only given.

In those cases can I assume that order of leaf node is same as the order of the tree?


Related to : Order of tree and order of leaf node
What is the appropriate post order travetse in a 'tree' where node can have more parents?
Programming Languages

I have a graph that is like a tree, node can have 'left child', 'right child' relationship, but instead of 'parent' it can have 'parents', so instead of one, more parents can exist.

Normally post order traverse go from down to up, from left to right. I want to keep this good behaviour.

Wether this algorythm will do it:

  1. traverse all parents if possible
  2. traverse left child if possible
  3. traverse right child if possible
  4. mark visited node

parents relationship is an ordered relationship, each parent has an index: 0, 1 .. n


Create flat list from tree ordered by the tree order
Programming Languages

I'm working on C# and i'm looking for a simple way to take a list that represent a tree and flat the tree to a list with the same order as in the tree.

I have 4 properties per node:
* ID
* ParentID,
* Seq
* Name

public class MyNode  
{  
   public int ID{get;set;}  
   public int ParentID{get;set;}  
   public int SeqID{get;set;}  
   public string Name{get;set;}  
}  

And i have a collection of MyNode:

List<MyNode> FlatListOfNodes{get;set;}

I'm looking for something that will look like this:
FlatListOfNodes.OrderBy(something).DoAnotherThing1(somthing)....

that will order the list in the same order that is in the tree.

for example if will have this tree:

-- Parent1
     -- Child 1.1  
     -- Child 1.2  
        -- grandson 1.2.1  
        -- grandson 1.2.2  
        -- grandson 1.2.3
    -- Child 1.3
-- Parent2
     -- Child 2.1  
     -- Child 2.2  
        -- grandson 2.2.1  
        -- grandson 2.2.2  
        -- grandson 2.2.3
    -- Child 2.3
        -- grandson 2.3.1
        -- grandson 2.3.2

I want to represent it in a flat list by the same order.

in this example:

  • Parent1 have ID=32, ParentID=-1,SeqID=1,Name="Parent1"
  • Child1.2 have ID=412, ParentID=32,SeqID=2, Name="Child1.2"
  • Grandson 1.2.1 have ID=231, ParentID=412, SeqID=1, Name="grandson 1.2.1"
  • Parent2 will have ID=345,ParentID=-1,SeqID=2,Name="Parent2"
  • Child2.3 with have ID=785, ParentID=345, SeqID=3, Name="Child 2.3"
  • Grandson 2.3.1 will have ID=854, ParentID=785, SeqID=1, Name= "grandson 2.3.1"

What is the best way to do it?
Is there some way to do it with linq?

Thanks!


As there is no default order in SQL, what determines the order rows are returned in if an Order By is not specified?
Programming Languages

I know that if an SQL query is not sorted by an Order By argument, it's not sorted at all. When running a query without an Order By, I'd expect to see the same results in a differing order.

However, the results are still returned in an order (i.e. there is a row 1, a row 2 and so on), just not a dependable one - so if they're not sorted, what determines (presumably on a case-by-case basis) the order in which rows are returned.

Specifically, my experience is with MySQL, but I'm curious about this from a theoretical point, rather than trying to solve a specific problem.


How to find a leaf node in a binary NOT SORTED tree
Programming Languages

I want to find a leaf node in an unsorted binary tree and be able to use it in other functions. i have this as an idea

UPDATED****

node * leaf(node* root)
{
    if(root==NULL)
        return NULL;
    if(root->left==NULL && root->right==NULL)
        return root;
    else
    {   leaf(root->left);
        leaf(root->right);
    }
}

How to randomly get or find a sub-tree (include root node) from a given tree that contains n leaf-nodes
Programming Languages

I have a non-binary tree. I want to randomly find a "sub-trees" that are connected from root to leaf which must have at least n leaf-nodes (leaf-nodes of sub-tree must be leaf-nodes of given tree). For example: given a tree as below

           *A
          /   
         B     C
        /      
      *E   D    *F
            
             *J

n = 2
A random sub-tree that contains 2 leaf-nodes could be:

            A
          /   
         B     C
        /       
       E         F

or

            A
          /   
         B     C
               
           D     F
            
             J

or

            A
          /   
         B     
        /      
       E   D     
            
             J

I don't need to get all possible sub-trees, just randomly get it with a given tree and n

Reason for edit: The question I've asked is not really meet my need and not really useful.


Order of tree and order of leaf node
Programming Languages

I was reading the book Fundamentals Of Database Systems by Navathe. The book mentions the order of internal nodes and order of the leaf node separately.

In other sources I found the order of tree to be only given.

In those cases can I assume that order of leaf node is same as the order of the tree?



Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .