How to design  databse for binary tree

kindly help in desiging databse for binary tree and also to retrive data from database.

Since you're not asking about Java, you'll probably get more responses by posting this in a database forum.

Similar Messages

  • How to extend  breadth first Search for Binary Tree to any kind of Tree??

    Dear Friends,
    I am thinking a problem, How to extend breadth first Search for Binary Tree to any kind of Tree?? ie each node has more than 2 leaves such as 1, 2,3,4 or any,
    I have following code to successfully apply for breadth first Search in Binary Tree as follows,
    package a.border;
    import java.util.ArrayList;
    import java.util.LinkedList;
    public class Tree
        int root;
        Tree left;
        Tree right;
        static ArrayList<Integer> list = new ArrayList<Integer>();
        static ArrayList<Tree> treeList = new ArrayList<Tree>();
        private static LinkedList<Tree> queue = new LinkedList<Tree>();
         * @param root root value
         * @param left left node
         * @param right right node
        public Tree(int root, Tree left, Tree right)
            this.root = root;
            this.left = left;
            this.right = right;
        /** Creates a new instance of Tree
         * You really should know what this does...
         * @param root
        public Tree(int root)
            this.root = root;
            this.left = null;
            this.right = null;
         * Simply runs a basic left then right traversal.
        public void basicTraversal()
            //Check if we can go left
            if (left != null)
                left.basicTraversal();
            //Add the root
            list.add(root);
            //Check if we can go right
            if (right != null)
                right.basicTraversal();
        public ArrayList<Integer> getBreadthTraversal(ArrayList<Integer> list)
            //Add the root to the arraylist, we know it is always the first entry.
            list.add(root);
            //Basically we add the first set of nodes into the queue for
            //traversing.
            //Query if left exists
            if (left != null)
                //Then add the node into the tree for traversing later
                queue.add(left);
            //Same for right
            if (right != null)
                queue.add(right);
            //Then we call the traverse method to do the rest of the work
            return traverse(list);
        private ArrayList<Integer> traverse(ArrayList<Integer> list)
            //Keep traversing until we run out of people
            while (!queue.isEmpty())
                Tree p = queue.remove();
                //Check if it has any subnodes
                if (p.left != null)
                    //Add the subnode to the back of the queue
                    queue.add(p.left);
                //Same for left
                if (p.right != null)
                    //Same here, no queue jumping!
                    queue.add(p.right);
                //Append to the ArrayList
                list.add(p.root);
            //And return
            return list;
         * Makes a tree and runs some operations
         * @param args
        public static void main(String[] args)
             *                             4
             *          t =           2       6
             *                      1   3    5   7
            Tree leaf6 = new Tree(1);
            Tree leaf7 = new Tree(3);
            Tree leaf8 = new Tree(5);
            Tree leaf9 = new Tree(7);
            Tree t4 = new Tree(2, leaf6, leaf7);
            Tree t5 = new Tree(6, leaf8, leaf9);
            Tree t = new Tree(4, t4, t5);
            t.basicTraversal();
            System.out.println("Here is basicTraversal ="+list.toString());
            list.clear();
            t.getBreadthTraversal(list);
            System.out.println("getBreadthTraversal= " +list.toString());
            list.clear();
        }Can Guru help how to update to any kind of tree??
    here this code is for the tree like:
             *                             4
             *          t =           2       6
             *                      1   3    5   7
             */But i hope the new code can handle tree like:
             *                             4
             *                           /   | \
             *                          /     |   \
             *          t =            2     8   6
             *                        / |  \    |    /| \
             *                      1 11  3 9   5 10  7
             */Thanks

    sunnymanman wrote:
    Dear Friends,
    I am thinking a problem, How to extend breadth first Search for Binary Tree to any kind of Tree?? ...The answer is interfaces.
    What do all trees have in common? And what do all nodes in trees have in common?
    At least these things:
    interface Tree<T> {
        Node<T> getRoot();
    interface Node<T> {
        T getData();
        List<Node<T>> getChildren();
    }Now write concrete classes implementing these interfaces. Let's start with a binary tree (nodes should have comparable items) and an n-tree:
    class BinaryTree<T extends Comparable<T>> implements Tree<T> {
        protected BTNode<T> root;
        public Node<T> getRoot() {
            return root;
    class BTNode<T> implements Node<T> {
        private T data;
        private Node<T> left, right;
        public List<Node<T>> getChildren() {
            List<Node<T>> children = new ArrayList<Node<T>>();
            children.add(left);
            children.add(right);
            return children;
        public T getData() {
            return data;
    class NTree<T> implements Tree<T> {
        private NTNode<T> root;
        public Node<T> getRoot() {
            return root;
    class NTNode<T> implements Node<T> {
        private T data;
        private List<Node<T>> children;
        public List<Node<T>> getChildren() {
            return children;
        public T getData() {
            return data;
    }Now with these classes, you can wite a more generic traversal class. Of course, every traversal class (breath first, depth first) will also have something in common: they return a "path" of nodes (if the 'goal' node/data is found). So, you can write an interface like this:
    interface Traverser<T> {
        List<Node<T>> traverse(T goal, Tree<T> tree);
    }And finally write an implementation for it:
    class BreathFirst<T> implements Traverser<T> {
        public List<Node<T>> traverse(T goal, Tree<T> tree) {
            Node<T> start = tree.getRoot();
            List<Node<T>> children = start.getChildren();
            // your algorithm here
            return null; // return your traversal
    }... which can be used to traverse any tree! Here's a small demo of how to use it:
    public class Test {
        public static void main(String[] args) {
            Tree<Integer> binTree = new BinaryTree<Integer>();
            // populate your binTree
            Tree<Integer> nTree = new NTree<Integer>();
            // populate your nTree
            Traverser<Integer> bfTraverser = new BreathFirst<Integer>();
            // Look for integer 6 in binTree
            System.out.println("bTree bfTraversal -> "+bfTraverser.traverse(6, binTree));
            // Look for integer 6 in nTree
            System.out.println("bTree bfTraversal -> "+bfTraverser.traverse(6, nTree));
    }Good luck!

  • Queue for Binary Tree Node

    I need to create a simple Queue class for Binary Tree Node. The class consist of only enqueue and dequeue, I cannot use the Collection Interface though. But I have no idea how to do it. Below is my Binary Tree Node Class.
    public class BTNode {
         private customer     item;
         private BTNode     left;
         private BTNode     right;
         public BTNode() {// constructor
              item = null;
              left = right = null;
         public BTNode(customer newItem) {// constructor
              item = newItem.clone();
              left = right = null;
         public void setItem(customer newItem) {// set methods
              item = newItem.clone();
         public void setLeft(BTNode newLeft) {
              left = newLeft;
         public void setRight(BTNode newRight) {
              right = newRight;
         public customer getItem() {     // get methods
              return item;
         public BTNode getLeft() {
              return left;
         public BTNode getRight() {
              return right;
    public class Queue1 extends BTNode {
        public Queue1() {
            super();
        public void enqueue(BTNode newItem) {
        public void dequeue() {
    }

    public class Queue1 extends BTNode {Why do you think that the queue should extend BTNode?
    You probably want to aggregate a List.
    Kaj

  • How to design EDW for source systems from different Time-Zones

    How to design EDW for source systems from different Time-Zones?
    Suppose IT landscape has a global BW in New York, and source systems in americas, europe and asia, then how the time-zones effect on time related things like delta selections on date or timestamp etc.

    As you said BW is global in NY, your source system must be global too. People from various locations can connect to same source system and thus timestamps for delta is always maintained as 1 single time. We have same scenario in our project. Our R/3 system is used by users in US and Europe. So we run deltas twice in day to make sure we got deltas from both locations.
    If scenarios was such that all locations connect to separate R/3 system, then obviously you have multiple queues. That is unique delta queue for each source system so deltas will be pulled as per data in respective queues.
    Abhijit

  • How to Pretty Print a Binary Tree?

    I'm trying to display a Binary Tree in such a way:
    ________26
    ___13_________2
    1_______4 3_________1
    (without the underscores)
    however I cannot figure out the display method.
    class BinaryNode
              //Constructors
              BinaryNode leftChild, rightChild;
    Object data;
         BinaryNode()
    leftChild = null;
    data = null;
    rightChild = null;
              BinaryNode( Object d, BinaryNode left, BinaryNode right)
    leftChild = left;
    data = d;
    rightChild = right;
              //Height
              public static int Height(BinaryNode root)
    if (root == null)
    return 0;
    if ((Height(root.leftChild)) > Height(root.rightChild))
    return 1 + Height(root.leftChild);
    return 1 + Height(root.rightChild);
              //Count
    public static int Count(BinaryNode root)
    if(root==null)
    return 0;
    return 1 + Count(root.leftChild) + Count(root.rightChild);
              //Display
              public static void Display(BinaryNode root)
              int level = 2^(Level(root)-1)
              for (int i = 1; i<Height(root)+1; i++)
              System.out.printf("%-4s%
              Display(root, i);
              System.out.println();
              public static void Display(BinaryNode root, int level)
              if (root!=null)
              if(level==1)
              System.out.print(root.data + " ");
              else
              Display(root.leftChild, level-1);
              Display(root.rightChild, level-1);
              //Level
              public static int Level(BinaryNode root)
              if(root==null)
              return 0;
              if(root.leftChild == null && root.rightChild == null)
              return 1;
              return Level(root.leftChild) + Level(root.rightChild);
    Edited by: 815035 on Nov 23, 2010 12:27 PM

    The example of what the OP wants it to look like I thought was quite plain. Its right at the top of the post.
    Unfortunately it is also quite difficult to accomplish using System.out.print statements.
    You have to print out the root of the tree first (its at the top)
    However you don't know how far along to the right you need to print it without traversing the child nodes already (you need to know how deep the tree is, and how far to the left the tree extends from the root)
    So you will need to traverse the tree at least twice.
    Once to work out the offsets, and again to print out the values.
    The working out of offsets would have to be a depth search traversal I think
    The printing of the values in this fashion would be a breadth first traversal.
    I remember (ages ago) doing a similar assignment, except we printed the tree sideways.
    ie the root was on the left, the leaves of the tree on the right of the screen.
    That meant you could do an inorder depth traversal of the tree to just print it once.
    hope this helps,
    evnafets

  • Succinct encoding for binary tree with n nodes...

    How do I find all possible bit strings (Succinct encoding) for a binary tree with order n? Can anybody give me an algorithm?

    I associate the order of a tree with some sort of a search or traversal. What do you mean by a "+tree with order n+"?
    Could you perhaps give an example of what you're looking for?

  • How to Design Report for Excel output?

    Hello Experts...
    I have both versions Crystal Report XI and Crystal 2013 at this time as we are in the process of Upgrading...
    How to design for excel output with no page size limit.
    I have several fields going across (crossing width of paper size 11X17 landscape) and I do not need this report output to be printed at all only for excel output.
    Appreciate your time!
    Thank you,
    Padma

    Hi Padma,
    You would need to increase the Page Size horizontally. Go to File > Page Setup > Check 'No Printer' > Check 'Dissociate Formatting Page Size and Printer page Size' > Increase the Horizontal value.
    Also see:
    http://scn.sap.com/docs/DOC-6687
    and
    How to WYSIWYG SAP Crystal Reports Export to XLS
    Formatting a Crystal Report for Export to MS Excel
    -Abhilash

  • How to design model for staging layer.

    Hi expert,
         what is the rule when design staging layer? such as how much layer needed for staging? and what objects used in staging? why different layers needed for staging .etc.?

    Hi,
    Please have a look at SAP Help - Enterprise Data Warehouse (EDW) for basic information around layers and architecture. Moreover, please have a look at my blog Layered, Scalable Architecture (LSA) from an Implementation Perspective - Overview where you can find several "accelerators" to facilitate your implementation.
    Best regards,
    Sander

  • How to design a listbox or tree control related to the database

    Now i have a problem to design a listbox or tree control, it is designed to connect to the database, if the related element in database changed, the element in listbox or tree control should also change. i have managed to read the element in database, but i cannot input it to the listbox or tree control, since it has no input terminal that i can only use the Labeling tool and enter text into it.
    is there any advise on it, maybe i can use another control rather than listbox or tree control. any suggestion would be appreciate.
    Thank you
    XuY

    Hi Xuy,
          On the front-panel, right-click on the text-ring control and select: Create\Property Node.
    Then, on the diagram, right-click on the property-node and select "Strings[]".
    The "strings[]" property is the array of strings available in the control - and you can change it.
    Cheers!
    Message Edited by tbd on 04-05-2007 11:18 PM
    "Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
    Attachments:
    RingStrings.jpg ‏6 KB

  • How to Design ODS for a scenario

    Hi All,
    I need to load a flat file into an ODS. It has got separate fields for the ID and text of a characteristic(Key Field) and then I have few keyfigures/ DataFields and a navigational attribute in the ODS. The format looks like as follows:
    Pnt_ID Pnt_Txt Matl_type Jan        Feb            Mar           APr            May              Jun             Jul
                                          Min Max    Min Max     Min Max    Min Max    Min Max    Min Max    Min Max
    How do I design the ODS in such a secnario?
    Please suggest a solution.
    Regards,
    Harika.

    Hi,
           According to me in DSO use
    2 characteristic in Key fields
    Pnt_ID, Calmonth
    2 keyfigure in data field
    Max amount , Min Amount
    and then load Print_txt in print_ID using text upoad.
    Hope this will solve your issue.
    any problem then ask me.
    regards,

  • How to design FXML for all screen resolution

    hello
    I am designing a page in FXML using scene builder,and I want that my fxml runs good on few screen resolutions,for that there is need for relative positioning but in FXML there is nothing like % and all.
    Please do any one have worked on this then help me out.
    thanks in advance.

    See this blog, it doesn't answer your question, but I hope it helps:
    http://blog.randahl.dk/2012/12/javafx-designing-for-multiple-screen.html

  • How to design tables for Apex applications?

    Hi,
    I am learning Apex . I have one question.
    Considering normal tables, I have primary key (some single column and some composite) for my tables.
    But I learnt that Apex works well when we have primary keys using sequences.
    So Should I do the following now.
    1) Add a new column to all my tables which gets populated from Apex directly and make that column as primary key
    2) Create a sequence to associate each such primary key
    3) Make the actual primary keys as Unique keys + Not null constraints
    Thank You

    Why are you designing your tables o suit the tool? What happenes when you change development products? You SHOULD develop based upon SOUND database design methods. Use of surrogate keys IS a prefered development method, since use of multi-key (Composite) keys is known to be a pain for multiple reasons..
    Take this small bit of knowledge.. Design you database properly for an interface and you will NOT have issues..
    Thank you,
    Tony Miller
    Raleigh, NC

  • How to design a simple binary one-shot

    I need a simple binary one-shot that when a signal becomes true, a new value goes True for one evaluation and does not get re-triggered until the original signal becomes false and then true again. I have tried many ways and either the wait for the signal to go false again locks up the loop or the trigger remains true and causes the logic to keep on processing.
    Solved!
    Go to Solution.

    Can you post an image of what you have tried, preferably in .png format? Or attach your code attempts, ID'ing what version of LabVIEW. 
    Putnam
    Certified LabVIEW Developer
    Senior Test Engineer
    Currently using LV 6.1-LabVIEW 2012, RT8.5
    LabVIEW Champion

  • Design Pattern for Building Trees (Java)

    I'm wondering if there is a design pattern suited to build trees from a given domain object.
    public interface DomainObject {
    public long getId();
    public abstract class Displayable {
    private DomainObject domainObject;
    private Displayable parent;
    private Vector children;
    public Displayable(DomainObject domainObject, Displayable parent) {
    this.domainObject = domainObject;
    this.parent = parent;
    this.children = new Vector();
    public Displayable(DomainObject domainObject) {
    this(domainObject, null);
    public Displayable getParent() {
    return parent;
    public DomainObject getDomainObject() {
    return domainObject;
    public Displayable[] getChildren() {
    return (Displayable[])children.toArray(new Displayable[children.size()]);
    public void addChild(Displayable d) {
    children.add(d);
    Example:
    DomainObject O
    Displayable D (contains O)
    D's parent is C
    C's parent is B
    B's parent is A
    A does not have a parent
    A --> B --> C --> D(O)
    Method signature
    public Displayable buildDisplayable(DomainObject domainObject);
    So basically pass in a DomainObject (O) and spit out the Displayable (D), with the tree built up to the root (A).

    No I graduated last year from college. I'm trying to improve our SWT/JFace GUI framework. That method signature is just something I thought about. I'm thinking using Factory Pattern will have to do considering I know ahead of time which subclasses of Displayable have parents and children.

  • How to Display Heading for TREE Structure (report)

    hi,
         tell me how display the heading for the TREE Report.
    With Regards,
    Shakthi Raj N.

    Hi,
    If you are using object oriented approach for developing the Tree report, then you can use below shown example for creating header for the report.
      first create tree control
      CREATE OBJECT TREE1
        EXPORTING
            PARENT              = G_CONTAINER_OBJECT
            NODE_SELECTION_MODE = CL_GUI_COLUMN_TREE=>NODE_SEL_MODE_SINGLE
            ITEM_SELECTION      = ''
            NO_HTML_HEADER      = ''
            NO_TOOLBAR          = ''
        EXCEPTIONS
            CNTL_ERROR                   = 1
            CNTL_SYSTEM_ERROR            = 2
            CREATE_ERROR                 = 3
            LIFETIME_ERROR               = 4
            ILLEGAL_NODE_SELECTION_MODE  = 5
            FAILED                       = 6
            ILLEGAL_COLUMN_NAME          = 7.
      CLEAR GT_HEADER.
      GT_HEADER-TYP = 'H'.
      GT_HEADER-INFO = 'Output'.
      APPEND GT_HEADER.
      CLEAR GT_HEADER.
      GT_HEADER-TYP = 'S'.
      GT_HEADER-KEY = 'Display'.
      GT_HEADER-INFO = 'Report'.
      APPEND GT_HEADER.
    then create empty tree-control
      CALL METHOD TREE1->SET_TABLE_FOR_FIRST_DISPLAY
              EXPORTING
                   IS_HIERARCHY_HEADER  = G_HIERARCHY_HEADER
                   I_BACKGROUND_ID      = 'ALV_BACKGROUND'
                   IT_LIST_COMMENTARY   = GT_HEADER[]
              CHANGING
                   IT_OUTTAB            = GT_SPFLI[]    "empty table
                   IT_FIELDCATALOG      = GT_FIELDCAT_LVC[].
    In this way header can be given for Tree report.
    Hope this answers your query.
    Regards,
    Brajvir

Maybe you are looking for

  • Getting an Error in my Iif statement

    I am trying to check to see if there are more than 20 characters in a field and if so return the data formatted in two different ways.  This works... =Iif(Len(Fields!Street_Address_1.Value)>20,"LongAddress","ShortAddress") This works... =Iif(Len(Fiel

  • Movie tab is missing in iTunes

    For some reason there is no Movie tab in my iTunes on my iPad2 that I bought today I've updated iTunes. Heeelp. Message was edited by: Lineb

  • Video problem with movies that previously played okay

    I transfer movies on and off my Touch to open up space. I previously copied a dvd using toast Titanium 8 to my touch which played fine. I then deleted it to make space. When I tried to transfer the movie back to the Touch a few days later it wouldn't

  • "Cannot recover" Error when opening InDesign doc

    We are a Server 2008 w/ XP/SP3 client environment. I have a user that opens an InDesign doc located on a shared network drive, does some work on it, and closes it. When the next person opens it, they get this error: "Cannot recover <<filename>>.indd.

  • Using xperia with ps4 for double screen

    So i downloaded the PS4 app and i am tyring to use the dual screens with Battlefield 4 game. I have gone into the ps4 and registered my tablet with the ps4, it sees it when you goig into the settings. I load up the app on my tablet and it sees my tro